From 695780d7d54c4062cd4af0001940e25ffbef749b Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 2 Jul 2013 16:35:33 +0200 Subject: [PATCH] Added more import features --- com.woltlab.wcf/objectType.xml | 4 +- .../files/lib/data/user/UserAction.class.php | 14 ++-- .../files/lib/data/user/UserEditor.class.php | 19 +++-- .../AbstractCommentImporter.class.php | 45 +++++++++++ .../AbstractCommentResponseImporter.class.php | 40 ++++++++++ .../importer/UserAvatarImporter.class.php | 67 ++++++++++++++++ .../importer/UserCommentImporter.class.php | 39 ++++++++++ .../UserCommentResponseImporter.class.php | 19 +++++ .../importer/UserFollowerImporter.class.php | 2 +- .../importer/UserGroupImporter.class.php | 2 +- .../system/importer/UserImporter.class.php | 2 +- .../importer/UserOptionImporter.class.php | 76 +++++++++++++++++++ .../importer/UserRankImporter.class.php | 2 +- 13 files changed, 308 insertions(+), 23 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/UserCommentResponseImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index e45c17a049..88a8c83016 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -222,7 +222,7 @@ com.woltlab.wcf.importer - + com.woltlab.wcf.user.follower com.woltlab.wcf.importer diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 635b83c967..e74292d6e9 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/data/user/UserEditor.class.php b/wcfsetup/install/files/lib/data/user/UserEditor.class.php index eafd19d18c..265fe9f79e 100644 --- a/wcfsetup/install/files/lib/data/user/UserEditor.class.php +++ b/wcfsetup/install/files/lib/data/user/UserEditor.class.php @@ -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 index 0000000000..07c1e31014 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentImporter.class.php @@ -0,0 +1,45 @@ + + * @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 index 0000000000..40a0a5d173 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -0,0 +1,40 @@ + + * @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 index 0000000000..10680c1437 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/UserAvatarImporter.class.php @@ -0,0 +1,67 @@ + + * @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 index 0000000000..0ed7fbac34 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/UserCommentImporter.class.php @@ -0,0 +1,39 @@ + + * @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 index 0000000000..1e734e2b5c --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/UserCommentResponseImporter.class.php @@ -0,0 +1,19 @@ + + * @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'; +} diff --git a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php index 626e06ee38..c2cf18becb 100644 --- a/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserFollowerImporter.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php index 254307a5a0..96d8222e10 100644 --- a/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserGroupImporter.class.php @@ -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( diff --git a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php index f7b20cefff..0a5fe99a0d 100644 --- a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php @@ -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 index 0000000000..adcdfce13e --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/UserOptionImporter.class.php @@ -0,0 +1,76 @@ + + * @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; + } +} diff --git a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php index f97b9f7934..a79100b074 100644 --- a/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserRankImporter.class.php @@ -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']); -- 2.20.1