Fixed template copy function
authorMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:46:51 +0000 (01:46 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:46:51 +0000 (01:46 +0200)
wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php

index 7ad09cde43b25ba1d32faeb2dd9a45f2119ab4bb..b0c8891c6870568348073d6aa0d1ab4c639de2e0 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\acp\form;
+use wcf\system\exception\IllegalLinkException;
+
 use wcf\data\template\group\TemplateGroup;
 use wcf\data\template\group\TemplateGroupAction;
 use wcf\data\template\group\TemplateGroupList;
@@ -61,6 +63,35 @@ class TemplateAddForm extends AbstractForm {
         */
        public $packageID = PACKAGE_ID;
        
+       /**
+        * id of copied template
+        * @var integer
+        */
+       public $copy = 0;
+       
+       /**
+        * copied template object
+        * @var wcf\data\template\Template
+        */
+       public $copiedTemplate = null;
+       
+       /**
+        * @see wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+       
+               if (!empty($_REQUEST['copy'])) {
+                       $this->copy = intval($_REQUEST['copy']);
+                       $this->copiedTemplate = new Template($this->copy);
+                       if (!$this->copiedTemplate->templateID) {
+                               throw new IllegalLinkException();
+                       }
+                       
+                       $this->packageID = $this->copiedTemplate->packageID;
+               }
+       }
+       
        /**
         * @see wcf\form\IForm::readFormParameters()
         */
@@ -171,13 +202,9 @@ class TemplateAddForm extends AbstractForm {
                $templateGroupList->readObjects();
                $this->availableTemplateGroups = $templateGroupList->getObjects();
                
-               if (!count($_POST)) {
-                       if (!empty($_REQUEST['copy'])) {
-                               $templateID = intval($_REQUEST['copy']);
-                               $template = new Template($templateID);
-                               $this->tplName = $template->templateName;
-                               $this->templateSource = $template->getSource();
-                       }
+               if (!count($_POST) && $this->copiedTemplate !== null) {
+                       $this->tplName = $this->copiedTemplate->templateName;
+                       $this->templateSource = $this->copiedTemplate->getSource();
                }
        }