Unregister field, after destroy the form
authorJoshua Rüsweg <josh@bastelstu.be>
Sun, 20 Jan 2019 18:59:54 +0000 (19:59 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Sun, 20 Jan 2019 18:59:54 +0000 (19:59 +0100)
See #2825

wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php
wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php

index 53bacb637aaaa7d9c788797f2467adfb8285866f..36f19c026bbc5c109a0bdd39e8ad8c704760b17f 100644 (file)
@@ -55,6 +55,26 @@ class UploadHandler extends SingletonFactory {
                }
        }
        
+       /**
+        * Unregisters an upload field by the given field id.
+        * 
+        * @param       string          $fieldId
+        * 
+        * @throws      \InvalidArgumentException       if the given fieldId is unknown
+        */
+       public function unregisterUploadField($fieldId) {
+               if (!isset($this->fields[$fieldId])) {
+                       throw new \InvalidArgumentException('UploadField with the id "'. $fieldId .'" is unknown.');
+               }
+               
+               $storage = $this->getStorage();
+               unset($storage[$this->fields[$fieldId]->getInternalId()]);
+               
+               WCF::getSession()->register(self::UPLOAD_HANDLER_SESSION_VAR, $storage);
+               
+               unset($this->fields[$fieldId]);
+       }
+       
        /**
         * Returns the uploaded files for a specific fieldId.
         * 
index d145ca3f89b384791847a1fab36289b9e9883272..6b98265fee65ecb8c6186763ae7751476d270404 100644 (file)
@@ -40,6 +40,15 @@ class UploadFormField extends AbstractFormField {
                }
        }
        
+       /**
+        * Unregisters the current field in the upload handler.
+        */
+       private function unregisterField() {
+               if (UploadHandler::getInstance()->isRegisteredFieldId($this->getId())) {
+                       UploadHandler::getInstance()->unregisterUploadField($this->getId());
+               }
+       }
+       
        /**
         * Builds the UploadField class. 
         * 
@@ -147,6 +156,15 @@ class UploadFormField extends AbstractFormField {
                return false;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function cleanup() {
+               $this->unregisterField();
+               
+               return $this;
+       }
+       
        /**
         * @inheritDoc
         *