pluizia codice

This commit is contained in:
mariano
2026-05-21 10:54:04 +02:00
parent 5fac26040a
commit 223180d1a9
12 changed files with 32 additions and 38 deletions
+3 -9
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * UrBackup plugin for GLPI
@@ -70,15 +72,7 @@ if (isset($_POST['disconnect'])) {
Html::displayRightError(); Html::displayRightError();
} }
global $DB; $result = ServerAsset::disconnectAsset($itemtype, $items_id);
$link = ServerAsset::getLinkForAsset($itemtype, $items_id, false);
if ($link === null) {
Html::displayValidationError(__('Asset is not linked to any server'));
}
$result = $DB->delete('glpi_plugin_urbackup_serverassets', ['id' => (int) $link['id']]);
if ($result) { if ($result) {
$item->getFromDB($items_id); $item->getFromDB($items_id);
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
use GlpiPlugin\Urbackup\Config; use GlpiPlugin\Urbackup\Config;
use Html; use Html;
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
use GlpiPlugin\Urbackup\Profile; use GlpiPlugin\Urbackup\Profile;
use GlpiPlugin\Urbackup\Server; use GlpiPlugin\Urbackup\Server;
use GlpiPlugin\Urbackup\ServerAsset; use GlpiPlugin\Urbackup\ServerAsset;
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
use GlpiPlugin\Urbackup\Profile; use GlpiPlugin\Urbackup\Profile;
use GlpiPlugin\Urbackup\Server; use GlpiPlugin\Urbackup\Server;
use Html; use Html;
+3
View File
@@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* AJAX endpoint for testing UrBackup API * AJAX endpoint for testing UrBackup API
*/ */
+2 -10
View File
@@ -1,19 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * 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\Config;
+2 -3
View File
@@ -1,12 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * UrBackup plugin for GLPI
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*
* Uninstall process for GLPI 11.
* -------------------------------------------------------------------------
*/ */
use GlpiPlugin\Urbackup\Profile; use GlpiPlugin\Urbackup\Profile;
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
// Force OPcache to reload this file when accessed via web // Force OPcache to reload this file when accessed via web
if (PHP_SAPI !== 'cli' && function_exists('opcache_invalidate')) { if (PHP_SAPI !== 'cli' && function_exists('opcache_invalidate')) {
opcache_invalidate(__FILE__, true); opcache_invalidate(__FILE__, true);
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * UrBackup plugin for GLPI
+2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * UrBackup plugin for GLPI
+4 -2
View File
@@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* UrBackup plugin for GLPI * UrBackup plugin for GLPI
@@ -327,7 +329,7 @@ class Server extends CommonDBTM
$this->initForm($ID, $options); $this->initForm($ID, $options);
$this->showFormHeader($options); $this->showFormHeader($options);
$this->showFormFields($ID); $this->showFormFields($ID > 0 ? (int) $ID : null);
$this->showFormButtons($options); $this->showFormButtons($options);
return true; return true;
@@ -1339,7 +1341,7 @@ JAVASCRIPT;
return $cache[$id]; return $cache[$id];
} }
private static function getAssetIp(string $itemtype, int $items_id): string public static function getAssetIp(string $itemtype, int $items_id): string
{ {
global $DB; global $DB;
+6 -14
View File
@@ -79,7 +79,6 @@ class ServerAsset extends CommonDBTM
} }
$table = self::getTable(); $table = self::getTable();
$date = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s');
$existing = self::getLinkForAsset($itemtype, $items_id, false); $existing = self::getLinkForAsset($itemtype, $items_id, false);
@@ -88,10 +87,6 @@ class ServerAsset extends CommonDBTM
$table, $table,
[ [
'plugin_urbackup_servers_id' => $server_id, 'plugin_urbackup_servers_id' => $server_id,
'client_name' => (string) ($item->fields['name'] ?? ''),
'client_ip' => self::extractAssetIp($item),
'is_active' => 1,
'date_mod' => $date,
], ],
[ [
'id' => (int) $existing['id'], 'id' => (int) $existing['id'],
@@ -243,43 +238,40 @@ class ServerAsset extends CommonDBTM
echo "<div class='center'>"; echo "<div class='center'>";
echo "<table class='tab_cadre_fixehov'>"; echo "<table class='tab_cadre_fixehov'>";
echo "<tr><th colspan='5'>" . htmlspecialchars(__('Linked assets', 'urbackup')) . "</th></tr>"; echo "<tr><th colspan='4'>" . htmlspecialchars(__('Linked assets', 'urbackup')) . "</th></tr>";
echo "<tr>"; echo "<tr>";
echo "<th>" . htmlspecialchars(__('Asset', 'urbackup')) . "</th>"; echo "<th>" . htmlspecialchars(__('Asset', 'urbackup')) . "</th>";
echo "<th>" . htmlspecialchars(__('Type')) . "</th>"; echo "<th>" . htmlspecialchars(__('Type')) . "</th>";
echo "<th>" . htmlspecialchars(__('IP address', 'urbackup')) . "</th>"; echo "<th>" . htmlspecialchars(__('IP address', 'urbackup')) . "</th>";
echo "<th>" . htmlspecialchars(__('Last file backup', 'urbackup')) . "</th>";
echo "<th>" . htmlspecialchars(__('Last image backup', 'urbackup')) . "</th>";
echo "</tr>"; echo "</tr>";
$iterator = $DB->request([ $iterator = $DB->request([
'FROM' => self::getTable(), 'FROM' => self::getTable(),
'WHERE' => [ 'WHERE' => [
'plugin_urbackup_servers_id' => (int) $item->fields['id'], 'plugin_urbackup_servers_id' => (int) $item->fields['id'],
'is_active' => 1,
], ],
'ORDER' => 'client_name',
]); ]);
foreach ($iterator as $row) { foreach ($iterator as $row) {
$asset_label = (string) $row['client_name'];
$itemtype = (string) $row['itemtype']; $itemtype = (string) $row['itemtype'];
$items_id = (int) $row['items_id']; $items_id = (int) $row['items_id'];
$asset_label = (string) $items_id;
$asset_ip = '';
if (class_exists($itemtype)) { if (class_exists($itemtype)) {
$asset = new $itemtype(); $asset = new $itemtype();
if ($asset instanceof CommonDBTM && $asset->getFromDB($items_id)) { if ($asset instanceof CommonDBTM && $asset->getFromDB($items_id)) {
$asset_label = $asset->getLink(); $asset_label = $asset->getLink();
$asset_ip = Server::getAssetIp($itemtype, $items_id);
} }
} }
echo "<tr class='tab_bg_1'>"; echo "<tr class='tab_bg_1'>";
echo "<td>" . $asset_label . "</td>"; echo "<td>" . $asset_label . "</td>";
echo "<td>" . htmlspecialchars($itemtype) . "</td>"; echo "<td>" . htmlspecialchars($itemtype) . "</td>";
echo "<td>" . htmlspecialchars((string) $row['client_ip']) . "</td>"; echo "<td>" . htmlspecialchars($asset_ip ?: '-') . "</td>";
echo "<td>" . htmlspecialchars((string) $row['last_file_backup']) . "</td>";
echo "<td>" . htmlspecialchars((string) $row['last_image_backup']) . "</td>";
echo "</tr>"; echo "</tr>";
} }