From 6c1b515cfe1e3cb65b110c3370b0f9f48970351d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 19 Nov 2016 20:23:08 +0100 Subject: [PATCH] Added a worker for utf8 -> utf8mb4 conversion --- com.woltlab.wcf/objectType.xml | 6 ++ .../DatabaseConvertEncodingWorker.class.php | 80 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 2 + wcfsetup/install/lang/en.xml | 2 + 4 files changed, 90 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/worker/DatabaseConvertEncodingWorker.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 20bf321505..dc6d9dc70c 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -332,6 +332,12 @@ + + com.woltlab.wcf.databaseConvertEncoding + com.woltlab.wcf.rebuildData + wcf\system\worker\DatabaseConvertEncodingWorker + -200 + com.woltlab.wcf.like com.woltlab.wcf.rebuildData diff --git a/wcfsetup/install/files/lib/system/worker/DatabaseConvertEncodingWorker.class.php b/wcfsetup/install/files/lib/system/worker/DatabaseConvertEncodingWorker.class.php new file mode 100644 index 0000000000..d293bd38e2 --- /dev/null +++ b/wcfsetup/install/files/lib/system/worker/DatabaseConvertEncodingWorker.class.php @@ -0,0 +1,80 @@ + + * @package WoltLabSuite\Core\System\Worker + */ +class DatabaseConvertEncodingWorker extends AbstractWorker { + /** + * @inheritDoc + */ + protected $limit = 1; + + /** + * @inheritDoc + */ + public function countObjects() { + if ($this->count === null) { + $this->count = count($this->getTables()); + } + } + + /** + * @inheritDoc + */ + public function getProceedURL() { + return LinkHandler::getInstance()->getLink('RebuildData'); + } + + /** + * @inheritDoc + */ + public function validate() { + WCF::getSession()->checkPermissions(['admin.management.canRebuildData']); + } + + /** + * @inheritDoc + */ + public function execute() { + $tables = $this->getTables(); + + $statement = WCF::getDB()->prepareStatement("SET FOREIGN_KEY_CHECKS=0"); + $statement->execute(); + + $convertTables = array_slice($tables, $this->limit * $this->loopCount, $this->limit); + foreach ($convertTables as $table) { + $sql = "ALTER TABLE " . $table . " CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + } + + $statement = WCF::getDB()->prepareStatement("SET FOREIGN_KEY_CHECKS=1"); + $statement->execute(); + } + + /** + * Returns the list of known database tables. + * + * @return string[] + */ + protected function getTables() { + $sql = "SELECT DISTINCT sqlTable + FROM wcf".WCF_N."_package_installation_sql_log"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + $tables = []; + while ($table = $statement->fetchColumn()) { + $tables[] = $table; + } + + return $tables; + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index fef48408e6..fc1507e562 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1478,6 +1478,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index c2f15613a9..1f2879f5b6 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1442,6 +1442,8 @@ Examples for medium ID detection: + + -- 2.20.1