Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Automatic generation on delivery no longer creates a consumable model per received consumable
- CI: fix Psalm cache directory, drop the stray `glpi-project/tools` composer dependency, declare a unique composer autoloader suffix
- Plugin upgrade no longer rebuilds tables whose columns already have the expected type, nor replays legacy data migrations, which made it time out on large databases (#616)

## [2.12.11] - 2026-09-18

Expand Down
5 changes: 4 additions & 1 deletion inc/bill.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ public static function install(Migration $migration)
}
}

$migration->changeField($table, "value", "value", "decimal(20,6) NOT NULL DEFAULT '0.000000'");
if (!PluginOrderConfig::fieldHasType($table, "value", 'decimal(20,6)')) {
$migration->changeField($table, "value", "value", "decimal(20,6) NOT NULL DEFAULT '0.000000'");
}

$migration->migrationOneTable($table);
}

Expand Down
29 changes: 28 additions & 1 deletion inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/


use function Safe\preg_replace;

class PluginOrderConfig extends CommonDBTM
{
Expand Down Expand Up @@ -669,6 +669,33 @@ public function canRenameDocuments()


//----------------- Install & uninstall -------------------//

/**
* Tell whether a column already has the expected SQL type, so that an upgrade does
* not replay a type change: every CHANGE rebuilds the whole table.
*
* @param string $table Table name
* @param string $field Column name
* @param string $type Expected type, as reported by SHOW COLUMNS (ie. "decimal(20,6)", "int unsigned")
*
* @return bool true when the column is missing or already has this type
*/
public static function fieldHasType(string $table, string $field, string $type): bool
{
/** @var DBmysql $DB */
global $DB;

$column = $DB->getField($table, $field, false);
if ($column === null) {
return true;
}

// MySQL 5.7 and MariaDB report an integer display width ("int(10) unsigned"), MySQL 8 does not
$current = preg_replace('/^(tinyint|smallint|mediumint|int|bigint)\(\d+\)/', '$1', strtolower((string) $column['Type']));

return $current === strtolower($type);
}

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
Expand Down
5 changes: 4 additions & 1 deletion inc/deliverystate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public static function install(Migration $migration)
//Upgrade 1.2.0
$migration->renameTable("glpi_dropdown_plugin_order_deliverystate", $table);
$migration->changeField($table, "ID", "id", sprintf('int %s NOT NULL auto_increment', $default_key_sign));
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
if (!PluginOrderConfig::fieldHasType($table, "name", 'varchar(255)')) {
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
}

$migration->changeField($table, "comments", "comment", "text");
$migration->migrationOneTable($table);
}
Expand Down
34 changes: 15 additions & 19 deletions inc/order.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2735,12 +2735,10 @@ public static function install(Migration $migration)
"is_recursive",
"tinyint NOT NULL default 0",
);
$migration->changeField(
$table,
"name",
"name",
"varchar(255) default NULL",
);
if (!PluginOrderConfig::fieldHasType($table, "name", 'varchar(255)')) {
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
}

$migration->changeField(
$table,
"budget",
Expand Down Expand Up @@ -2795,12 +2793,10 @@ public static function install(Migration $migration)
"states_id",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
$table,
"comment",
"comment",
"text",
);
if (!PluginOrderConfig::fieldHasType($table, "comment", 'text')) {
$migration->changeField($table, "comment", "comment", "text");
}

$migration->changeField(
$table,
"notes",
Expand Down Expand Up @@ -2863,12 +2859,10 @@ public static function install(Migration $migration)
"end_date",
"date default NULL",
);
$migration->changeField(
"glpi_plugin_order_budgets",
"value",
"value",
"float NOT NULL DEFAULT '0'",
);
if (!PluginOrderConfig::fieldHasType("glpi_plugin_order_budgets", "value", 'float')) {
$migration->changeField("glpi_plugin_order_budgets", "value", "value", "float NOT NULL DEFAULT '0'");
}

$migration->addKey("glpi_plugin_order_budgets", "entities_id");
$migration->addKey("glpi_plugin_order_budgets", "is_deleted");
$migration->migrationOneTable("glpi_plugin_order_budgets");
Expand Down Expand Up @@ -3023,7 +3017,9 @@ public static function install(Migration $migration)
$migration->addField($table, "global_discount", "FLOAT NOT NULL default '0'");

//2.7.3
$migration->changeField($table, "plugin_order_billstates_id", "plugin_order_billstates_id", sprintf('int %s NOT NULL DEFAULT 0', $default_key_sign));
if (!PluginOrderConfig::fieldHasType($table, "plugin_order_billstates_id", trim('int ' . $default_key_sign))) {
$migration->changeField($table, "plugin_order_billstates_id", "plugin_order_billstates_id", sprintf('int %s NOT NULL DEFAULT 0', $default_key_sign));
}

