Add update_com.woltlab.wcf_5.5_ensureInnoDbSearch.php
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 09:32:50 +0000 (11:32 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 09:32:50 +0000 (11:32 +0200)
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_ensureInnoDbSearch.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_ensureInnoDbSearch.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_ensureInnoDbSearch.php
new file mode 100644 (file)
index 0000000..438253c
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\search\SearchIndexManager;
+use wcf\system\WCF;
+
+$objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.searchableObjectType');
+$tableNames = [];
+foreach ($objectTypes as $objectType) {
+    $tableNames[] = SearchIndexManager::getTableName($objectType->objectType);
+}
+$conditionBuilder = new PreparedStatementConditionBuilder(true);
+$conditionBuilder->add('TABLE_NAME IN (?)', [$tableNames]);
+$conditionBuilder->add('TABLE_SCHEMA = ?', [WCF::getDB()->getDatabaseName()]);
+$conditionBuilder->add('ENGINE <> ?', ['InnoDB']);
+
+$sql = "SELECT  COUNT(*)
+        FROM    INFORMATION_SCHEMA.TABLES
+        " . $conditionBuilder;
+$statement = WCF::getDB()->prepareStatement($sql);
+$statement->execute($conditionBuilder->getParameters());
+$nonInnoDbSearch = $statement->fetchSingleColumn() > 0;
+
+if ($nonInnoDbSearch) {
+    if (WCF::getLanguage()->getFixedLanguageCode() === 'de') {
+        $message = "Es wurden noch nicht alle Tabellen auf InnoDB migriert.";
+    } else {
+        $message = "The migration to InnoDB was not yet performed for all database tables.";
+    }
+
+    throw new \RuntimeException($message);
+}