From: Alexander Ebert Date: Sat, 19 Nov 2016 19:23:08 +0000 (+0100) Subject: Added a worker for utf8 -> utf8mb4 conversion X-Git-Tag: 3.0.0_Beta_5~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6c1b515cfe1e3cb65b110c3370b0f9f48970351d;p=GitHub%2FWoltLab%2FWCF.git Added a worker for utf8 -> utf8mb4 conversion --- 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: + +