Files
urbackup/src/Config.php
T

165 lines
4.2 KiB
PHP
Raw Normal View History

2026-05-20 09:20:27 +02:00
<?php
declare(strict_types=1);
/**
* -------------------------------------------------------------------------
* UrBackup plugin for GLPI
* -------------------------------------------------------------------------
*/
namespace GlpiPlugin\Urbackup;
use CommonDBTM;
2026-05-22 08:29:59 +02:00
use Glpi\Asset\Asset;
2026-05-20 09:20:27 +02:00
use Glpi\Asset\AssetDefinitionManager;
use DBmysql;
use Html;
use Session;
class Config extends CommonDBTM
{
public static $rightname = 'config';
/**
* Get type name.
*
* @param int $nb Number
*
* @return string
*/
public static function getTypeName($nb = 0): string
{
return __('UrBackup configuration', 'urbackup');
}
/**
* Get table name.
*
* @param string|null $classname Class name
*
* @return string
*/
public static function getTable($classname = null): string
{
return 'glpi_plugin_urbackup_configs';
}
/**
* Ensure default configuration.
*
* @return void
*/
public static function ensureDefaultConfiguration(): void
{
2026-05-22 08:29:59 +02:00
// Computer is always enabled by default.
// Asset Definition types are managed via the native Capacities UI.
2026-05-20 09:20:27 +02:00
}
/**
* Get assettypes table name.
*
* @return string
*/
public static function getAssetTypesTable(): string
{
return 'glpi_plugin_urbackup_assettypes';
}
/**
* Check whether itemtype is enabled for UrBackup.
*
* @param string $itemtype Itemtype
*
* @return bool
*/
public static function isItemtypeEnabled(string $itemtype): bool
{
if ($itemtype === '') {
return false;
}
if ($itemtype === 'Computer') {
return true;
}
2026-05-22 08:29:59 +02:00
// All Asset subclasses are enabled by default.
// The UrBackupCapacity is still registered for cleanup (onCapacityDisabled)
// and usage tracking in the Capacities UI, but visibility is always on
// so the tab appears out of the box on any Asset Definition.
if (is_a($itemtype, Asset::class, true)) {
return true;
2026-05-20 09:20:27 +02:00
}
2026-05-22 08:29:59 +02:00
return false;
2026-05-20 09:20:27 +02:00
}
/**
* Get enabled itemtypes.
*
* @return array<int, string>
*/
public static function getEnabledItemtypes(): array
{
2026-05-22 08:29:59 +02:00
$itemtypes = ['Computer'];
2026-05-20 09:20:27 +02:00
2026-05-22 08:29:59 +02:00
if (class_exists(AssetDefinitionManager::class)) {
$manager = AssetDefinitionManager::getInstance();
foreach ($manager->getDefinitions() as $definition) {
$classname = $definition->getAssetClassName();
if (!in_array($classname, $itemtypes, true)) {
$itemtypes[] = $classname;
}
2026-05-20 09:20:27 +02:00
}
}
2026-05-22 08:29:59 +02:00
return $itemtypes;
2026-05-20 09:20:27 +02:00
}
/**
* Show config form.
*
* @param int $ID ID
* @param array $options Options
*
* @return bool
*/
public function showForm($ID, array $options = []): bool
{
Session::checkRight('config', UPDATE);
echo "<div class='center'>";
echo "<table class='tab_cadre_fixe'>";
2026-05-22 08:29:59 +02:00
echo "<tr><th colspan='2'>" . htmlspecialchars(__('UrBackup configuration', 'urbackup')) . "</th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td><strong>" . htmlspecialchars(__('Computer', 'urbackup')) . "</strong></td>";
echo "<td><span class='badge bg-success'>" . htmlspecialchars(__('Always enabled', 'urbackup')) . "</span></td>";
2026-05-20 09:20:27 +02:00
echo "</tr>";
echo "</table>";
2026-05-22 08:29:59 +02:00
echo "<br>";
echo "<div class='alert alert-info'>";
echo htmlspecialchars(
__('For Asset Definition types, enable/disable UrBackup via Config > Asset definitions > Capacities.', 'urbackup')
);
echo "</div>";
echo "</div>";
2026-05-20 09:20:27 +02:00
return true;
}
/**
* Save configuration.
*
2026-05-22 08:29:59 +02:00
* In the new capacity system, asset types are managed via the native Capacities UI.
* This method is kept for backward compatibility but does nothing.
*
2026-05-20 09:20:27 +02:00
* @param array<string, mixed> $input Input data
*
* @return void
*/
public static function saveConfiguration(array $input): void
{
Session::checkRight('config', UPDATE);
}
}