[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [FIX] Add filename_hash to avoid secdb long path PK collisions

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a12796dc8a6a_3819447077095@gitlab-sidekiq-low-urgency-cpu-bound-v2-d7f87744c-fx7vq.mail>

ushindi bienvenu pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
71293d71 by ushindi bienvenu at 2026-05-24T04:00:56+00:00
[FIX] Add filename_hash to avoid secdb long path PK collisions
---
* [FIX] Add filename_hash to avoid secdb long path PK collisions

See merge request tikiwiki/tiki!10361

- - - - -


5 changed files:

- db/tiki-secdb_27.6_mysql.sql
- doc/devtools/release.php
- installer/Installer.php
- + installer/schema/20260524_fix_18lts_upgrade_schema_tiki.php
- − installer/schema/20260524_increase_filename_len_in_pk_tiki.sql


Changes:

=====================================
db/tiki-secdb_27.6_mysql.sql
=====================================
The diff for this file was not included because it is too large.

=====================================
doc/devtools/release.php
=====================================
@@ -301,11 +301,7 @@ function updateSecdb($version)
         sort($queries);
         fwrite($fp, "start transaction;\n");
         fwrite($fp, "DELETE FROM `tiki_secdb`;\n");
-        // This index was originally created with a size limit that would raise an error on some versions,
-        // notably on 18.0. Since this file is executed before any patch in installer/schema, the fix had to
-        // be done here. It's a quick operation because table is empty, so no harm in leaving this here forever.
-        fwrite($fp, "ALTER TABLE `tiki_secdb` ADD COLUMN `filename_hash` CHAR(32) NOT NULL AFTER `filename`;\n");
-        fwrite($fp, "ALTER TABLE `tiki_secdb` DROP PRIMARY KEY, ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20));\n\n");
+        fwrite($fp, "\n");
 
         $insertString = 'INSERT INTO `tiki_secdb` (`filename`, `filename_hash`, `md5_value`, `tiki_version`) VALUES ';
 


=====================================
installer/Installer.php
=====================================
@@ -125,6 +125,7 @@ class Installer extends TikiDb_Bridge implements SplSubject
         $secdb = __DIR__ . '/../' . TIKI_BASE_SQL_SCHEMA_PATH . '/tiki-secdb_' . $dbversion_tiki . '_mysql.sql';
         $secdbData = __DIR__ . '/../' . TIKI_BASE_SQL_SCHEMA_PATH . '/tiki-secdb_' . $dbversion_tiki . '_mysql.data';
         if (file_exists($secdbData)) {
+            $this->assureSecdbTableCanLoadHashedFilenames();
             // A MySQL datafile exists
             $truncateTable = true;
             $rc = $this->runDataFile($secdbData, 'tiki_secdb', $truncateTable);
@@ -132,11 +133,13 @@ class Installer extends TikiDb_Bridge implements SplSubject
                 // The batch loader failed
                 if (file_exists($secdb)) {
                     // Run single inserts
+                    $this->assureSecdbTableCanLoadHashedFilenames();
                     $this->runFile($secdb, false);
                 }
             }
         } elseif (file_exists($secdb)) {
             // Run single inserts
+            $this->assureSecdbTableCanLoadHashedFilenames();
             $this->runFile($secdb, false);
         }
         foreach (Patch::getPatches([Patch::NOT_APPLIED]) as $patchName => $patch) {
@@ -436,6 +439,27 @@ class Installer extends TikiDb_Bridge implements SplSubject
         return in_array($tableName, $list);
     }
 
+    private function assureSecdbTableCanLoadHashedFilenames(): void
+    {
+        if (! $this->tableExists('tiki_secdb')) {
+            return;
+        }
+
+        $this->query('DELETE FROM `tiki_secdb`');
+
+        $filenameHashColumn = $this->query("SHOW COLUMNS FROM `tiki_secdb` LIKE 'filename_hash'", countQueries: false);
+        if (! $filenameHashColumn || empty($filenameHashColumn->result)) {
+            $this->query("ALTER TABLE `tiki_secdb` ADD COLUMN `filename_hash` CHAR(32) NOT NULL AFTER `filename`");
+        }
+
+        $primaryKey = $this->fetchAll("SHOW INDEX FROM `tiki_secdb` WHERE Key_name = 'PRIMARY'") ?: [];
+        if (! empty($primaryKey)) {
+            $this->query('ALTER TABLE `tiki_secdb` DROP PRIMARY KEY');
+        }
+
+        $this->query("ALTER TABLE `tiki_secdb` ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20))");
+    }
+
     public function isInstalled()
     {
         return $this->tableExists('tiki_preferences');


=====================================
installer/schema/20260524_fix_18lts_upgrade_schema_tiki.php
=====================================
@@ -0,0 +1,23 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+function upgrade_20260524_fix_18lts_upgrade_schema_tiki($installer)
+{
+    if ($installer->tableExists('tiki_secdb')) {
+        $installer->query('ALTER TABLE `tiki_secdb` DROP PRIMARY KEY');
+        $installer->query("ALTER TABLE `tiki_secdb` ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20))");
+    }
+
+    if ($installer->tableExists('tiki_payment_requests')) {
+        $dueDateColumn = $installer->query("SHOW COLUMNS FROM `tiki_payment_requests` LIKE 'due_date'", countQueries: false);
+        if ($dueDateColumn && ! empty($dueDateColumn->result)) {
+            $installer->query("ALTER TABLE `tiki_payment_requests` CHANGE `due_date` `due_date` TIMESTAMP NULL DEFAULT NULL");
+        }
+    }
+
+    return true;
+}


=====================================
installer/schema/20260524_increase_filename_len_in_pk_tiki.sql deleted
=====================================
@@ -1,10 +0,0 @@
-ALTER TABLE `tiki_secdb`
-  ADD COLUMN `filename_hash` CHAR(32) NOT NULL DEFAULT '' AFTER `filename`;
-
-UPDATE `tiki_secdb`
-SET `filename_hash` = MD5(`filename`)
-WHERE `filename_hash` = '';
-
-ALTER TABLE `tiki_secdb`
-  DROP PRIMARY KEY,
-  ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20));



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/71293d714598ac275342d24398f57a39e36541ed

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/71293d714598ac275342d24398f57a39e36541ed
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.