Add a workaround for the migration of the spider data
authorAlexander Ebert <ebert@woltlab.com>
Sat, 22 Jun 2024 12:07:51 +0000 (14:07 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 22 Jun 2024 12:07:51 +0000 (14:07 +0200)
Fixes #5941

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php [deleted file]
wcfsetup/install/files/acp/update_com.woltlab.wcf_6.1_spider_step1.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php
deleted file mode 100644 (file)
index b807f63..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-
-/**
- * Drops old spider related columns and index from `wcf1_session` table.
- *
- * @author      Olaf Braun
- * @copyright   2001-2024 WoltLab GmbH
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @since       6.1
- */
-
-use wcf\system\database\table\column\IntDatabaseTableColumn;
-use wcf\system\database\table\index\DatabaseTableForeignKey;
-use wcf\system\database\table\index\DatabaseTableIndex;
-use wcf\system\database\table\PartialDatabaseTable;
-
-return [
-    PartialDatabaseTable::create('wcf1_session')
-        ->columns([
-            IntDatabaseTableColumn::create('spiderID')
-                ->length(10)
-                ->drop(),
-        ])
-        ->indices([
-            DatabaseTableIndex::create('packageID')
-                ->columns(['lastActivityTime', 'spiderID'])
-                ->drop(),
-        ])
-        ->foreignKeys([
-            DatabaseTableForeignKey::create()
-                ->columns(['spiderID'])
-                ->referencedTable('wcf1_spider')
-                ->referencedColumns(['spiderID'])
-                ->onDelete('CASCADE')
-                ->drop(),
-        ]),
-];
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.1_spider_step1.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.1_spider_step1.php
new file mode 100644 (file)
index 0000000..cf91642
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Drops old spider related columns and index from `wcf1_session` table.
+ *
+ * @author      Olaf Braun
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since       6.1
+ */
+
+use wcf\system\database\table\column\IntDatabaseTableColumn;
+use wcf\system\database\table\DatabaseTableChangeProcessor;
+use wcf\system\database\table\index\DatabaseTableForeignKey;
+use wcf\system\database\table\index\DatabaseTableIndex;
+use wcf\system\database\table\PartialDatabaseTable;
+use wcf\system\WCF;
+
+$tableNames = WCF::getDB()->getEditor()->getTableNames();
+if (!\in_array('wcf' . WCF_N . '_spider', $tableNames)) {
+    // The table `wcf1_spider` will be removed by a database PIP that is
+    // executed after this script.
+    return;
+}
+
+$tables = [
+    PartialDatabaseTable::create('wcf1_session')
+        ->columns([
+            IntDatabaseTableColumn::create('spiderID')
+                ->length(10)
+                ->drop(),
+        ])
+        ->indices([
+            DatabaseTableIndex::create('packageID')
+                ->columns(['lastActivityTime', 'spiderID'])
+                ->drop(),
+        ])
+        ->foreignKeys([
+            // This foreign key definition fails to validate when the table
+            // `wcf1_spider` no longer exists, despite it being scheduled for
+            // removal.
+            DatabaseTableForeignKey::create()
+                ->columns(['spiderID'])
+                ->referencedTable('wcf1_spider')
+                ->referencedColumns(['spiderID'])
+                ->onDelete('CASCADE')
+                ->drop(),
+        ]),
+];
+
+(new DatabaseTableChangeProcessor(
+    /** @var ScriptPackageInstallationPlugin $this */
+    $this->installation->getPackage(),
+    $tables,
+    WCF::getDB()->getEditor()
+)
+)->process();