Add update script to normalize package installation file logs
authorMatthias Schmidt <gravatronics@live.com>
Mon, 7 Jun 2021 08:16:44 +0000 (10:16 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 7 Jun 2021 11:16:25 +0000 (13:16 +0200)
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_normalizeFileLog.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_normalizeFileLog.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_normalizeFileLog.php
new file mode 100644 (file)
index 0000000..746d36a
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Normalizes the filenames in the package installation file log during the update from 5.4 to 5.5.
+ *
+ * @author Matthias Schmidt
+ * @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;
+use wcf\util\FileUtil;
+
+$sql = "SELECT  *
+        FROM    wcf1_package_installation_file_log
+        WHERE   filename LIKE ?";
+$statement = WCF::getDB()->prepare($sql);
+$statement->execute(['./%']);
+
+$sql = "DELETE FROM wcf1_package_installation_file_log
+        WHERE       packageID = ?
+                AND filename = ?
+                AND application = ?";
+$deleteStatement = WCF::getDB()->prepare($sql);
+
+$sql = "INSERT IGNORE INTO  wcf1_package_installation_file_log
+                            (packageID, filename, application)
+        VALUES              (?, ?, ?)";
+$insertStatement = WCF::getDB()->prepare($sql);
+
+while ($row = $statement->fetchArray()) {
+    $deleteStatement->execute([
+        $row['packageID'],
+        $row['filename'],
+        $row['application'],
+    ]);
+    $insertStatement->execute([
+        $row['packageID'],
+        FileUtil::getRealPath($row['filename']),
+        $row['application'],
+    ]);
+}