From fc531efba131c2fb6eab15a30ed5b1e0769c36fd Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sat, 6 Jul 2013 19:32:40 +0200 Subject: [PATCH] Added additional import features --- .../AbstractAttachmentImporter.class.php | 14 +++++- .../AbstractCommentResponseImporter.class.php | 2 +- .../importer/AbstractPollImporter.class.php | 38 ++++++++++++++ .../AbstractPollOptionImporter.class.php | 41 ++++++++++++++++ .../AbstractPollOptionVoteImporter.class.php | 49 +++++++++++++++++++ .../AbstractWatchedObjectImporter.class.php | 35 +++++++++++++ 6 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php create mode 100644 wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php diff --git a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php index 96b10745d7..726c2abc8e 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php @@ -3,6 +3,7 @@ namespace wcf\system\importer; use wcf\data\attachment\AttachmentAction; use wcf\data\attachment\AttachmentEditor; use wcf\system\exception\SystemException; +use wcf\util\StringUtil; /** * Imports attachments. @@ -16,7 +17,7 @@ use wcf\system\exception\SystemException; */ class AbstractAttachmentImporter implements IImporter { /** - * object type id for attachment + * object type id for attachments * @var integer */ protected $objectTypeID = 0; @@ -78,4 +79,15 @@ class AbstractAttachmentImporter implements IImporter { return 0; } + + protected function fixEmbeddedAttachments($message, $oldID, $newID) { + if (StringUtil::indexOfIgnoreCase($message, '[attach]'.$oldID.'[/attach]') !== false || StringUtil::indexOfIgnoreCase($message, '[attach='.$oldID.']') !== false) { + $message = StringUtil::replaceIgnoreCase('[attach]'.$oldID.'[/attach]', '[attach]'.$newID.'[/attach]', $message); + $message = StringUtil::replaceIgnoreCase('[attach='.$oldID.']', '[attach='.$newID.']', $message); + + return $message; + } + + return false; + } } diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php index e86bcb3ff7..b0047e470f 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -15,7 +15,7 @@ use wcf\data\comment\response\CommentResponseAction; class AbstractCommentResponseImporter implements IImporter { /** * object type name - * @var integer + * @var string */ protected $objectTypeName = ''; diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php new file mode 100644 index 0000000000..31cf2fabed --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php @@ -0,0 +1,38 @@ + + * @package com.woltlab.wcf + * @subpackage system.importer + * @category Community Framework + */ +class AbstractPollImporter implements IImporter { + /** + * object type id for poll + * @var integer + */ + protected $objectTypeID = 0; + + /** + * object type name + * @var string + */ + protected $objectTypeName = ''; + + /** + * @see wcf\system\importer\IImporter::import() + */ + public function import($oldID, array $data) { + $poll = PollEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID))); + + ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $poll->pollID); + + return $poll->pollID; + } +} diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php new file mode 100644 index 0000000000..8f1d8693c8 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php @@ -0,0 +1,41 @@ + + * @package com.woltlab.wcf + * @subpackage system.importer + * @category Community Framework + */ +class AbstractPollOptionImporter implements IImporter { + /** + * option object type name + * @var string + */ + protected $objectTypeName = ''; + + /** + * poll object type name + * @var string + */ + protected $pollObjectTypeName = ''; + + /** + * @see wcf\system\importer\IImporter::import() + */ + public function import($oldID, array $data) { + $data['pollID'] = ImportHandler::getInstance()->getNewID($this->pollObjectTypeName, $data['pollID']); + if (!$data['pollID']) return 0; + + $option = PollOptionEditor::create($data); + + ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $option->optionID); + + return $option->optionID; + } +} diff --git a/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php new file mode 100644 index 0000000000..70254aefc9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php @@ -0,0 +1,49 @@ + + * @package com.woltlab.wcf + * @subpackage system.importer + * @category Community Framework + */ +class AbstractPollOptionVoteImporter implements IImporter { + /** + * option object type name + * @var string + */ + protected $objectTypeName = ''; + + /** + * poll object type name + * @var string + */ + protected $pollObjectTypeName = ''; + + /** + * @see wcf\system\importer\IImporter::import() + */ + public function import($oldID, array $data) { + $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); + if (!$data['userID']) return 0; + + $data['pollID'] = ImportHandler::getInstance()->getNewID($this->pollObjectTypeName, $data['pollID']); + if (!$data['pollID']) return 0; + + $data['optionID'] = ImportHandler::getInstance()->getNewID($this->pollObjectTypeName, $data['optionID']); + if (!$data['optionID']) return 0; + + $sql = "INSERT INTO wcf".WCF_N."_poll_option_vote + (pollID, optionID, userID) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($data['pollID'], $data['optionID'], $data['userID'])); + + return 1; + } +} diff --git a/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php new file mode 100644 index 0000000000..1329628ef1 --- /dev/null +++ b/wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php @@ -0,0 +1,35 @@ + + * @package com.woltlab.wcf + * @subpackage system.importer + * @category Community Framework + */ +class AbstractWatchedObjectImporter implements IImporter { + /** + * object type id for watched objects + * @var integer + */ + protected $objectTypeID = 0; + + /** + * @see wcf\system\importer\IImporter::import() + */ + public function import($oldID, array $data) { + $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; + } +} -- 2.20.1