<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>
// 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;
* 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)) {
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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);
+ }
+}
--- /dev/null
+<?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';
+}
*/
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']);
*/
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(
*/
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
--- /dev/null
+<?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;
+ }
+}
*/
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']);