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
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/**
* -------------------------------------------------------------------------
* UrBackup plugin for GLPI
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/**
* -------------------------------------------------------------------------
* UrBackup plugin for GLPI
+4 -2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/**
* -------------------------------------------------------------------------
* UrBackup plugin for GLPI
@@ -327,7 +329,7 @@ class Server extends CommonDBTM
$this->initForm($ID, $options);
$this->showFormHeader($options);
$this->showFormFields($ID);
$this->showFormFields($ID > 0 ? (int) $ID : null);
$this->showFormButtons($options);
return true;
@@ -1339,7 +1341,7 @@ JAVASCRIPT;
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;
+6 -14
View File
@@ -79,7 +79,6 @@ class ServerAsset extends CommonDBTM
}
$table = self::getTable();
$date = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s');
$existing = self::getLinkForAsset($itemtype, $items_id, false);
@@ -88,10 +87,6 @@ class ServerAsset extends CommonDBTM
$table,
[
'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'],
@@ -243,43 +238,40 @@ class ServerAsset extends CommonDBTM
echo "<div class='center'>";
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 "<th>" . htmlspecialchars(__('Asset', 'urbackup')) . "</th>";
echo "<th>" . htmlspecialchars(__('Type')) . "</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>";
$iterator = $DB->request([
'FROM' => self::getTable(),
'WHERE' => [
'plugin_urbackup_servers_id' => (int) $item->fields['id'],
'is_active' => 1,
],
'ORDER' => 'client_name',
]);
foreach ($iterator as $row) {
$asset_label = (string) $row['client_name'];
$itemtype = (string) $row['itemtype'];
$items_id = (int) $row['items_id'];
$asset_label = (string) $items_id;
$asset_ip = '';
if (class_exists($itemtype)) {
$asset = new $itemtype();
if ($asset instanceof CommonDBTM && $asset->getFromDB($items_id)) {
$asset_label = $asset->getLink();
$asset_ip = Server::getAssetIp($itemtype, $items_id);
}
}
echo "<tr class='tab_bg_1'>";
echo "<td>" . $asset_label . "</td>";
echo "<td>" . htmlspecialchars($itemtype) . "</td>";
echo "<td>" . htmlspecialchars((string) $row['client_ip']) . "</td>";
echo "<td>" . htmlspecialchars((string) $row['last_file_backup']) . "</td>";
echo "<td>" . htmlspecialchars((string) $row['last_image_backup']) . "</td>";
echo "<td>" . htmlspecialchars($asset_ip ?: '-') . "</td>";
echo "</tr>";
}