// Add ecotax fields if they don't exist
if (!$DB->fieldExists($table, 'ecotax_price')) {
Expand Down
114 changes: 53 additions & 61 deletions inc/order_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2107,26 +2107,29 @@ public static function install(Migration $migration)
$migration->migrationOneTable($table);

//1.4.0
$migration->addField(
$vat_added = $migration->addField(
$table,
"plugin_order_ordertaxes_id",
sprintf("INT %s NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertaxes (id)'", $default_key_sign),
);
$migration->migrationOneTable($table);

/* Migrate VAT */
foreach ($DB->request(['FROM' => 'glpi_plugin_order_orders']) as $data) {
$migration->addPostQuery(
$DB->buildUpdate(
'glpi_plugin_order_orders_items',
['plugin_order_ordertaxes_id' => $data['plugin_order_ordertaxes_id']],
['plugin_order_orders_id' => $data['id']],
),
);
/* Migrate VAT, only when the column has just been created: one query per order
on every upgrade makes the migration time out on large databases */
if ($vat_added) {
foreach ($DB->request(['FROM' => 'glpi_plugin_order_orders']) as $data) {
$migration->addPostQuery(
$DB->buildUpdate(
'glpi_plugin_order_orders_items',
['plugin_order_ordertaxes_id' => $data['plugin_order_ordertaxes_id']],
['plugin_order_orders_id' => $data['id']],
),
);
}
}

//1.5.0
$migration->addField($table, "entities_id", sprintf("INT %s NOT NULL DEFAULT '0'", $default_key_sign));
$entities_added = $migration->addField($table, "entities_id", sprintf("INT %s NOT NULL DEFAULT '0'", $default_key_sign));
$migration->addField($table, "is_recursive", "TINYINT NOT NULL DEFAULT '0'");
$migration->addField($table, "plugin_order_bills_id", sprintf("INT %s NOT NULL DEFAULT '0'", $default_key_sign));
$migration->addField($table, "plugin_order_billstates_id", sprintf("INT %s NOT NULL DEFAULT '0'", $default_key_sign));
Expand All @@ -2137,62 +2140,51 @@ public static function install(Migration $migration)
$migration->migrationOneTable($table);

//Change format for prices : from float to decimal
$migration->changeField(
$table,
"price_taxfree",
"price_taxfree",
"decimal(20,6) NOT NULL DEFAULT '0.000000'",
);
$migration->changeField(
$table,
"price_discounted",
"price_discounted",
"decimal(20,6) NOT NULL DEFAULT '0.000000'",
);
$migration->changeField(
$table,
"price_ati",
"price_ati",
"decimal(20,6) NOT NULL DEFAULT '0.000000'",
);
$migration->changeField(
$table,
"discount",
"discount",
"decimal(20,6) NOT NULL DEFAULT '0.000000'",
);
foreach (['price_taxfree', 'price_discounted', 'price_ati', 'discount'] as $field) {
if (!PluginOrderConfig::fieldHasType($table, $field, 'decimal(20,6)')) {
$migration->changeField(
$table,
$field,
$field,
"decimal(20,6) NOT NULL DEFAULT '0.000000'",
);
}
}

//Drop unused fields from previous migration
$migration->dropField($table, "price_taxfree2");
$migration->dropField($table, "price_discounted2");
$migration->migrationOneTable($table);

//Forward entities_id and is_recursive into table glpi_plugin_order_orders_items
$query = [
'SELECT' => [
'go.entities_id as entities_id',
'go.is_recursive as is_recursive',
'goi.id as items_id',
],
'FROM' => [
'glpi_plugin_order_orders as go',
$table . ' as goi',
],
'WHERE' => [
'goi.plugin_order_orders_id' => new QueryExpression(DBmysql::quoteName('go.id')),
],
];
foreach ($DB->request($query) as $data) {
$migration->addPostQuery(
$DB->buildUpdate(
$table,
[
'entities_id' => $data['entities_id'],
'is_recursive' => $data['is_recursive'],
],
['id' => $data['items_id']],
),
);
//Forward entities_id and is_recursive into table glpi_plugin_order_orders_items,
//only when the column has just been created (one query per order line otherwise)
if ($entities_added) {
$query = [
'SELECT' => [
'go.entities_id as entities_id',
'go.is_recursive as is_recursive',
'goi.id as items_id',
],
'FROM' => [
'glpi_plugin_order_orders as go',
$table . ' as goi',
],
'WHERE' => [
'goi.plugin_order_orders_id' => new QueryExpression(DBmysql::quoteName('go.id')),
],
];
foreach ($DB->request($query) as $data) {
$migration->addPostQuery(
$DB->buildUpdate(
$table,
[
'entities_id' => $data['entities_id'],
'is_recursive' => $data['is_recursive'],
],
['id' => $data['items_id']],
),
);
}
}

if (!$DB->fieldExists($table, 'plugin_order_analyticnatures_id')) {
Expand Down
5 changes: 4 additions & 1 deletion inc/orderpayment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public static function install(Migration $migration)
//1.2.0
$migration->renameTable("glpi_dropdown_plugin_order_payment", $table);
$migration->changeField($table, "ID", "id", sprintf('int %s NOT NULL auto_increment', $default_key_sign));
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
if (!PluginOrderConfig::fieldHasType($table, "name", 'varchar(255)')) {
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
}

$migration->changeField($table, "comments", "comment", "text");
$migration->migrationOneTable($table);
}
Expand Down
5 changes: 4 additions & 1 deletion inc/ordertax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public static function install(Migration $migration)
//1.2.0
$migration->renameTable("glpi_dropdown_plugin_order_taxes", $table);
$migration->changeField($table, "ID", "id", sprintf('int %s NOT NULL auto_increment', $default_key_sign));
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
if (!PluginOrderConfig::fieldHasType($table, "name", 'varchar(255)')) {
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
}

$migration->changeField($table, "comments", "comment", "text");
$migration->migrationOneTable($table);

Expand Down
10 changes: 4 additions & 6 deletions inc/reference.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,10 @@ public static function install(Migration $migration)
"is_recursive",
"tinyint NOT NULL default '0'",
);
$migration->changeField(
$table,
"name",
"name",
"varchar(255) default NULL",
);
if (!PluginOrderConfig::fieldHasType($table, "name", 'varchar(255)')) {
$migration->changeField($table, "name", "name", "varchar(255) default NULL");
}

$migration->changeField(
$table,
"FK_glpi_enterprise",
Expand Down
Loading
Loading