[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] Use filename hash as secdb primary key to avoid long path collisions

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

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


Commits:
e2848295 by ushindi bienvenu at 2026-08-24T22:28:26+00:00
[FIX]  Use filename hash as secdb primary key to avoid long path collisions
---
* [FIX] Use filename hash as secdb primary key to avoid long path collisions
---
* [FIX] Make update-secdb last step

See merge request tikiwiki/tiki!10368

* [FIX] Check if column already exist before update
---
* [FIX] Check if column already exist before update

See merge request tikiwiki/tiki!10817

See merge request tikiwiki/tiki!11050


(cherry picked from commit e8efdac2e5a17f7ed101a425c13893396339bebd)

d7f9a22e [FIX] Check if column already exist before update
f522f084 [FIX] Use filename hash as secdb primary key to avoid long path collisions

Co-authored-by: ushindi bienvenu <[email protected]>
- - - - -


4 changed files:

- db/tiki.sql
- doc/devtools/release.php
- installer/Installer.php
- + installer/schema/20260825_increase_filename_len_in_pk_tiki.php


Changes:

=====================================
db/tiki.sql
=====================================
@@ -2215,10 +2215,11 @@ DROP TABLE IF EXISTS `tiki_secdb`;
 CREATE TABLE tiki_secdb(
   `md5_value` varchar(32) NOT NULL,
   `filename` varchar(250) NOT NULL,
+  `filename_hash` char(32) NOT NULL DEFAULT '',
   `tiki_version` varchar(60) NOT NULL,
   `severity` int(4) NOT NULL default '0',
-  PRIMARY KEY (`filename`(171),`tiki_version`(20)),
-  KEY `sdb_fn` (filename(191))
+  PRIMARY KEY (`filename_hash`, `tiki_version`(20)),
+  KEY `sdb_fn` (`filename`(191))
 ) ENGINE=MyISAM;
 
 DROP TABLE IF EXISTS `tiki_semaphores`;


=====================================
doc/devtools/release.php
=====================================
@@ -304,12 +304,8 @@ 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` DROP PRIMARY KEY, ADD PRIMARY KEY (`filename`(171),`tiki_version`(20));\n\n");
-
-        $insertString = 'INSERT INTO `tiki_secdb` (`filename`, `md5_value`, `tiki_version`) VALUES ';
+        fwrite($fp, "\n");
+        $insertString = 'INSERT INTO `tiki_secdb` (`filename`, `filename_hash`, `md5_value`, `tiki_version`) VALUES ';
 
         $extendedInsertSize = 0;
         $extendedInsertMaxSize = 1 * 1024 * 1024 - 100; // 1MB with 100 bytes safety limit, some old versions of Mysql had max_allowed_packet=1MB
@@ -422,7 +418,8 @@ function build_secdb_queries($dir, $version, &$queries, $excludes = [])
 
                 if (is_readable($entry)) {
                     $hash = md5_file($entry);
-                    $queries[] = "('$file', '$hash', '$version')";
+                    $filenameHash = md5($file);
+                    $queries[] = "('$file', '$filenameHash', '$hash', '$version')";
                 }
             }
         }


=====================================
installer/Installer.php
=====================================
@@ -116,6 +116,18 @@ class Installer extends TikiDb_Bridge implements SplSubject
         $this->assureDefaultCharSetIsAlignedWithTikiSchema();
         $this->assureInnoDdTableRowFormatIsDynamicOrBetter();
 
+        foreach (Patch::getPatches([Patch::NOT_APPLIED]) as $patchName => $patch) {
+            try {
+                $this->installPatch($patchName);
+            } catch (Exception $e) {
+                if ($e->getCode() != 2) {
+                    throw $e;
+                } else {
+                    return false;
+                }
+            }
+        }
+
         $TWV = new TWVersion();
 
         // If a Mysql data file exists, use that. Very fast
@@ -137,17 +149,6 @@ class Installer extends TikiDb_Bridge implements SplSubject
             // Run single inserts
             $this->runFile($secdb, false);
         }
-        foreach (Patch::getPatches([Patch::NOT_APPLIED]) as $patchName => $patch) {
-            try {
-                $this->installPatch($patchName);
-            } catch (Exception $e) {
-                if ($e->getCode() != 2) {
-                    throw $e;
-                } else {
-                    return false;
-                }
-            }
-        }
 
         foreach ($this->scripts as $script) {
             $this->runScript($script);


=====================================
installer/schema/20260825_increase_filename_len_in_pk_tiki.php
=====================================
@@ -0,0 +1,52 @@
+<?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.
+
+use Tiki\Installer\Installer;
+
+/**
+ * Adds the filename_hash column to tiki_secdb and updates the primary key.
+ *
+ * Some instances may already contain this column if the migration was
+ * previously applied, so the schema change is performed only when needed.
+ *
+ * @param Installer $installer
+ *
+ * @return true
+ */
+function upgrade_20260825_increase_filename_len_in_pk_tiki(Installer $installer)
+{
+    global $dbs_tiki;
+
+    $exists = $installer->getOne(
+        "SELECT COUNT(*)
+        FROM INFORMATION_SCHEMA.COLUMNS
+        WHERE COLUMN_NAME = 'filename_hash'
+            AND TABLE_SCHEMA = '" . $dbs_tiki . "'
+            AND TABLE_NAME = 'tiki_secdb'"
+    );
+
+    if (! boolval($exists)) {
+        $installer->query("
+            ALTER TABLE `tiki_secdb`
+                ADD COLUMN `filename_hash` CHAR(32) NOT NULL DEFAULT '' AFTER `filename`
+        ");
+
+        $installer->query("
+            UPDATE `tiki_secdb`
+            SET `filename_hash` = MD5(`filename`)
+            WHERE `filename_hash` = ''
+        ");
+
+        $installer->query("
+            ALTER TABLE `tiki_secdb`
+                DROP PRIMARY KEY,
+                ADD PRIMARY KEY (`filename_hash`, `tiki_version`(20))
+        ");
+    }
+
+    return true;
+}



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

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e2848295b4739c35ba499701995c31b1e63f9265
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.