From 6eb1d79069f8ce02e594202dabf760bc15720240 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 7 Jul 2013 21:34:49 +0200 Subject: [PATCH] Importer optimizations --- .../importer/AbstractAttachmentImporter.class.php | 11 ++++------- .../importer/AbstractCommentImporter.class.php | 2 +- .../AbstractCommentResponseImporter.class.php | 2 +- .../system/importer/AbstractLikeImporter.class.php | 2 +- .../system/importer/AbstractPollImporter.class.php | 2 +- .../importer/AbstractPollOptionImporter.class.php | 2 +- .../AbstractPollOptionVoteImporter.class.php | 2 +- .../AbstractWatchedObjectImporter.class.php | 2 +- .../files/lib/system/importer/IImporter.class.php | 3 ++- .../system/importer/UserAvatarImporter.class.php | 13 +++++-------- .../system/importer/UserCommentImporter.class.php | 2 +- .../system/importer/UserFollowerImporter.class.php | 2 +- .../system/importer/UserGroupImporter.class.php | 2 +- .../lib/system/importer/UserImporter.class.php | 14 +++++--------- .../system/importer/UserOptionImporter.class.php | 6 ++---- .../lib/system/importer/UserRankImporter.class.php | 2 +- 16 files changed, 29 insertions(+), 40 deletions(-) diff --git a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php index 726c2abc8e..2ae24f7e92 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php @@ -25,15 +25,12 @@ class AbstractAttachmentImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { - $fileLocation = $data['fileLocation']; - unset($data['fileLocation']); - + public function import($oldID, array $data, array $additionalData = array()) { // check file location - if (!@file_exists($fileLocation)) return 0; + if (!@file_exists($additionalData['fileLocation'])) return 0; // get file hash - if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($fileLocation); + if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($additionalData['fileLocation']); // get user id if ($data['userID']) $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); @@ -54,7 +51,7 @@ class AbstractAttachmentImporter implements IImporter { // copy file try { - if (!copy($fileLocation, $attachment->getLocation())) { + if (!copy($additionalData['fileLocation'], $attachment->getLocation())) { throw new SystemException(); } diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php index 607ece88da..d58786ed65 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php @@ -28,7 +28,7 @@ class AbstractCommentImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { if ($data['userID']) $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); $action = new CommentAction(array(), 'create', array( diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php index b0047e470f..7d46815adc 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -22,7 +22,7 @@ class AbstractCommentResponseImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { if ($data['userID']) $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); $data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']); diff --git a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php index 14d24c58a5..46adfe34a9 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php @@ -22,7 +22,7 @@ class AbstractLikeImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { if ($data['objectUserID']) $data['objectUserID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['objectUserID']); $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); if (!$data['userID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php index 31cf2fabed..e92bf9f289 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php @@ -28,7 +28,7 @@ class AbstractPollImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $poll = PollEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID))); ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $poll->pollID); diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php index 8f1d8693c8..6857b73fe4 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php @@ -28,7 +28,7 @@ class AbstractPollOptionImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['pollID'] = ImportHandler::getInstance()->getNewID($this->pollObjectTypeName, $data['pollID']); if (!$data['pollID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php index 1610dedb85..c01c3353f4 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php @@ -28,7 +28,7 @@ class AbstractPollOptionVoteImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); if (!$data['userID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php index 1329628ef1..18b4a33ff8 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php @@ -22,7 +22,7 @@ class AbstractWatchedObjectImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); if (!$data['userID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/IImporter.class.php b/wcfsetup/install/files/lib/system/importer/IImporter.class.php index a7a1d2a423..a6a2590122 100644 --- a/wcfsetup/install/files/lib/system/importer/IImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/IImporter.class.php @@ -17,7 +17,8 @@ interface IImporter { * * @param mixed $oldID * @param array $data + * @param array $additionalData * @return mixed new id */ - public function import($oldID, array $data); + public function import($oldID, array $data, array $additionalData = array()); } diff --git a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php index 669cb7eaf5..9906218b9a 100644 --- a/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php @@ -20,15 +20,12 @@ class UserAvatarImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { - $fileLocation = $data['fileLocation']; - unset($data['fileLocation']); - + public function import($oldID, array $data, array $additionalData = array()) { // check file location - if (!@file_exists($fileLocation)) return 0; + if (!@file_exists($additionalData['fileLocation'])) return 0; // get image size - $imageData = @getimagesize($fileLocation); + $imageData = @getimagesize($additionalData['fileLocation']); if ($imageData === false) return 0; $data['width'] = $imageData[0]; $data['height'] = $imageData[1]; @@ -39,7 +36,7 @@ class UserAvatarImporter implements IImporter { if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) return 0; // get file hash - if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($fileLocation); + if (empty($data['fileHash'])) $data['fileHash'] = sha1_file($additionalData['fileLocation']); // get user id $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); @@ -61,7 +58,7 @@ class UserAvatarImporter implements IImporter { // copy file try { - if (!copy($fileLocation, $avatar->getLocation())) { + if (!copy($additionalData['fileLocation'], $avatar->getLocation())) { throw new SystemException(); } diff --git a/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php index 0ed7fbac34..5b9448950d 100644 --- a/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php @@ -30,7 +30,7 @@ class UserCommentImporter extends AbstractCommentImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['objectID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['objectID']); if (!$data['objectID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php index c2cf18becb..f357d209ac 100644 --- a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php @@ -16,7 +16,7 @@ class UserFollowerImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); $data['followUserID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['followUserID']); if (!$data['userID'] || !$data['followUserID']) return 0; diff --git a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php index 96d8222e10..46b7228069 100644 --- a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php @@ -16,7 +16,7 @@ class UserGroupImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $action = new UserGroupAction(array(), 'create', array( 'data' => $data )); diff --git a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php index 0a5fe99a0d..5bc39b6eb3 100644 --- a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php @@ -19,7 +19,7 @@ class UserImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { // check existing user id $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_user @@ -31,19 +31,17 @@ class UserImporter implements IImporter { // get group ids $groupIDs = array(); - if (isset($data['groupIDs'])) { - foreach ($data['groupIDs'] as $oldGroupID) { + if (isset($additionalData['groupIDs'])) { + foreach ($additionalData['groupIDs'] as $oldGroupID) { $newGroupID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $oldGroupID); if ($newGroupID) $groupIDs[] = $newGroupID; } - - unset($data['groupIDs']); } // handle user options $userOptions = array(); - if (isset($data['options'])) { - foreach ($data['options'] as $optionName => $optionValue) { + if (isset($additionalData['options'])) { + foreach ($additionalData['options'] as $optionName => $optionValue) { if (is_int($optionName)) $optionID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.option', $optionName); else $optionID = User::getUserOptionID($optionName); @@ -51,8 +49,6 @@ class UserImporter implements IImporter { $userOptions[$optionID] = $optionValue; } } - - unset($data['options']); } // create user diff --git a/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php index adcdfce13e..1a3b50c3a4 100644 --- a/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php @@ -39,9 +39,7 @@ class UserOptionImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { - $name = $data['name']; - unset($data['name']); + public function import($oldID, array $data, array $additionalData = array()) { $data['packageID'] = 1; // save option @@ -63,7 +61,7 @@ class UserOptionImporter implements IImporter { $statement->execute(array( LanguageFactory::getInstance()->getDefaultLanguageID(), 'wcf.user.option.option'.$userOption->optionID, - $name, + $additionalData, 0, $this->languageCategoryID, 1 diff --git a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php index a79100b074..49d487aacf 100644 --- a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php @@ -17,7 +17,7 @@ class UserRankImporter implements IImporter { /** * @see wcf\system\importer\IImporter::import() */ - public function import($oldID, array $data) { + public function import($oldID, array $data, array $additionalData = array()) { $data['groupID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $data['groupID']); if (!$data['groupID']) $data['groupID'] = UserGroup::getGroupByType(UserGroup::USERS)->groupID; -- 2.20.1