Added a worker for utf8 -> utf8mb4 conversion
authorAlexander Ebert <ebert@woltlab.com>
Sat, 19 Nov 2016 19:23:08 +0000 (20:23 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 19 Nov 2016 19:23:15 +0000 (20:23 +0100)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/worker/DatabaseConvertEncodingWorker.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 20bf321505c87feb383eea78628d5f69bdfe7c43..dc6d9dc70ccb3e31c6f4494dbc5ef17a7dd7a599 100644 (file)
                <!-- /importers -->
                
                <!-- rebuild data workers -->
+               <type>
+                       <name>com.woltlab.wcf.databaseConvertEncoding</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname>wcf\system\worker\DatabaseConvertEncodingWorker</classname>
+                       <nicevalue>-200</nicevalue>
+               </type>
                <type>
                        <name>com.woltlab.wcf.like</name>
                        <definitionname>com.woltlab.wcf.rebuildData</definitionname>
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 (file)
index 0000000..d293bd3
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+namespace wcf\system\worker;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for database table encoding conversion.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+       }
+}
index fef48408e66e91562465ba270cb317e777abe42e..fc1507e5623a6ed516c0320c9d92ad9a7bf7414b 100644 (file)
@@ -1478,6 +1478,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll.description"><![CDATA[Aktualisiert Zähler der Umfragen]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article"><![CDATA[Artikel aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article.description"><![CDATA[Aktualisiert den Suchindex für Artikel]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding"><![CDATA[Datenbank-Kodierung konvertieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding.description"><![CDATA[Warnung: Die Ausführung dieser Aktion kann bei umfangreichen Datenbanken sehr lange dauern.]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">
index c2f15613a995c6dd0507dc603d157be6cf4bae87..1f2879f5b6c9643d2be74068b5f7aa56a60db07d 100644 (file)
@@ -1442,6 +1442,8 @@ Examples for medium ID detection:
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll.description"><![CDATA[Rebuilds the poll counters.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article"><![CDATA[Rebuild Articles]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article.description"><![CDATA[Rebuilds the article search index.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding"><![CDATA[Convert Database Encoding]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding.description"><![CDATA[Warning: This action may take a while to complete on large databases.]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">