Stable
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
// Force OPcache to reload this file when accessed via web
|
||||
if (PHP_SAPI !== 'cli' && function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate(__FILE__, true);
|
||||
}
|
||||
|
||||
use Glpi\Plugin\Hooks;
|
||||
use GlpiPlugin\Urbackup\AssetTab;
|
||||
use GlpiPlugin\Urbackup\Config;
|
||||
use GlpiPlugin\Urbackup\Profile;
|
||||
use GlpiPlugin\Urbackup\Server;
|
||||
use GlpiPlugin\Urbackup\ServerAsset;
|
||||
use GlpiPlugin\Urbackup\MassiveAction as PluginUrbackupMassiveAction;
|
||||
|
||||
define('PLUGIN_URBACKUP_VERSION', '0.4.2');
|
||||
define('PLUGIN_URBACKUP_MIN_GLPI', '11.0.0');
|
||||
define('PLUGIN_URBACKUP_MAX_GLPI', '11.99.99');
|
||||
|
||||
if (!defined('PLUGIN_URBACKUP_DIR')) {
|
||||
define('PLUGIN_URBACKUP_DIR', __DIR__);
|
||||
}
|
||||
|
||||
if (!defined('PLUGIN_URBACKUP_WEB_DIR')) {
|
||||
define('PLUGIN_URBACKUP_WEB_DIR', Plugin::getWebDir('urbackup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize plugin hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_init_urbackup(): void
|
||||
{
|
||||
global $PLUGIN_HOOKS;
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['urbackup'] = true;
|
||||
$PLUGIN_HOOKS[Hooks::CHANGE_PROFILE]['urbackup'] = [Profile::class, 'initProfile'];
|
||||
|
||||
Profile::registerRights();
|
||||
|
||||
Plugin::registerClass(Config::class);
|
||||
Plugin::registerClass(Profile::class, [
|
||||
'addtabon' => 'Profile',
|
||||
]);
|
||||
Plugin::registerClass(Server::class, [
|
||||
'linkgroup_types' => true,
|
||||
'document_types' => true,
|
||||
]);
|
||||
Plugin::registerClass(ServerAsset::class);
|
||||
Plugin::registerClass(PluginUrbackupMassiveAction::class);
|
||||
|
||||
// Register tab on Computer and other assets
|
||||
$enabled_types = Config::getEnabledItemtypes();
|
||||
if (!empty($enabled_types)) {
|
||||
Plugin::registerClass(AssetTab::class, [
|
||||
'addtabon' => $enabled_types,
|
||||
]);
|
||||
}
|
||||
|
||||
$PLUGIN_HOOKS['config_page']['urbackup'] = 'front/config.form.php';
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::MENU_TOADD]['urbackup'] = [
|
||||
'admin' => Server::class,
|
||||
];
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::USE_MASSIVE_ACTION]['urbackup'] = true;
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::ADD_CSS]['urbackup'] = [
|
||||
'public/css/urbackup.css',
|
||||
];
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['urbackup'] = [
|
||||
'public/js/urbackup.js',
|
||||
];
|
||||
|
||||
$PLUGIN_HOOKS[Hooks::POST_INIT]['urbackup'] = 'plugin_urbackup_postinit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Post init hook.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function plugin_urbackup_postinit(): void
|
||||
{
|
||||
Config::registerAssetTabs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin version information.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
function plugin_version_urbackup(): array
|
||||
{
|
||||
return [
|
||||
'name' => __('UrBackup', 'urbackup'),
|
||||
'version' => PLUGIN_URBACKUP_VERSION,
|
||||
'author' => 'Finstral',
|
||||
'license' => 'GPL-2.0-or-later',
|
||||
'homepage' => '',
|
||||
'requirements' => [
|
||||
'glpi' => [
|
||||
'min' => PLUGIN_URBACKUP_MIN_GLPI,
|
||||
'max' => PLUGIN_URBACKUP_MAX_GLPI,
|
||||
],
|
||||
'php' => [
|
||||
'min' => '8.3.0',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check plugin prerequisites.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_check_prerequisites(): bool
|
||||
{
|
||||
if (version_compare(GLPI_VERSION, PLUGIN_URBACKUP_MIN_GLPI, '<')) {
|
||||
echo sprintf(
|
||||
__('This plugin requires GLPI >= %s.', 'urbackup'),
|
||||
PLUGIN_URBACKUP_MIN_GLPI
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version_compare(GLPI_VERSION, PLUGIN_URBACKUP_MAX_GLPI, '>')) {
|
||||
echo sprintf(
|
||||
__('This plugin requires GLPI < %s.', 'urbackup'),
|
||||
PLUGIN_URBACKUP_MAX_GLPI
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '8.3.0', '<')) {
|
||||
echo __('This plugin requires PHP 8.3 or higher.', 'urbackup');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check plugin config.
|
||||
*
|
||||
* @param bool $verbose Verbose output
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_check_config(bool $verbose = false): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin installation function.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_install(): bool
|
||||
{
|
||||
require_once __DIR__ . '/install/install.php';
|
||||
return plugin_urbackup_install_process();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin uninstallation function.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function plugin_urbackup_uninstall(): bool
|
||||
{
|
||||
require_once __DIR__ . '/install/uninstall.php';
|
||||
return plugin_urbackup_uninstall_process();
|
||||
}
|
||||
Reference in New Issue
Block a user