Add parameter to add the request data to the UploadHandler
authorJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 5 Apr 2019 18:26:13 +0000 (20:26 +0200)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Fri, 5 Apr 2019 18:26:13 +0000 (20:26 +0200)
See #2509
See #2825

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

index 1c32d969ccb5660d14abfdbef17d0422183147e1..80465ff79bf10e850546c7d9d47dc44949c9bc19 100644 (file)
@@ -39,17 +39,22 @@ class UploadHandler extends SingletonFactory {
         * Registers a UploadField.
         * 
         * @param       UploadField     $field
+        * @param       mixed           $requestData
         * 
         * @throws      \InvalidArgumentException       if a field with the given fieldId is already registered
         */
-       public function registerUploadField(UploadField $field) {
+       public function registerUploadField(UploadField $field, array $requestData = null) {
                if (isset($this->fields[$field->getFieldId()])) {
                        throw new \InvalidArgumentException('UploadField with the id "'. $field->getFieldId() .'" is already registered.');
                }
                
+               if ($requestData === null) {
+                       $requestData = $_POST;
+               }
+               
                // read internal identifier
-               if (!empty($_POST) && isset($_POST[$field->getFieldId()]) && $this->isValidInternalId($_POST[$field->getFieldId()])) {
-                       $field->setInternalId($_POST[$field->getFieldId()]);
+               if (!empty($requestData) && isset($requestData[$field->getFieldId()]) && $this->isValidInternalId($requestData[$field->getFieldId()])) {
+                       $field->setInternalId($requestData[$field->getFieldId()]);
                        
                        $this->fields[$field->getFieldId()] = $field;
                }
index c078d8aa4ce60c6bbace338bd3f6d648ad01f403..59f4ee2c0a49237f2d318e55fdf8642afea3f54a 100644 (file)
@@ -52,7 +52,7 @@ class UploadFormField extends AbstractFormField {
         */
        private function registerField() {
                if (!UploadHandler::getInstance()->isRegisteredFieldId($this->getPrefixedId())) {
-                       UploadHandler::getInstance()->registerUploadField($this->buildUploadField());
+                       UploadHandler::getInstance()->registerUploadField($this->buildUploadField(), $this->getDocument()->getRequestData());
                }
        }