Geeklog-Core / geeklog

Geeklog - The Secure CMS.
https://www.geeklog.net
25 stars 19 forks source link

Spam-X plugin upgrade may fail #1151

Open dhaun opened 1 year ago

dhaun commented 1 year ago

When upgrading from an older version of Geeklog and the Spam-X plugin, there are 2 potential places in plugins/spamx/sql/mysql_updates.php where the upgrade may fail.

    '1.3.1' => array(
        "ALTER TABLE {$_TABLES['spamx']} ADD PRIMARY KEY (name, value)"
    ),

It's possible that you have multiple entries for value, in which case adding the PRIMARY KEY will fail.

My SQL is a little rusty but it should be possible to check for and silently delete duplicate entries before adding the PRIMARY KEY. Having duplicate entries makes no sense anyway, so this should be fine.

    '1.3.2' => array(
        "ALTER TABLE {$_TABLES['spamx']} MODIFY COLUMN regdate DATETIME DEFAULT NULL",
        "ALTER TABLE {$_TABLES['spamx']} DROP PRIMARY  KEY",
        "DROP INDEX `spamx_name` ON {$_TABLES['spamx']}",
        "ALTER TABLE {$_TABLES['spamx']} ADD PRIMARY KEY (name)"
    ),

Adding just name as a PRIMARY KEY will almost certainly fail if you have any entries at all, since that column was never meant to be unique.

If possible, I'd check which - if any - PRIMARY KEY exists and only remove it in case it's PRIMARY KEY (name) and leave it alone if it's already PRIMARY KEY (name, value).