Add missing SQL log entry for `wcf1_acp_session_virtual` during upgrade to 5.4
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 15 Jul 2021 09:57:39 +0000 (11:57 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 15 Jul 2021 10:00:52 +0000 (12:00 +0200)
This entry is required to be able to delete this table later in the process.

com.woltlab.wcf/files_pre_check.tar
com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_fixSqlLog.php [new file with mode: 0644]

index d2cc313a698675afda633b966370c7f21684cc44..16c365c731dd9babe3a4353d1f4c90670fbee06c 100644 (file)
Binary files a/com.woltlab.wcf/files_pre_check.tar and b/com.woltlab.wcf/files_pre_check.tar differ
index c89ce9d0a1b51f61796dc8bb880535d179b64b27..ad5c4b8ef0b2b67abc06e88454231b0f3b223cdc 100644 (file)
                <!--
 tar cvf com.woltlab.wcf/files_pre_check.tar -C wcfsetup/install/files/ \
        acp/update_com.woltlab.wcf_5.4_checkSystemRequirements.php \
-       acp/update_com.woltlab.wcf_5.4_checkOwnerGroup.php
+       acp/update_com.woltlab.wcf_5.4_checkOwnerGroup.php \
+       acp/update_com.woltlab.wcf_5.4_fixSqlLog.php
                -->
                <instruction type="file" run="standalone">files_pre_check.tar</instruction>
                
                <!-- Checks that need to happen before the upgrade starts. -->
                <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4_checkSystemRequirements.php</instruction>
                <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4_checkOwnerGroup.php</instruction>
+               <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4_fixSqlLog.php</instruction>
 
                <!--
 tar cvf com.woltlab.wcf/files_pre.tar -C wcfsetup/install/files/ \
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_fixSqlLog.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_fixSqlLog.php
new file mode 100644 (file)
index 0000000..b2b3d33
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Adds the missing SQL log entry for wcf1_acp_session_virtual. It might be missing
+ * in communities that were upgraded from 2.1 to 3.0.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core
+ */
+
+use wcf\system\WCF;
+
+$packageID = 1;
+$sqlTable = "wcf" . WCF_N . "_acp_session_virtual";
+$sqlColumn = '';
+$sqlIndex = '';
+
+$sql = "SELECT  isDone
+        FROM    wcf" . WCF_N . "_package_installation_sql_log
+        WHERE   packageID = ?
+            AND sqlTable = ?
+            AND sqlColumn = ?
+            AND sqlIndex = ?";
+$statement = WCF::getDB()->prepareStatement($sql);
+$statement->execute([
+    $packageID,
+    $sqlTable,
+    $sqlColumn,
+    $sqlIndex,
+]);
+
+$isDone = $statement->fetchSingleColumn();
+
+if ($isDone === false) {
+    // Create the record of no row can be found.
+    $sql = "INSERT INTO wcf" . WCF_N . "_package_installation_sql_log
+                (packageID, sqlTable, sqlColumn, sqlIndex, isDone)
+            VALUES
+                (?, ?, ?, ?, ?)";
+    $statement = WCF::getDB()->prepareStatement($sql);
+    $statement->execute([
+        $packageID,
+        $sqlTable,
+        $sqlColumn,
+        $sqlIndex,
+        1,
+    ]);
+} else {
+    if ($isDone) {
+        // The record exists with isDone = 1. We don't need to do anything.
+    } else {
+        // Mark the record as done, because the table must exist for the ACP to work.
+        $sql = "UPDATE  wcf" . WCF_N . "_package_installation_sql_log
+                SET     isDone = ?
+                WHERE   packageID = ?
+                    AND sqlTable = ?
+                    AND sqlColumn = ?
+                    AND sqlIndex = ?";
+        $statement = WCF::getDB()->prepareStatement($sql);
+        $statement->execute([
+            1,
+            $packageID,
+            $sqlTable,
+            $sqlColumn,
+            $sqlIndex,
+        ]);
+    }
+}