From 8d8368ee0018c6ce26c6588bb9ca10dff0484a61 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Mon, 12 Aug 2013 22:32:32 +0200 Subject: [PATCH] Added unique import hash --- .../system/importer/ImportHandler.class.php | 26 +++++++++++++++---- .../lib/system/worker/ImportWorker.class.php | 4 +++ wcfsetup/setup/db/install.sql | 3 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php b/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php index b46d02fcf9..51930f4497 100644 --- a/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php +++ b/wcfsetup/install/files/lib/system/importer/ImportHandler.class.php @@ -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 @@ -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; + } } diff --git a/wcfsetup/install/files/lib/system/worker/ImportWorker.class.php b/wcfsetup/install/files/lib/system/worker/ImportWorker.class.php index 6ce635ec15..9e4fba8866 100644 --- a/wcfsetup/install/files/lib/system/worker/ImportWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/ImportWorker.class.php @@ -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)); } /** diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index b05613c40c..a9e433aae4 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -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; -- 2.20.1