Importer improvements
authorMarcel Werk <burntime@woltlab.com>
Tue, 13 Aug 2013 11:33:51 +0000 (13:33 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 13 Aug 2013 11:33:51 +0000 (13:33 +0200)
22 files changed:
wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php
wcfsetup/install/files/lib/system/importer/IImporter.class.php
wcfsetup/install/files/lib/system/importer/ImportHandler.class.php
wcfsetup/install/files/lib/system/importer/LabelGroupImporter.class.php
wcfsetup/install/files/lib/system/importer/LabelImporter.class.php
wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php
wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php
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
wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php

index a89e1b9705bb01f45f17cb5ef84d2fd3dcb24288..22984d0b405a4d0835cf6924612b4464e0d9851f 100644 (file)
@@ -12,7 +12,7 @@ use wcf\system\WCF;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractACLImporter implements IImporter {
+class AbstractACLImporter extends AbstractImporter {
        /**
         * object type id for options
         * @var integer
index cdf9c7d46f9127ebcc7abfd1f64191adde371ea4..6b71e83823da3583ab97afb7c239d8858b8d356b 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\attachment\AttachmentAction;
 use wcf\data\attachment\AttachmentEditor;
 use wcf\system\exception\SystemException;
 use wcf\util\StringUtil;
@@ -15,7 +14,12 @@ use wcf\util\StringUtil;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractAttachmentImporter implements IImporter {
+class AbstractAttachmentImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\attachment\Attachment';
+       
        /**
         * object type id for attachments
         * @var integer
@@ -45,11 +49,7 @@ class AbstractAttachmentImporter implements IImporter {
                $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
                
                // save attachment
-               $action = new AttachmentAction(array(), 'create', array(
-                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
-               ));
-               $returnValues = $action->executeAction();
-               $attachment = $returnValues['returnValues'];
+               $attachment = AttachmentEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
                
                // check attachment directory
                // and create subdirectory if necessary
index ed26c4faa7aac73a9a62bb623df11202844fe06d..b59f3f560e1eef9aa3ba808e856acbf5de0ce176 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\category\CategoryAction;
+use wcf\data\category\CategoryEditor;
 
 /**
  * Imports categories.
@@ -12,7 +12,12 @@ use wcf\data\category\CategoryAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractCategoryImporter implements IImporter {
+class AbstractCategoryImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\category\Category';
+       
        /**
         * object type id for categories
         * @var integer
@@ -31,14 +36,10 @@ class AbstractCategoryImporter implements IImporter {
        public function import($oldID, array $data, array $additionalData = array()) {
                if (!empty($data['parentCategoryID'])) $data['parentCategoryID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['parentCategoryID']);
                
-               $action = new CategoryAction(array(), 'create', array(
-                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
-               ));
-               $returnValues = $action->executeAction();
-               $newID = $returnValues['returnValues']->categoryID;
+               $category = CategoryEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
                
-               ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $newID);
+               ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $category->categoryID);
                
-               return $newID;
+               return $category->categoryID;
        }
 }
index 3e00fee312aa5679dcd7f2bdff236c18adc86f0d..1333856377943a4abc3d9fb714d48d3753885f3b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\comment\CommentAction;
+use wcf\data\comment\CommentEditor;
 
 /**
  * Imports comments.
@@ -12,7 +12,12 @@ use wcf\data\comment\CommentAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractCommentImporter implements IImporter {
+class AbstractCommentImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\comment\Comment';
+       
        /**
         * object type id for comments
         * @var integer
@@ -31,14 +36,10 @@ class AbstractCommentImporter implements IImporter {
        public function import($oldID, array $data, array $additionalData = array()) {
                $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
                
-               $action = new CommentAction(array(), 'create', array(
-                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
-               ));
-               $returnValues = $action->executeAction();
-               $newID = $returnValues['returnValues']->commentID;
+               $comment = CommentEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
                
-               ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $newID);
+               ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $comment->commentID);
                
-               return $newID;
+               return $comment->commentID;
        }
 }
index 9e78a90ce62661eb6548fb62283c39ab6a7b842a..d6049fb9bf1b1badfe3defc9aa83e7d9eb2058cd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\comment\response\CommentResponseAction;
+use wcf\data\comment\response\CommentResponseEditor;
 
 /**
  * Imports comment responses.
@@ -12,7 +12,12 @@ use wcf\data\comment\response\CommentResponseAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractCommentResponseImporter implements IImporter {
+class AbstractCommentResponseImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\comment\response\CommentResponse';
+       
        /**
         * object type name
         * @var string
@@ -28,12 +33,8 @@ class AbstractCommentResponseImporter implements IImporter {
                $data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']);
                if (!$data['commentID']) return 0;
                
-               $action = new CommentResponseAction(array(), 'create', array(
-                       'data' => $data         
-               ));
-               $returnValues = $action->executeAction();
-               $newID = $returnValues['returnValues']->responseID;
+               $response = CommentResponseEditor::create($data);
                
-               return $newID;
+               return $response->responseID;
        }
 }
diff --git a/wcfsetup/install/files/lib/system/importer/AbstractImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractImporter.class.php
new file mode 100644 (file)
index 0000000..a281ee7
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace wcf\system\importer;
+
+/**
+ * Basic implementation of IImporter.
+ *
+ * @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
+ */
+abstract class AbstractImporter implements IImporter {
+       /**
+        * database object class name
+        * @var string
+        */
+       protected $className = '';
+       
+       /**
+        * @see wcf\system\importer\IImporter::getClassName()
+        */
+       public function getClassName() {
+               return $this->className;
+       }
+}
index 46adfe34a9e76fcfe9856120b04109500d20c093..a7f9b25fbf07e5c944114378f16a4541cf9bfed7 100644 (file)
@@ -12,7 +12,12 @@ use wcf\data\like\LikeEditor;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractLikeImporter implements IImporter {
+class AbstractLikeImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\like\Like';
+       
        /**
         * object type id for likes
         * @var integer
index e92bf9f289fb0a935960d1d18bad84856b5bed34..8e6e438d24c11a6f331409ec1d2ac3acb3d53fa7 100644 (file)
@@ -12,7 +12,12 @@ use wcf\data\poll\PollEditor;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractPollImporter implements IImporter {
+class AbstractPollImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\poll\Poll';
+       
        /**
         * object type id for poll
         * @var integer
index 6857b73fe4cd5d924b87fd77614f18276db4b54b..db1c10d2fd6a7110332633541efe890a659fd88c 100644 (file)
@@ -12,7 +12,12 @@ use wcf\data\poll\option\PollOptionEditor;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractPollOptionImporter implements IImporter {
+class AbstractPollOptionImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\poll\option\PollOption';
+       
        /**
         * option object type name
         * @var string
index abde6401a56032cbd7ea02f1f50b94ff7390076d..974c4ab23052469ee513e078ca143c2bf573c25d 100644 (file)
@@ -12,7 +12,7 @@ use wcf\system\WCF;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractPollOptionVoteImporter implements IImporter {
+class AbstractPollOptionVoteImporter extends AbstractImporter {
        /**
         * option object type name
         * @var string
index 18b4a33ff8636dd68dc824a935ebab9b8aa999ef..f6f498c5a6c3b5d04bb8aa97021371e9fc6bad8e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\system\importer;
-use wcf\data\user\object\watch\UserObjectWatchAction;
+use wcf\data\user\object\watch\UserObjectWatchEditor;
 
 /**
  * Imports watched objects.
@@ -12,7 +12,12 @@ use wcf\data\user\object\watch\UserObjectWatchAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class AbstractWatchedObjectImporter implements IImporter {
+class AbstractWatchedObjectImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\object\watch';
+       
        /**
         * object type id for watched objects
         * @var integer
@@ -26,10 +31,7 @@ class AbstractWatchedObjectImporter implements IImporter {
                $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
                if (!$data['userID']) return 0;
                
-               $action = new UserObjectWatchAction(array(), 'create', array(
-                       'data' => array_merge($data, array('objectTypeID' => $this->objectTypeID))              
-               ));
-               $returnValues = $action->executeAction();
-               return $returnValues['returnValues']->watchID;
+               $watch = UserObjectWatchEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
+               return $watch->watchID;
        }
 }
index a6a2590122af78edc91edf50e2bec55bef8b0342..a18e39c007463c36a30bbd9aa9e976a3bfcf3c28 100644 (file)
@@ -21,4 +21,11 @@ interface IImporter {
         * @return      mixed           new id
         */
        public function import($oldID, array $data, array $additionalData = array());
+       
+       /**
+        * Returns database object class name.
+        * 
+        * @return      string
+        */
+       public function getClassName();
 }
index 51930f449789735f803b52b80eab88e8bb29959d..d089dbf9e17bb0f96adb9d17bf0b2725ad067729 100644 (file)
@@ -93,12 +93,20 @@ class ImportHandler extends SingletonFactory implements IAJAXInvokeAction {
                
                if (!isset($this->idMappingCache[$objectTypeID]) || !array_key_exists($oldID, $this->idMappingCache[$objectTypeID])) {
                        $this->idMappingCache[$objectTypeID][$oldID] = null;
+                       $importer = $this->getImporter($type);
+                       $tableName = $indexName = '';
+                       if ($importer->getClassName()) {
+                               $tableName = call_user_func(array($importer->getClassName(), 'getDatabaseTableName'));
+                               $indexName = call_user_func(array($importer->getClassName(), 'getDatabaseTableIndexName'));
+                       }
                        
-                       $sql = "SELECT  newID
-                               FROM    wcf".WCF_N."_import_mapping
-                               WHERE   importHash = ?
-                                       AND objectTypeID = ?
-                                       AND oldID = ?";
+                       $sql = "SELECT          import_mapping.newID
+                               FROM            wcf".WCF_N."_import_mapping import_mapping
+                               ".($tableName ? "LEFT JOIN ".$tableName." object_table ON (object_table.".$indexName." = import_mapping.newID)" : '')."
+                               WHERE           import_mapping.importHash = ?
+                                               AND import_mapping.objectTypeID = ?
+                                               AND import_mapping.oldID = ?
+                                               ".($tableName ? "AND object_table.".$indexName." IS NOT NULL" : '');
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute(array($this->importHash, $objectTypeID, $oldID));
                        $row = $statement->fetchArray();
index 8c43f1208e612c2270ba54f64290f6b557764686..771003f5ee63d1b91e182390e1f98e26910cddb5 100644 (file)
@@ -13,7 +13,12 @@ use wcf\system\WCF;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class LabelGroupImporter implements IImporter {
+class LabelGroupImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\label\group\LabelGroup';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
index b46f22a11cfbf689ecc3848696b0b0304fdb12c4..9d8a0754d84b1142cae253d27c9f7ca1675b6bc8 100644 (file)
@@ -13,7 +13,12 @@ use wcf\system\WCF;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class LabelImporter implements IImporter {
+class LabelImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\label\Label';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
index 551c2fdd8616e07b6c967c71ff918879984a5b72..cfd029c02e200723bfaeb2d3b9e800f6535513aa 100644 (file)
@@ -14,7 +14,12 @@ use wcf\util\StringUtil;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class SmileyImporter implements IImporter {
+class SmileyImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\smiley\Smiley';
+       
        /**
         * known smiley codes
         * 
index 9906218b9a3f6fb06bd9dfc81b8936f956f0e535..2e345745d2e706b1a22e673d90768e020129c772 100644 (file)
@@ -16,7 +16,12 @@ use wcf\util\FileUtil;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserAvatarImporter implements IImporter {
+class UserAvatarImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\avatar\UserAvatar';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
@@ -43,11 +48,7 @@ class UserAvatarImporter implements IImporter {
                if (!$data['userID']) return 0;
                
                // save avatar
-               $action = new UserAvatarAction(array(), 'create', array(
-                       'data' => $data
-               ));
-               $returnValues = $action->executeAction();
-               $avatar = $returnValues['returnValues'];
+               $avatar = UserAvatarEditor::create($data);
                
                // check avatar directory
                // and create subdirectory if necessary
index 3aa714ae62e7377e8eb2853271608a8e57fc747f..f8676c517284ab2c4a5b2eae8c5c8fe31f3bb8e2 100644 (file)
@@ -12,7 +12,12 @@ use wcf\system\WCF;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserFollowerImporter implements IImporter {
+class UserFollowerImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\follow\UserFollow';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
index 8d657e6c704b4cdd78da136039786217956d6e7f..e39883ad2a27ade9144b3c5bd7f62b2d97938ca3 100644 (file)
@@ -13,7 +13,12 @@ use wcf\data\user\group\UserGroupAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserGroupImporter implements IImporter {
+class UserGroupImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\group\UserGroup';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
index e83b8e35619f715207a99a359f4bc0df4b15350c..e2cb7c44633d68f84c1f40478d2ad8888d4534cf 100644 (file)
@@ -17,7 +17,12 @@ use wcf\util\StringUtil;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserImporter implements IImporter {
+class UserImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\User';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
index 50a3a5e22aabdc8e6cf88a0df2f1a586604f6897..cf2a69ff6aa670bc26ea6f2a2f9ba3ee927d6cc1 100644 (file)
@@ -16,7 +16,12 @@ use wcf\util\StringUtil;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserOptionImporter implements IImporter {
+class UserOptionImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\option\UserOption';
+       
        /**
         * language category id
         * @var integer
index 49d487aacf5b6b96a88fe92a31ebafa5eed30fff..53a4d2128bb30f2a36ac812a843041cab2da64a1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace wcf\system\importer;
 use wcf\data\user\group\UserGroup;
-use wcf\data\user\rank\UserRankAction;
+use wcf\data\user\rank\UserRankEditor;
 
 /**
  * Imports user ranks.
@@ -13,7 +13,12 @@ use wcf\data\user\rank\UserRankAction;
  * @subpackage system.importer
  * @category   Community Framework
  */
-class UserRankImporter implements IImporter {
+class UserRankImporter extends AbstractImporter {
+       /**
+        * @see wcf\system\importer\AbstractImporter::$className
+        */
+       protected $className = 'wcf\data\user\rank\UserRank';
+       
        /**
         * @see wcf\system\importer\IImporter::import()
         */
@@ -21,14 +26,10 @@ class UserRankImporter implements IImporter {
                $data['groupID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $data['groupID']);
                if (!$data['groupID']) $data['groupID'] = UserGroup::getGroupByType(UserGroup::USERS)->groupID;
                
-               $action = new UserRankAction(array(), 'create', array(
-                       'data' => $data         
-               ));
-               $returnValues = $action->executeAction();
-               $newID = $returnValues['returnValues']->rankID;
+               $rank = UserRankEditor::create($data);
                
-               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.rank', $oldID, $newID);
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.rank', $oldID, $rank->rankID);
                
-               return $newID;
+               return $rank->rankID;
        }
 }