Added unique import hash
authorMarcel Werk <burntime@woltlab.com>
Mon, 12 Aug 2013 20:32:32 +0000 (22:32 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 12 Aug 2013 20:32:32 +0000 (22:32 +0200)
wcfsetup/install/files/lib/system/importer/ImportHandler.class.php
wcfsetup/install/files/lib/system/worker/ImportWorker.class.php
wcfsetup/setup/db/install.sql

index b46d02fcf96c3ac94c6c43377e99454619949e7c..51930f449789735f803b52b80eab88e8bb29959d 100644 (file)
@@ -43,6 +43,12 @@ class ImportHandler extends SingletonFactory implements IAJAXInvokeAction {
         */
        protected $userMergeMode = 2;
        
+       /**
+        * import hash
+        * @var string
+        */
+       protected $importHash = '';
+       
        /**
         * list of methods allowed for remote invoke
         * @var array<string>
@@ -90,10 +96,11 @@ class ImportHandler extends SingletonFactory implements IAJAXInvokeAction {
                        
                        $sql = "SELECT  newID
                                FROM    wcf".WCF_N."_import_mapping
-                               WHERE   objectTypeID = ?
+                               WHERE   importHash = ?
+                                       AND objectTypeID = ?
                                        AND oldID = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array($objectTypeID, $oldID));
+                       $statement->execute(array($this->importHash, $objectTypeID, $oldID));
                        $row = $statement->fetchArray();
                        if ($row !== false) $this->idMappingCache[$objectTypeID][$oldID] = $row['newID'];
                }
@@ -112,10 +119,10 @@ class ImportHandler extends SingletonFactory implements IAJAXInvokeAction {
                $objectTypeID = $this->objectTypes[$type]->objectTypeID;
                
                $sql = "INSERT IGNORE INTO      wcf".WCF_N."_import_mapping
-                                               (objectTypeID, oldID, newID)
-                       VALUES                  (?, ?, ?)";
+                                               (importHash, objectTypeID, oldID, newID)
+                       VALUES                  (?, ?, ?, ?)";
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($objectTypeID, $oldID, $newID));
+               $statement->execute(array($this->importHash, $objectTypeID, $oldID, $newID));
                
                unset($this->idMappingCache[$objectTypeID][$oldID]);
        }
@@ -159,4 +166,13 @@ class ImportHandler extends SingletonFactory implements IAJAXInvokeAction {
        public function getUserMergeMode() {
                return $this->userMergeMode;
        }
+       
+       /**
+        * Sets the import hash.
+        *
+        * @param       string          $hash
+        */
+       public function setImportHash($hash) {
+               $this->importHash = $hash;
+       }
 }
index 6ce635ec15f8ec1c8754ccd2816ca6cd5e2ac2c0..9e4fba8866d233c103160c4a5b1eaa3603782f1e 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\exception\SystemException;
 use wcf\system\importer\ImportHandler;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Worker implementation for data import.
@@ -53,6 +54,9 @@ class ImportWorker extends AbstractWorker {
 
                // set user merge mode
                ImportHandler::getInstance()->setUserMergeMode($this->importData['userMergeMode']);
+               
+               // set import hash
+               ImportHandler::getInstance()->setImportHash(substr(StringUtil::getHash($this->importData['exporterName'] . $this->importData['dbHost'] . $this->importData['dbName'] . $this->importData['dbPrefix']), 0, 8));
        }
 
        /**
index b05613c40cf1bee05c795a648db3c6711810df5b..a9e433aae41ab310cdd792ce1ad07b472676d350 100644 (file)
@@ -328,10 +328,11 @@ CREATE TABLE wcf1_event_listener (
 
 DROP TABLE IF EXISTS wcf1_import_mapping;
 CREATE TABLE wcf1_import_mapping (
+       importHash CHAR(8) NOT NULL,
        objectTypeID INT(10) NOT NULL,
        oldID VARCHAR(255) NOT NULL,
        newID INT(10) NOT NULL,
-       UNIQUE KEY (objectTypeID, oldID)
+       UNIQUE KEY (importHash, objectTypeID, oldID)
 );
 
 DROP TABLE IF EXISTS wcf1_label;