Fixed import issue
authorMarcel Werk <burntime@woltlab.com>
Wed, 1 Jan 2014 17:06:35 +0000 (18:06 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 1 Jan 2014 17:06:35 +0000 (18:06 +0100)
wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php

index 5b971912d4a284cf3f480329dcd8eb038023b157..71637b92d8c082b42585ddbe5ff0ed6ed35656ef 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\importer;
+use wcf\data\user\option\category\UserOptionCategoryEditor;
+use wcf\data\user\option\category\UserOptionCategoryList;
 use wcf\data\user\option\UserOptionAction;
 use wcf\data\user\option\UserOptionEditor;
 use wcf\system\language\LanguageFactory;
@@ -28,6 +30,12 @@ class UserOptionImporter extends AbstractImporter {
         */
        protected $languageCategoryID = null;
        
+       /**
+        * list of available user option categories
+        * @var array<string>
+        */
+       protected $categoryCache = null;
+       
        /**
         * Creates a new UserOptionImporter object.
         */
@@ -56,6 +64,9 @@ class UserOptionImporter extends AbstractImporter {
                        }
                }
                
+               // create category
+               $this->createCategory($data['categoryName']);
+               
                // save option
                $action = new UserOptionAction(array(), 'create', array('data' => $data));
                $returnValues = $action->executeAction();
@@ -85,4 +96,30 @@ class UserOptionImporter extends AbstractImporter {
                
                return $userOption->optionID;
        }
+       
+       /**
+        * Creates the given category if necessary.
+        * 
+        * @param       string          $name
+        */
+       protected function createCategory($name) {
+               if ($this->categoryCache === null) {
+                       // get existing categories
+                       $list = new UserOptionCategoryList();
+                       $list->getConditionBuilder()->add('categoryName = ? OR parentCategoryName = ?', array('profile', 'profile'));
+                       $list->readObjects();
+                       foreach ($list->getObjects() as $category) $this->categoryCache[] = $category->categoryName;
+               }
+               
+               if (!in_array($name, $this->categoryCache)) {
+                       // create category
+                       UserOptionCategoryEditor::create(array(
+                               'packageID' => 1,
+                               'categoryName' => $name,
+                               'parentCategoryName' => 'profile'
+                       ));
+                       
+                       $this->categoryCache[] = $name;
+               }
+       }
 }