From c2836ca37fc33f87d83103aea950d7a1c60ceca2 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 13 Aug 2013 13:33:51 +0200 Subject: [PATCH] Importer improvements --- .../importer/AbstractACLImporter.class.php | 2 +- .../AbstractAttachmentImporter.class.php | 14 +++++----- .../AbstractCategoryImporter.class.php | 19 ++++++------- .../AbstractCommentImporter.class.php | 19 ++++++------- .../AbstractCommentResponseImporter.class.php | 17 ++++++------ .../importer/AbstractImporter.class.php | 27 +++++++++++++++++++ .../importer/AbstractLikeImporter.class.php | 7 ++++- .../importer/AbstractPollImporter.class.php | 7 ++++- .../AbstractPollOptionImporter.class.php | 7 ++++- .../AbstractPollOptionVoteImporter.class.php | 2 +- .../AbstractWatchedObjectImporter.class.php | 16 ++++++----- .../lib/system/importer/IImporter.class.php | 7 +++++ .../system/importer/ImportHandler.class.php | 18 +++++++++---- .../importer/LabelGroupImporter.class.php | 7 ++++- .../system/importer/LabelImporter.class.php | 7 ++++- .../system/importer/SmileyImporter.class.php | 7 ++++- .../importer/UserAvatarImporter.class.php | 13 ++++----- .../importer/UserFollowerImporter.class.php | 7 ++++- .../importer/UserGroupImporter.class.php | 7 ++++- .../system/importer/UserImporter.class.php | 7 ++++- .../importer/UserOptionImporter.class.php | 7 ++++- .../importer/UserRankImporter.class.php | 19 ++++++------- 22 files changed, 171 insertions(+), 72 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractImporter.class.php diff --git a/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php index a89e1b9705..22984d0b40 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php index cdf9c7d46f..6b71e83823 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php @@ -1,6 +1,5 @@ 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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php index ed26c4faa7..b59f3f560e 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php @@ -1,6 +1,6 @@ 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; } } diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php index 3e00fee312..1333856377 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php @@ -1,6 +1,6 @@ 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; } } diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php index 9e78a90ce6..d6049fb9bf 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -1,6 +1,6 @@ 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 index 0000000000..a281ee75d0 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractImporter.class.php @@ -0,0 +1,27 @@ + + * @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; + } +} diff --git a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php index 46adfe34a9..a7f9b25fbf 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php index e92bf9f289..8e6e438d24 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php index 6857b73fe4..db1c10d2fd 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php index abde6401a5..974c4ab230 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php index 18b4a33ff8..f6f498c5a6 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php @@ -1,6 +1,6 @@ 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; } } diff --git a/wcfsetup/install/files/lib/system/importer/IImporter.class.php b/wcfsetup/install/files/lib/system/importer/IImporter.class.php index a6a2590122..a18e39c007 100644 --- a/wcfsetup/install/files/lib/system/importer/IImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/IImporter.class.php @@ -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(); } diff --git a/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php b/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php index 51930f4497..d089dbf9e1 100644 --- a/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php +++ b/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/system/importer/LabelGroupImporter.class.php b/wcfsetup/install/files/lib/system/importer/LabelGroupImporter.class.php index 8c43f1208e..771003f5ee 100644 --- a/wcfsetup/install/files/lib/system/importer/LabelGroupImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/LabelGroupImporter.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/system/importer/LabelImporter.class.php b/wcfsetup/install/files/lib/system/importer/LabelImporter.class.php index b46f22a11c..9d8a0754d8 100644 --- a/wcfsetup/install/files/lib/system/importer/LabelImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/LabelImporter.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php b/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php index 551c2fdd86..cfd029c02e 100644 --- a/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php @@ -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 * diff --git a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php index 9906218b9a..2e345745d2 100644 --- a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php index 3aa714ae62..f8676c5172 100644 --- a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php index 8d657e6c70..e39883ad2a 100644 --- a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php index e83b8e3561..e2cb7c4463 100644 --- a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php @@ -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() */ diff --git a/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php index 50a3a5e22a..cf2a69ff6a 100644 --- a/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php index 49d487aacf..53a4d2128b 100644 --- a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php @@ -1,7 +1,7 @@ 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; } } -- 2.20.1