pluginsGLPI / order

Order plugin for GLPI
GNU General Public License v3.0
39 stars 44 forks source link

fix migration update #375

Closed Rom1-B closed 6 months ago

Rom1-B commented 6 months ago

ref !31826

Fix error message during plugin update (since https://github.com/pluginsGLPI/order/pull/372) :

SQL Error "1062": Duplicate entry '0-PluginOrderOrder-1' for key 'unicity' in query "UPDATE `glpi_displaypreferences` SET `itemtype` = 'PluginOrderOrder' WHERE `itemtype` = '3150'"
In DBmysql.php line 1535:
update itemtype of table glpi_displaypreferences for PluginOrderOrder - Erreur durant l'éxecution de la requête : UPDATE `glpi_displaypreferences` SET `itemtype` = 'PluginOrderOrder' WHERE `itemtype` = '3150' - L'erreur est Duplicate entry '0-PluginOrderOrder-1' for key 'unicity'
stonebuzz commented 6 months ago

@AdrienClairembault

below, there is displayPref migration if $domigration_itemtypes = true


           //Only migrate itemtypes when it's only necessary, otherwise it breaks upgrade procedure !
            if ($domigration_itemtypes) {
                Plugin::migrateItemType(
                    [3150 => 'PluginOrderOrder'],
                    ["glpi_savedsearches", "glpi_savedsearches_users",
                        "glpi_displaypreferences", "glpi_documents_items",
                        "glpi_infocoms", "glpi_logs", "glpi_tickets"
                    ],
                    []
                );
            }

without the check $DB->tableExists('glpi_plugin_order') the migration of displayPref is constantly executed

Rom1-B commented 6 months ago

When the update renames the table, this block is executed (it was never executed before the previous PR mentioned).

image

As there is a uniqueness key on users_id, itemtype and num, it raises the error when trying to replace '3150' with 'PluginOrderOrder', as the key with PluginOrderOrder already exists.