From 6d63ca00df194ae1e3166c5701ab4aa933447a53 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Fri, 2 Oct 2026 13:57:44 +0200 Subject: [PATCH] feat(remotepc): add reboot on unreserve configuration for UDS --- CHANGELOG.md | 5 ++++ migrations/Version20261002135500.php | 31 +++++++++++++++++++++ src/Controller/UDS/RemotePcController.php | 20 ++++++++++++- src/Dto/Input/OrganizationalUnitInput.php | 9 ++++++ src/Dto/Output/OrganizationalUnitOutput.php | 8 ++++++ src/Entity/OrganizationalUnit.php | 15 ++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20261002135500.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c411cd..16241f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.11.0] - 2026-10-02 + +### Added +- **RemotePC**: Añadida la propiedad `remotePcRebootOnUnreserve` a la entidad `OrganizationalUnit` para permitir configurar si un equipo remoto debe ser reiniciado en lugar de apagado cuando UDS libera su reserva. + ## [1.10.0] - 2026-09-23 ### Added diff --git a/migrations/Version20261002135500.php b/migrations/Version20261002135500.php new file mode 100644 index 0000000..c5e93f6 --- /dev/null +++ b/migrations/Version20261002135500.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE organizational_unit ADD remote_pc_reboot_on_unreserve TINYINT(1) NOT NULL DEFAULT 0'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE organizational_unit DROP remote_pc_reboot_on_unreserve'); + } +} diff --git a/src/Controller/UDS/RemotePcController.php b/src/Controller/UDS/RemotePcController.php index bd7026d..098c0d0 100644 --- a/src/Controller/UDS/RemotePcController.php +++ b/src/Controller/UDS/RemotePcController.php @@ -183,7 +183,11 @@ class RemotePcController extends AbstractController ->setParameter('status', TraceStatus::PENDING) ->execute(); - $this->sendPowerOff($client); + if ($client->getOrganizationalUnit() && $client->getOrganizationalUnit()->isRemotePcRebootOnUnreserve()) { + $this->sendReboot($client); + } else { + $this->sendPowerOff($client); + } $this->logger->info('RemotePC: client unreserved', ['client_id' => $client->getId()]); @@ -375,6 +379,20 @@ class RemotePcController extends AbstractController } } + private function sendReboot(Client $client): void + { + try { + $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/Reiniciar', [ + 'verify_host' => false, + 'timeout' => 2.0, + 'headers' => ['Authorization' => $client->getToken()], + ])->getStatusCode(); + $this->logger->info('RemotePC: reboot sent', ['ip' => $client->getIp()]); + } catch (TransportExceptionInterface | HttpExceptionInterface $e) { + $this->logger->warning('RemotePC: reboot failed', ['client_id' => $client->getId(), 'error' => $e->getMessage()]); + } + } + private function createQueueEntry(Client $client, \DateTimeInterface $execTime, string $operation): void { $entry = new AgentQueue(); diff --git a/src/Dto/Input/OrganizationalUnitInput.php b/src/Dto/Input/OrganizationalUnitInput.php index b26c715..4229e09 100644 --- a/src/Dto/Input/OrganizationalUnitInput.php +++ b/src/Dto/Input/OrganizationalUnitInput.php @@ -102,6 +102,13 @@ class OrganizationalUnitInput )] public ?bool $remotePc = false; + #[Groups(['organizational-unit:write'])] + #[ApiProperty( + description: 'Indica si RemotePC debe reiniciar el equipo al liberar la reserva', + example: false + )] + public ?bool $remotePcRebootOnUnreserve = false; + #[Groups(['organizational-unit:write'])] #[ApiProperty( description: 'Si excluir cambios del padre', @@ -128,6 +135,7 @@ class OrganizationalUnitInput $this->comments = $organizationalUnit->getComments(); $this->type = $organizationalUnit->getType(); $this->remotePc = $organizationalUnit->isRemotePc(); + $this->remotePcRebootOnUnreserve = $organizationalUnit->isRemotePcRebootOnUnreserve(); if ($organizationalUnit->getNetworkSettings()){ $this->networkSettings = new NetworkSettingsInput($organizationalUnit->getNetworkSettings()); } @@ -155,6 +163,7 @@ class OrganizationalUnitInput $organizationalUnit->setComments($this->comments); $organizationalUnit->setType($this->type); $organizationalUnit->setRemotePc($this->remotePc); + $organizationalUnit->setRemotePcRebootOnUnreserve($this->remotePcRebootOnUnreserve ?? false); $organizationalUnit->setExcludeParentChanges($this->excludeParentChanges); if ($this->networkSettings){ diff --git a/src/Dto/Output/OrganizationalUnitOutput.php b/src/Dto/Output/OrganizationalUnitOutput.php index 290f0ad..54eb1fa 100644 --- a/src/Dto/Output/OrganizationalUnitOutput.php +++ b/src/Dto/Output/OrganizationalUnitOutput.php @@ -109,6 +109,13 @@ final class OrganizationalUnitOutput extends AbstractOutput )] public ?bool $remotePc = null; + #[Groups(['organizational-unit:read'])] + #[ApiProperty( + description: 'Indica si RemotePC debe reiniciar el equipo al liberar la reserva', + example: false + )] + public ?bool $remotePcRebootOnUnreserve = null; + #[Groups(['organizational-unit:read'])] #[ApiProperty( description: 'Indica si está disponible según el calendario', @@ -150,6 +157,7 @@ final class OrganizationalUnitOutput extends AbstractOutput $this->capacity = $organizationalUnit->getCapacity(); $this->type = $organizationalUnit->getType(); $this->remotePc = $organizationalUnit->isRemotePc(); + $this->remotePcRebootOnUnreserve = $organizationalUnit->isRemotePcRebootOnUnreserve(); $this->available = $organizationalUnit->getRemoteCalendar() && $organizationalUnit->getRemoteCalendar()->isAvailable(); $this->networkSettings = $organizationalUnit->getNetworkSettings() ? new NetworkSettingsOutput($organizationalUnit->getNetworkSettings()) : null; $this->remoteCalendar = $organizationalUnit->getRemoteCalendar() ? new RemoteCalendarOutput($organizationalUnit->getRemoteCalendar()) : null; diff --git a/src/Entity/OrganizationalUnit.php b/src/Entity/OrganizationalUnit.php index d2be019..39e3f07 100644 --- a/src/Entity/OrganizationalUnit.php +++ b/src/Entity/OrganizationalUnit.php @@ -89,6 +89,9 @@ class OrganizationalUnit extends AbstractEntity #[ORM\Column] private ?bool $remotePc = false; + #[ORM\Column] + private ?bool $remotePcRebootOnUnreserve = false; + #[ORM\Column] private ?bool $reserved = false; @@ -404,6 +407,18 @@ class OrganizationalUnit extends AbstractEntity return $this; } + public function isRemotePcRebootOnUnreserve(): ?bool + { + return $this->remotePcRebootOnUnreserve; + } + + public function setRemotePcRebootOnUnreserve(bool $remotePcRebootOnUnreserve): static + { + $this->remotePcRebootOnUnreserve = $remotePcRebootOnUnreserve; + + return $this; + } + public function isReserved(): ?bool { return $this->reserved;