fix x gruppi
This commit is contained in:
@@ -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`.
|
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.
|
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
|
## Versione
|
||||||
- 0.7.0
|
- 0.7.0
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,11 @@ function plugin_urbackup_install_update_servers_table(Migration $migration): voi
|
|||||||
'after' => 'name',
|
'after' => 'name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$migration->addField($table, 'users_id', 'integer', [
|
||||||
|
'value' => 0,
|
||||||
|
'after' => 'locations_id',
|
||||||
|
]);
|
||||||
|
|
||||||
$migration->addField($table, 'ip_address', 'string', [
|
$migration->addField($table, 'ip_address', 'string', [
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'after' => 'locations_id',
|
'after' => 'locations_id',
|
||||||
@@ -262,6 +267,7 @@ function plugin_urbackup_install_update_servers_table(Migration $migration): voi
|
|||||||
$migration->addKey($table, 'name');
|
$migration->addKey($table, 'name');
|
||||||
$migration->addKey($table, 'entities_id');
|
$migration->addKey($table, 'entities_id');
|
||||||
$migration->addKey($table, 'locations_id');
|
$migration->addKey($table, 'locations_id');
|
||||||
|
$migration->addKey($table, 'users_id');
|
||||||
$migration->addKey($table, 'is_active');
|
$migration->addKey($table, 'is_active');
|
||||||
$migration->addKey($table, ['locations_id', 'is_active'], 'location_active');
|
$migration->addKey($table, ['locations_id', 'is_active'], 'location_active');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_servers` (
|
|||||||
`is_recursive` TINYINT NOT NULL DEFAULT 0,
|
`is_recursive` TINYINT NOT NULL DEFAULT 0,
|
||||||
`name` VARCHAR(255) NOT NULL DEFAULT '',
|
`name` VARCHAR(255) NOT NULL DEFAULT '',
|
||||||
`locations_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
`locations_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||||
|
`users_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||||
`ip_address` VARCHAR(255) NOT NULL DEFAULT '',
|
`ip_address` VARCHAR(255) NOT NULL DEFAULT '',
|
||||||
`port` INT UNSIGNED NOT NULL DEFAULT 55414,
|
`port` INT UNSIGNED NOT NULL DEFAULT 55414,
|
||||||
`protocol` VARCHAR(10) NOT NULL DEFAULT 'http',
|
`protocol` VARCHAR(10) NOT NULL DEFAULT 'http',
|
||||||
@@ -32,6 +33,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_servers` (
|
|||||||
KEY `name` (`name`),
|
KEY `name` (`name`),
|
||||||
KEY `entities_id` (`entities_id`),
|
KEY `entities_id` (`entities_id`),
|
||||||
KEY `locations_id` (`locations_id`),
|
KEY `locations_id` (`locations_id`),
|
||||||
|
KEY `users_id` (`users_id`),
|
||||||
KEY `is_active` (`is_active`),
|
KEY `is_active` (`is_active`),
|
||||||
KEY `location_active` (`locations_id`, `is_active`)
|
KEY `location_active` (`locations_id`, `is_active`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||||
|
|||||||
+17
-5
@@ -259,6 +259,14 @@ class Server extends CommonDBTM
|
|||||||
|
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 8,
|
'id' => 8,
|
||||||
|
'table' => User::getTable(),
|
||||||
|
'field' => 'name',
|
||||||
|
'name' => User::getTypeName(1),
|
||||||
|
'datatype' => 'dropdown',
|
||||||
|
];
|
||||||
|
|
||||||
|
$tab[] = [
|
||||||
|
'id' => 9,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'is_active',
|
'field' => 'is_active',
|
||||||
'name' => __('Active'),
|
'name' => __('Active'),
|
||||||
@@ -266,7 +274,7 @@ class Server extends CommonDBTM
|
|||||||
];
|
];
|
||||||
|
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 9,
|
'id' => 10,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'last_api_status',
|
'field' => 'last_api_status',
|
||||||
'name' => __('Last API status', 'urbackup'),
|
'name' => __('Last API status', 'urbackup'),
|
||||||
@@ -274,7 +282,7 @@ class Server extends CommonDBTM
|
|||||||
];
|
];
|
||||||
|
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 10,
|
'id' => 11,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'last_api_check',
|
'field' => 'last_api_check',
|
||||||
'name' => __('Last API check', 'urbackup'),
|
'name' => __('Last API check', 'urbackup'),
|
||||||
@@ -282,7 +290,7 @@ class Server extends CommonDBTM
|
|||||||
];
|
];
|
||||||
|
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 11,
|
'id' => 12,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'date_creation',
|
'field' => 'date_creation',
|
||||||
'name' => __('Creation date'),
|
'name' => __('Creation date'),
|
||||||
@@ -290,7 +298,7 @@ class Server extends CommonDBTM
|
|||||||
];
|
];
|
||||||
|
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 12,
|
'id' => 13,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'date_mod',
|
'field' => 'date_mod',
|
||||||
'name' => __('Last update'),
|
'name' => __('Last update'),
|
||||||
@@ -299,7 +307,7 @@ class Server extends CommonDBTM
|
|||||||
|
|
||||||
if (Session::haveRight(self::$rightname, UPDATE)) {
|
if (Session::haveRight(self::$rightname, UPDATE)) {
|
||||||
$tab[] = [
|
$tab[] = [
|
||||||
'id' => 13,
|
'id' => 14,
|
||||||
'table' => self::getTable(),
|
'table' => self::getTable(),
|
||||||
'field' => 'id',
|
'field' => 'id',
|
||||||
'name' => __('View', 'urbackup'),
|
'name' => __('View', 'urbackup'),
|
||||||
@@ -571,6 +579,10 @@ class Server extends CommonDBTM
|
|||||||
return $input;
|
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) {
|
if (!isset($input['port']) || $input['port'] === '' || $input['port'] === null) {
|
||||||
$input['port'] = 55414;
|
$input['port'] = 55414;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user