Add full monitor edit modal, direct token creation per monitor row, and cascade deletion/renaming in Watchdog

This commit is contained in:
Deploymentcenter Bot
2026-08-05 22:58:04 +02:00
parent 9808d143f7
commit 21275d1a1f
2 changed files with 173 additions and 32 deletions
+23
View File
@@ -81,19 +81,31 @@ class MonitorRepo
string $oldSource,
string $newSource,
string $instance,
?string $type,
?string $groupKey,
?string $parentSource,
?string $os,
?string $notes,
?string $url,
?int $intervalSec,
?string $icon = null,
bool $isMuted = false
): bool {
// Cascade source renaming to children & agent tokens
if ($oldSource !== $newSource) {
$this->db->prepare('UPDATE watchdog_monitors SET parent_source = :new WHERE parent_source = :old')
->execute([':new' => $newSource, ':old' => $oldSource]);
$this->db->prepare('UPDATE watchdog_agent_tokens SET monitor_source = :new WHERE monitor_source = :old')
->execute([':new' => $newSource, ':old' => $oldSource]);
}
$stmt = $this->db->prepare('
UPDATE watchdog_monitors SET
source = :new_source,
type = COALESCE(:type, type),
group_key = :group_key,
parent_source = :parent_source,
os = :os,
notes = :notes,
url = :url,
expected_interval_sec = COALESCE(:interval, expected_interval_sec),
@@ -105,8 +117,10 @@ class MonitorRepo
return $stmt->execute([
':new_source' => $newSource,
':type' => !empty($type) ? $type : null,
':group_key' => !empty($groupKey) ? $groupKey : null,
':parent_source' => !empty($parentSource) ? $parentSource : null,
':os' => !empty($os) ? $os : null,
':notes' => !empty($notes) ? $notes : null,
':url' => !empty($url) ? $url : null,
':interval' => $intervalSec,
@@ -138,6 +152,15 @@ class MonitorRepo
public function deleteMonitor(string $source, string $instance = 'default'): bool
{
// 1. Unlink any children
$this->db->prepare('UPDATE watchdog_monitors SET parent_source = NULL WHERE parent_source = :s')
->execute([':s' => $source]);
// 2. Revoke agent tokens for this monitor
$this->db->prepare('UPDATE watchdog_agent_tokens SET revoked = 1 WHERE monitor_source = :s')
->execute([':s' => $source]);
// 3. Delete monitor
$stmt = $this->db->prepare('DELETE FROM watchdog_monitors WHERE source = :s AND instance = :i');
return $stmt->execute([':s' => $source, ':i' => $instance]);
}