Stable
This commit is contained in:
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* UrBackup plugin for GLPI
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Install/update process for GLPI 11.
|
||||
*
|
||||
* GLPI 11 Migration class does not expose createTable()/addTable().
|
||||
* Compatible GLPI plugin pattern:
|
||||
*
|
||||
* - initial schema creation from SQL file using $DB->runFile()
|
||||
* - schema evolution using Migration addField(), addKey(), executeMigration()
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
use GlpiPlugin\Urbackup\Config;
|
||||
use GlpiPlugin\Urbackup\Profile;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die('Sorry. You cannot access this file directly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Install or update plugin database schema and default data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_install_process(): bool
|
||||
{
|
||||
$migration = new Migration(PLUGIN_URBACKUP_VERSION);
|
||||
|
||||
$migration->displayMessage(__('UrBackup plugin installation', 'urbackup'));
|
||||
|
||||
plugin_urbackup_install_create_initial_schema($migration);
|
||||
|
||||
plugin_urbackup_install_update_configs_table($migration);
|
||||
plugin_urbackup_install_update_assettypes_table($migration);
|
||||
plugin_urbackup_install_update_servers_table($migration);
|
||||
plugin_urbackup_install_update_serverassets_table($migration);
|
||||
plugin_urbackup_install_update_profiles_table($migration);
|
||||
|
||||
$migration->executeMigration();
|
||||
|
||||
Config::ensureDefaultConfiguration();
|
||||
Profile::installRights();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create initial database schema from SQL file.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_create_initial_schema(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$required_tables = [
|
||||
'glpi_plugin_urbackup_configs',
|
||||
'glpi_plugin_urbackup_assettypes',
|
||||
'glpi_plugin_urbackup_servers',
|
||||
'glpi_plugin_urbackup_serverassets',
|
||||
'glpi_plugin_urbackup_profiles',
|
||||
];
|
||||
|
||||
$missing_table_found = false;
|
||||
|
||||
foreach ($required_tables as $table) {
|
||||
if (!$DB->tableExists($table)) {
|
||||
$missing_table_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$missing_table_found) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->displayMessage(__('Creating UrBackup plugin database schema', 'urbackup'));
|
||||
|
||||
$db_file = PLUGIN_URBACKUP_DIR . '/install/mysql/plugin_urbackup-empty.sql';
|
||||
|
||||
if (!file_exists($db_file)) {
|
||||
$migration->displayMessage(
|
||||
sprintf(
|
||||
__('Database schema file not found: %s', 'urbackup'),
|
||||
$db_file
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$DB->runFile($db_file)) {
|
||||
$migration->displayMessage(__('Error while creating UrBackup plugin database schema', 'urbackup'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update configs table.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_update_configs_table(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$table = 'glpi_plugin_urbackup_configs';
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->addField($table, 'name', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'value', 'text', [
|
||||
'after' => 'name',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'date_creation', 'timestamp');
|
||||
$migration->addField($table, 'date_mod', 'timestamp');
|
||||
|
||||
$migration->addKey($table, 'name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update assettypes table.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_update_assettypes_table(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$table = 'glpi_plugin_urbackup_assettypes';
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->addField($table, 'itemtype', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'is_active', 'bool', [
|
||||
'value' => 0,
|
||||
'after' => 'itemtype',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'is_default', 'bool', [
|
||||
'value' => 0,
|
||||
'after' => 'is_active',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'date_creation', 'timestamp');
|
||||
$migration->addField($table, 'date_mod', 'timestamp');
|
||||
|
||||
$migration->addKey($table, 'itemtype');
|
||||
$migration->addKey($table, 'is_active');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update servers table.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_update_servers_table(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$table = 'glpi_plugin_urbackup_servers';
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->addField($table, 'entities_id', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'is_recursive', 'bool', [
|
||||
'value' => 0,
|
||||
'after' => 'entities_id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'name', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'is_recursive',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'locations_id', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'name',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'ip_address', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'locations_id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'port', 'integer', [
|
||||
'value' => 55414,
|
||||
'after' => 'ip_address',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'protocol', 'string', [
|
||||
'value' => 'http',
|
||||
'after' => 'port',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'server_version', 'string', [
|
||||
'after' => 'protocol',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'api_username', 'string', [
|
||||
'after' => 'server_version',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'api_password', 'text', [
|
||||
'after' => 'api_username',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'ignore_ssl', 'bool', [
|
||||
'value' => 0,
|
||||
'after' => 'api_password',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'is_active', 'bool', [
|
||||
'value' => 1,
|
||||
'after' => 'ignore_ssl',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'last_api_status', 'bool', [
|
||||
'value' => 0,
|
||||
'after' => 'is_active',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'last_api_message', 'text', [
|
||||
'after' => 'last_api_status',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'last_api_check', 'timestamp', [
|
||||
'after' => 'last_api_message',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'comment', 'text', [
|
||||
'after' => 'last_api_check',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'date_creation', 'timestamp');
|
||||
$migration->addField($table, 'date_mod', 'timestamp');
|
||||
|
||||
$migration->addKey($table, 'name');
|
||||
$migration->addKey($table, 'entities_id');
|
||||
$migration->addKey($table, 'locations_id');
|
||||
$migration->addKey($table, 'is_active');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update serverassets table.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_update_serverassets_table(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$table = 'glpi_plugin_urbackup_serverassets';
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->addField($table, 'plugin_urbackup_servers_id', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'itemtype', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'plugin_urbackup_servers_id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'items_id', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'itemtype',
|
||||
]);
|
||||
|
||||
$migration->addKey($table, 'plugin_urbackup_servers_id');
|
||||
$migration->addKey($table, ['itemtype', 'items_id'], 'item');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update profiles table.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_install_update_profiles_table(Migration $migration): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$table = 'glpi_plugin_urbackup_profiles';
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->addField($table, 'profiles_id', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'rightname', 'string', [
|
||||
'value' => '',
|
||||
'after' => 'profiles_id',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'rights', 'integer', [
|
||||
'value' => 0,
|
||||
'after' => 'rightname',
|
||||
]);
|
||||
|
||||
$migration->addField($table, 'date_creation', 'timestamp');
|
||||
$migration->addField($table, 'date_mod', 'timestamp');
|
||||
|
||||
$migration->addKey($table, ['profiles_id', 'rightname'], 'profile_right');
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_configs` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`value` TEXT DEFAULT NULL,
|
||||
`date_creation` TIMESTAMP NULL DEFAULT NULL,
|
||||
`date_mod` TIMESTAMP NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_assettypes` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`itemtype` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`is_active` TINYINT NOT NULL DEFAULT 0,
|
||||
`is_default` TINYINT NOT NULL DEFAULT 0,
|
||||
`date_creation` TIMESTAMP NULL DEFAULT NULL,
|
||||
`date_mod` TIMESTAMP NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `itemtype` (`itemtype`),
|
||||
KEY `is_active` (`is_active`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_servers` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`entities_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`is_recursive` TINYINT NOT NULL DEFAULT 0,
|
||||
`name` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`locations_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',
|
||||
`server_version` VARCHAR(64) DEFAULT NULL,
|
||||
`api_username` VARCHAR(255) DEFAULT NULL,
|
||||
`api_password` TEXT DEFAULT NULL,
|
||||
`ignore_ssl` TINYINT NOT NULL DEFAULT 0,
|
||||
`is_active` TINYINT NOT NULL DEFAULT 1,
|
||||
`last_api_status` TINYINT NOT NULL DEFAULT 0,
|
||||
`last_api_message` TEXT DEFAULT NULL,
|
||||
`last_api_check` TIMESTAMP NULL DEFAULT NULL,
|
||||
`comment` TEXT DEFAULT NULL,
|
||||
`date_creation` TIMESTAMP NULL DEFAULT NULL,
|
||||
`date_mod` TIMESTAMP NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `name` (`name`),
|
||||
KEY `entities_id` (`entities_id`),
|
||||
KEY `locations_id` (`locations_id`),
|
||||
KEY `is_active` (`is_active`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_serverassets` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`plugin_urbackup_servers_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`itemtype` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`items_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `plugin_urbackup_servers_id` (`plugin_urbackup_servers_id`),
|
||||
KEY `item` (`itemtype`, `items_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `glpi_plugin_urbackup_profiles` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`profiles_id` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`rightname` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`rights` INT NOT NULL DEFAULT 0,
|
||||
`date_creation` TIMESTAMP NULL DEFAULT NULL,
|
||||
`date_mod` TIMESTAMP NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `profile_right` (`profiles_id`, `rightname`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* UrBackup plugin for GLPI
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Uninstall process for GLPI 11.
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
use GlpiPlugin\Urbackup\Profile;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die('Sorry. You cannot access this file directly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall plugin.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_uninstall_process(): bool
|
||||
{
|
||||
$migration = new Migration(PLUGIN_URBACKUP_VERSION);
|
||||
|
||||
$migration->displayMessage(__('UrBackup plugin uninstallation', 'urbackup'));
|
||||
|
||||
Profile::uninstallRights();
|
||||
|
||||
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');
|
||||
plugin_urbackup_migration_drop_table($migration, 'glpi_plugin_urbackup_assettypes');
|
||||
plugin_urbackup_migration_drop_table($migration, 'glpi_plugin_urbackup_configs');
|
||||
|
||||
$migration->executeMigration();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a plugin table through Migration.
|
||||
*
|
||||
* @param Migration $migration Migration instance
|
||||
* @param string $table Table name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_migration_drop_table(Migration $migration, $table): void
|
||||
{
|
||||
global $DB;
|
||||
|
||||
if (!$DB->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration->dropTable($table);
|
||||
}
|
||||
Reference in New Issue
Block a user