Added additional import features
authorMarcel Werk <burntime@woltlab.com>
Sat, 6 Jul 2013 17:32:40 +0000 (19:32 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sat, 6 Jul 2013 17:32:40 +0000 (19:32 +0200)
wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php
wcfsetup/install/files/lib/system/importer/AbstractPollImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/AbstractPollOptionImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/AbstractPollOptionVoteImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/AbstractWatchedObjectImporter.class.php [new file with mode: 0644]

index 96b10745d77436eedc276913cec5c93c1b6c9be4..726c2abc8eda06ce8345a7863ed98468b2ae1c64 100644 (file)
@@ -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;
+       }
 }
index e86bcb3ff7bcab4e6b77bd356c522efa417c01de..b0047e470fab6d79a3c8c187262354358bb3519e 100644 (file)
@@ -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 (file)
index 0000000..31cf2fa
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\poll\PollEditor;
+
+/**
+ * Imports polls.
+ *
+ * @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 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 (file)
index 0000000..8f1d869
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\poll\option\PollOptionEditor;
+
+/**
+ * Imports poll votes.
+ *
+ * @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 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 (file)
index 0000000..70254ae
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace wcf\system\importer;
+use wcf\system\WCF;
+
+/**
+ * Imports poll votes.
+ *
+ * @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 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 (file)
index 0000000..1329628
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\user\object\watch\UserObjectWatchAction;
+
+/**
+ * Imports watched objects.
+ *
+ * @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 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;
+       }
+}