diff --git a/MEMORY.md b/MEMORY.md index c073388..2aa2aad 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -61,6 +61,23 @@ In una nuova installazione del plugin, i campi "API username" e "API password" n 1. **`Server.php::showFormFields()`** — Sostituito `$canUpdate` con `$canEdit`: per nuovi server (`$ID <= 0`) usa `CREATE`, per server esistenti usa `UPDATE`. 2. **`Profile.php::installRights()`** — In assenza di sessione attiva (CLI), cerca il profilo "Super-Admin" tramite query diretta e gli assegna tutti i diritti. +## Bugfix: Unknown column 'users_id' — Group::getDataItems() SQL error + +### Problema +Su server produttivo, `Group::showItems()` generava un errore MySQL 1054 (Unknown column 'users_id') quando GLPI iterava sugli itemtype registrati con `linkgroup_types => true`. La query includeva: +```sql +WHERE ((... ) OR (`users_id` IN (SELECT `users_id` FROM `glpi_groups_users` WHERE `groups_id` IN ('7483')))) +``` +La colonna `users_id` non esisteva nella tabella `glpi_plugin_urbackup_servers`. + +### Causa +`Server` è registrato in `setup.php:57` con `linkgroup_types => true`, il che fa sì che GLPI lo includa nelle query di `Group::getDataItems()`. Il metodo aggiunge automaticamente una condizione `users_id IN (...)` assumendo che ogni itemtype abbia tale colonna. + +### Fix +1. **`install/mysql/plugin_urbackup-empty.sql`** — Aggiunta colonna `users_id INT UNSIGNED NOT NULL DEFAULT 0` dopo `locations_id` + indice +2. **`install/install.php`** — Aggiunto `$migration->addField('users_id', ...)` e `$migration->addKey('users_id')` nella migrazione del server +3. **`src/Server.php`** — Aggiunto search option `id=8` per `User::getTable()` + auto-set di `users_id` da `$_SESSION['glpiID']` in `prepareInputForAdd()` + ## Versione - 0.7.0 diff --git a/install/install.php b/install/install.php index 1f3d7c3..9a29004 100644 --- a/install/install.php +++ b/install/install.php @@ -202,6 +202,11 @@ function plugin_urbackup_install_update_servers_table(Migration $migration): voi 'after' => 'name', ]); + $migration->addField($table, 'users_id', 'integer', [ + 'value' => 0, + 'after' => 'locations_id', + ]); + $migration->addField($table, 'ip_address', 'string', [ 'value' => '', 'after' => 'locations_id', @@ -262,6 +267,7 @@ function plugin_urbackup_install_update_servers_table(Migration $migration): voi $migration->addKey($table, 'name'); $migration->addKey($table, 'entities_id'); $migration->addKey($table, 'locations_id'); + $migration->addKey($table, 'users_id'); $migration->addKey($table, 'is_active'); $migration->addKey($table, ['locations_id', 'is_active'], 'location_active'); } diff --git a/install/mysql/plugin_urbackup-empty.sql b/install/mysql/plugin_urbackup-empty.sql index ff173f3..2889e46 100644 --- a/install/mysql/plugin_urbackup-empty.sql +++ b/install/mysql/plugin_urbackup-empty.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_servers` ( `is_recursive` TINYINT NOT NULL DEFAULT 0, `name` VARCHAR(255) NOT NULL DEFAULT '', `locations_id` INT UNSIGNED NOT NULL DEFAULT 0, + `users_id` INT UNSIGNED NOT NULL DEFAULT 0, `ip_address` VARCHAR(255) NOT NULL DEFAULT '', `port` INT UNSIGNED NOT NULL DEFAULT 55414, `protocol` VARCHAR(10) NOT NULL DEFAULT 'http', @@ -32,6 +33,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_servers` ( KEY `name` (`name`), KEY `entities_id` (`entities_id`), KEY `locations_id` (`locations_id`), + KEY `users_id` (`users_id`), KEY `is_active` (`is_active`), KEY `location_active` (`locations_id`, `is_active`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; diff --git a/src/Server.php b/src/Server.php index ebd3375..3daaa72 100644 --- a/src/Server.php +++ b/src/Server.php @@ -259,6 +259,14 @@ class Server extends CommonDBTM $tab[] = [ 'id' => 8, + 'table' => User::getTable(), + 'field' => 'name', + 'name' => User::getTypeName(1), + 'datatype' => 'dropdown', + ]; + + $tab[] = [ + 'id' => 9, 'table' => self::getTable(), 'field' => 'is_active', 'name' => __('Active'), @@ -266,7 +274,7 @@ class Server extends CommonDBTM ]; $tab[] = [ - 'id' => 9, + 'id' => 10, 'table' => self::getTable(), 'field' => 'last_api_status', 'name' => __('Last API status', 'urbackup'), @@ -274,7 +282,7 @@ class Server extends CommonDBTM ]; $tab[] = [ - 'id' => 10, + 'id' => 11, 'table' => self::getTable(), 'field' => 'last_api_check', 'name' => __('Last API check', 'urbackup'), @@ -282,7 +290,7 @@ class Server extends CommonDBTM ]; $tab[] = [ - 'id' => 11, + 'id' => 12, 'table' => self::getTable(), 'field' => 'date_creation', 'name' => __('Creation date'), @@ -290,7 +298,7 @@ class Server extends CommonDBTM ]; $tab[] = [ - 'id' => 12, + 'id' => 13, 'table' => self::getTable(), 'field' => 'date_mod', 'name' => __('Last update'), @@ -299,7 +307,7 @@ class Server extends CommonDBTM if (Session::haveRight(self::$rightname, UPDATE)) { $tab[] = [ - 'id' => 13, + 'id' => 14, 'table' => self::getTable(), 'field' => 'id', 'name' => __('View', 'urbackup'), @@ -571,6 +579,10 @@ class Server extends CommonDBTM return $input; } + if (!isset($input['users_id']) || $input['users_id'] <= 0) { + $input['users_id'] = (int) ($_SESSION['glpiID'] ?? 0); + } + if (!isset($input['port']) || $input['port'] === '' || $input['port'] === null) { $input['port'] = 55414; }