Added more import features
authorMarcel Werk <burntime@woltlab.com>
Tue, 2 Jul 2013 14:35:33 +0000 (16:35 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 2 Jul 2013 14:35:33 +0000 (16:35 +0200)
13 files changed:
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/files/lib/data/user/UserEditor.class.php
wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserCommentResponseImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php
wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php
wcfsetup/install/files/lib/system/importer/UserImporter.class.php
wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php

index e45c17a04926a45dc5c8aa6a8b1d66c8a229efce..88a8c830166e503618fe95a5889311ff774c2ccb 100644 (file)
                        <definitionname>com.woltlab.wcf.importer</definitionname>
                        <classname><![CDATA[wcf\system\importer\UserGroupImporter]]></classname>
                </type>
-               <!-- <type>
+               <type>
                        <name>com.woltlab.wcf.user.option</name>
                        <definitionname>com.woltlab.wcf.importer</definitionname>
                        <classname><![CDATA[wcf\system\importer\UserOptionImporter]]></classname>
                        <name>com.woltlab.wcf.user.comment.response</name>
                        <definitionname>com.woltlab.wcf.importer</definitionname>
                        <classname><![CDATA[wcf\system\importer\UserCommentResponseImporter]]></classname>
-               </type>-->
+               </type>
                <type>
                        <name>com.woltlab.wcf.user.follower</name>
                        <definitionname>com.woltlab.wcf.importer</definitionname>
index 635b83c967ac06550e41922ba5a4b505bc6bd2f3..e74292d6e999ac1f5c1bc98b54720b01cca70862 100644 (file)
@@ -241,21 +241,17 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                
                // insert visible languages
                $languageIDs = (isset($this->parameters['languages'])) ? $this->parameters['languages'] : array();
-               $userEditor->addToLanguages($languageIDs);
+               $userEditor->addToLanguages($languageIDs, false);
                
                if (PACKAGE_ID) {
                        // set default notifications
                        $sql = "INSERT INTO     wcf".WCF_N."_user_notification_event_to_user
                                                (userID, eventID)
-                               VALUES          (?, ?)";
+                               SELECT          ?, eventID
+                               FROM            wcf".WCF_N."_user_notification_event
+                               WHERE           preset = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       foreach (UserNotificationEventCacheBuilder::getInstance()->getData() as $events) {
-                               foreach ($events as $event) {
-                                       if ($event->preset) {
-                                               $statement->execute(array($user->userID, $event->eventID));
-                                       }
-                               }
-                       }
+                       $statement->execute(array($user->userID, 1));
                }
                
                return $user;
index eafd19d18c6dd09d077fb1ef040362885508edab..265fe9f79e24d684f06520691acbf2d95d76d0db 100644 (file)
@@ -218,18 +218,21 @@ class UserEditor extends DatabaseObjectEditor implements IEditableCachedObject {
         * Saves the visible languages of a user.
         * 
         * @param       array           $languageIDs
+        * @param       boolean         $deleteOldLanguages
         */
-       public function addToLanguages(array $languageIDs) {
+       public function addToLanguages(array $languageIDs, $deleteOldLanguages = true) {
                // remove previous languages
-               $sql = "DELETE FROM     wcf".WCF_N."_user_to_language
-                       WHERE           userID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($this->userID));
+               if ($deleteOldLanguages) {
+                       $sql = "DELETE FROM     wcf".WCF_N."_user_to_language
+                               WHERE           userID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($this->userID));
+               }
                
                // insert language ids
-               $sql = "INSERT INTO     wcf".WCF_N."_user_to_language
-                                       (userID, languageID)
-                       VALUES          (?, ?)";
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_user_to_language
+                                               (userID, languageID)
+                       VALUES                  (?, ?)";
                $statement = WCF::getDB()->prepareStatement($sql);
                
                if (!empty($languageIDs)) {
diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php
new file mode 100644 (file)
index 0000000..07c1e31
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\comment\CommentAction;
+
+/**
+ * Imports comments.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class AbstractCommentImporter implements IImporter {
+       /**
+        * object type id for comments
+        * @var integer
+        */
+       protected $objectTypeID = 0;
+       
+       /**
+        * object type name
+        * @var integer
+        */
+       protected $objectTypeName = '';
+       
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               if ($data['userID']) $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               if (!$data['userID']) $data['userID'] = null;
+               
+               $action = new CommentAction(array(), 'create', array(
+                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
+               ));
+               $returnValues = $action->executeAction();
+               $newID = $returnValues['returnValues']->commentID;
+               
+               ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $newID);
+               
+               return $newID;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php
new file mode 100644 (file)
index 0000000..40a0a5d
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\comment\response\CommentResponseAction;
+
+/**
+ * Imports comment responses.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class AbstractCommentResponseImporter implements IImporter {
+       /**
+        * object type name
+        * @var integer
+        */
+       protected $objectTypeName = '';
+       
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               if ($data['userID']) $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               if (!$data['userID']) $data['userID'] = null;
+               
+               $data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']);
+               if ($data['commentID']) return 0;
+               
+               $action = new CommentResponseAction(array(), 'create', array(
+                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
+               ));
+               $returnValues = $action->executeAction();
+               $newID = $returnValues['returnValues']->responseID;
+               
+               return $newID;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php
new file mode 100644 (file)
index 0000000..10680c1
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\user\avatar\UserAvatarAction;
+use wcf\data\user\avatar\UserAvatarEditor;
+use wcf\util\FileUtil;
+use wcf\system\WCF;
+
+/**
+ * Imports user avatars.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class UserAvatarImporter implements IImporter {
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $fileLocation = $data['fileLocation'];
+               unset($data['fileLocation']);
+               
+               $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               if ($data['userID']) return 0;
+               
+               if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($fileLocation);
+               
+               $action = new UserAvatarAction(array(), 'create', array(
+                       'data' => $data         
+               ));
+               $returnValues = $action->executeAction();
+               $avatar = $returnValues['returnValues'];
+               
+               // check avatar directory
+               // and create subdirectory if necessary
+               $dir = dirname($avatar->getLocation());
+               if (!@file_exists($dir)) {
+                       FileUtil::makePath($dir, 0777);
+               }
+               
+               // copy file
+               if (@copy($fileLocation, $avatar->getLocation())) {
+                       // create thumbnails
+                       $action = new UserAvatarAction(array($avatar), 'generateThumbnails');
+                       $action->executeAction();
+                       
+                       // update owner
+                       $sql = "UPDATE  wcf".WCF_N."_user
+                               SET     avatarID = ?
+                               WHERE   userID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($avatar->avatarID, $data['userID']));
+                       
+                       return $avatar->avatarID;
+               }
+               else {
+                       // copy failed; delete avatar
+                       $editor = new UserAvatarEditor($avatar);
+                       $editor->delete();
+               }
+               
+               return 0;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php
new file mode 100644 (file)
index 0000000..0ed7fba
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\comment\CommentAction;
+use wcf\data\object\type\ObjectTypeCache;
+
+/**
+ * Imports user profile comments.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class UserCommentImporter extends AbstractCommentImporter {
+       /**
+        * @see wcf\system\importer\AbstractCommentImporter::$objectTypeName
+        */
+       protected $objectTypeName = 'com.woltlab.wcf.user.comment';
+       
+       /**
+        * Creates a new UserCommentImporter object.
+        */
+       public function __construct() {
+               $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.user.profileComment');
+               $this->objectTypeID = $objectType->objectTypeID;
+       }
+       
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['objectID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['objectID']);
+               if (!$data['objectID']) return 0;
+               
+               return parent::import($oldID, $data);
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/UserCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserCommentResponseImporter.class.php
new file mode 100644 (file)
index 0000000..1e734e2
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+namespace wcf\system\importer;
+
+/**
+ * Imports user profile comment response.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class UserCommentResponseImporter extends AbstractCommentResponseImporter {
+       /**
+        * @see wcf\system\importer\AbstractCommentResponseImporter::$objectTypeName
+        */
+       protected $objectTypeName = 'com.woltlab.wcf.user.comment';
+}
index 626e06ee38b03cfaa75765a69ec66fdba4a6ec5f..c2cf18becb17baac5fe64dac1cf8d1bada8ddf41 100644 (file)
@@ -14,7 +14,7 @@ use wcf\data\user\follow\UserFollowAction;
  */
 class UserFollowerImporter implements IImporter {
        /**
-        * @see wcf\system\importer::import()
+        * @see wcf\system\importer\IImporter::import()
         */
        public function import($oldID, array $data) {
                $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
index 254307a5a0e55d2ba06d40b6492533e7b8df2666..96d8222e1006e75d58e34290d4b8ddc62687de1b 100644 (file)
@@ -14,7 +14,7 @@ use wcf\data\user\group\UserGroupAction;
  */
 class UserGroupImporter implements IImporter {
        /**
-        * @see wcf\system\importer::import()
+        * @see wcf\system\importer\IImporter::import()
         */
        public function import($oldID, array $data) {
                $action = new UserGroupAction(array(), 'create', array(
index f7b20cefffa40656f68b2b0070d7e41186fcd1d3..0a5fe99a0d701fdbe3edf3c11bbd4c84ddb3b852 100644 (file)
@@ -17,7 +17,7 @@ use wcf\system\WCF;
  */
 class UserImporter implements IImporter {
        /**
-        * @see wcf\system\importer::import()
+        * @see wcf\system\importer\IImporter::import()
         */
        public function import($oldID, array $data) {
                // check existing user id
diff --git a/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php
new file mode 100644 (file)
index 0000000..adcdfce
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\user\option\UserOptionAction;
+use wcf\data\user\option\UserOptionEditor;
+use wcf\system\language\LanguageFactory;
+use wcf\system\WCF;
+
+/**
+ * Imports user options.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class UserOptionImporter implements IImporter {
+       /**
+        * language category id
+        * @var integer
+        */
+       protected $languageCategoryID = null;
+       
+       /**
+        * Creates a new UserOptionImporter object.
+        */
+       public function __construct() {
+               // get language category id
+               $sql = "SELECT  languageCategoryID
+                       FROM    wcf".WCF_N."_language_category
+                       WHERE   languageCategory = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array('wcf.user.option'));
+               $row = $statement->fetchArray();
+               $this->languageCategoryID = $row['languageCategoryID'];
+       }
+       
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $name = $data['name'];
+               unset($data['name']);
+               $data['packageID'] = 1;
+               
+               // save option
+               $action = new UserOptionAction(array(), 'create', array('data' => $data));
+               $returnValues = $action->executeAction();
+               $userOption = $returnValues['returnValues'];
+               
+               // update generic option name
+               $editor = new UserOptionEditor($userOption);
+               $editor->update(array(
+                       'optionName' => 'option'.$userOption->optionID
+               ));
+               
+               // save name
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_language_item
+                                               (languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)
+                       VALUES                  (?, ?, ?, ?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       LanguageFactory::getInstance()->getDefaultLanguageID(),
+                       'wcf.user.option.option'.$userOption->optionID,
+                       $name,
+                       0,
+                       $this->languageCategoryID,
+                       1
+               ));
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.option', $oldID, $userOption->optionID);
+               
+               return $userOption->optionID;
+       }
+}
index f97b9f7934d0b63d9e4e090b35efe6d74650e537..a79100b07486f77686c47df14113e6c1b1acf3f5 100644 (file)
@@ -15,7 +15,7 @@ use wcf\data\user\rank\UserRankAction;
  */
 class UserRankImporter implements IImporter {
        /**
-        * @see wcf\system\importer::import()
+        * @see wcf\system\importer\IImporter::import()
         */
        public function import($oldID, array $data) {
                $data['groupID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $data['groupID']);