fix server
This commit is contained in:
@@ -16,6 +16,49 @@ if (!defined('GLPI_ROOT')) {
|
||||
|
||||
require_once __DIR__ . '/install.php';
|
||||
|
||||
/**
|
||||
* Remove the UrBackup capacity reference from Asset Definitions.
|
||||
*
|
||||
* When the plugin is uninstalled, the `UrBackupCapacity` class no longer exists,
|
||||
* but its reference may remain stored in the `capacities` JSON column of
|
||||
* `glpi_assetdefinitions`. GLPI core safely ignores such orphaned capacities,
|
||||
* but we clean them up so the database does not keep stale references.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_uninstall_cleanup_capacities(Migration $migration, \DBmysql $db): void
|
||||
{
|
||||
$capacity_class = \GlpiPlugin\Urbackup\Capacity\UrBackupCapacity::class;
|
||||
$table = 'glpi_assetdefinitions';
|
||||
|
||||
if (!$db->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($db->request(['FROM' => $table, 'WHERE' => ['capacities' => ['<>' => '[]']]]) as $row) {
|
||||
$decoded = json_decode((string) $row['capacities'], true);
|
||||
if (!is_array($decoded)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filtered = array_values(array_filter($decoded, static function ($spec) use ($capacity_class): bool {
|
||||
return is_array($spec) && (string) ($spec['name'] ?? '') !== $capacity_class;
|
||||
}));
|
||||
|
||||
if (count($filtered) === count($decoded)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$db->update($table, [
|
||||
'capacities' => json_encode($filtered),
|
||||
], ['id' => (int) $row['id']]);
|
||||
}
|
||||
|
||||
$migration->displayMessage(__('UrBackup capacity removed from asset definitions', 'urbackup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall plugin.
|
||||
*
|
||||
@@ -29,6 +72,9 @@ function plugin_urbackup_uninstall_process(): bool
|
||||
|
||||
Profile::uninstallRights();
|
||||
|
||||
global $DB;
|
||||
plugin_urbackup_uninstall_cleanup_capacities($migration, $DB);
|
||||
|
||||
plugin_urbackup_migration_drop_table($migration, 'glpi_plugin_urbackup_profiles');
|
||||
plugin_urbackup_migration_drop_table($migration, 'glpi_plugin_urbackup_serverassets');
|
||||
plugin_urbackup_migration_drop_table($migration, 'glpi_plugin_urbackup_servers');
|
||||
|
||||
Reference in New Issue
Block a user