From 09d45de9c46d8a3b20794bec693b061e097408d9 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 13 May 2025 10:34:24 +0200 Subject: [PATCH 1/3] added calls to notification endpoints --- app/Jobs/UpdateSite.php | 9 +++++++++ app/RemoteSite/Connection.php | 3 +++ app/RemoteSite/Responses/Notification.php | 13 +++++++++++++ app/RemoteSite/WebserviceEndpoint.php | 8 ++++++++ 4 files changed, 33 insertions(+) create mode 100644 app/RemoteSite/Responses/Notification.php diff --git a/app/Jobs/UpdateSite.php b/app/Jobs/UpdateSite.php index bff698b..11ae42e 100644 --- a/app/Jobs/UpdateSite.php +++ b/app/Jobs/UpdateSite.php @@ -110,6 +110,9 @@ public function handle(): void "Status code has changed after update for site: " . $this->site->id ); } + + // Notify users + $connection->notificationSuccess(["fromVersion" => $healthResult->cms_version]); } protected function performExtraction(PrepareUpdate $prepareResult): void @@ -166,6 +169,12 @@ protected function performExtraction(PrepareUpdate $prepareResult): void public function failed(\Exception $exception): void { + /** @var Connection $connection */ + $connection = $this->site->connection; + + // Notify users + $connection->notificationFailed(["fromVersion" => $this->site->cms_version]); + // We log any issues during the update to the DB $this->site->updates()->create([ 'old_version' => $this->site->cms_version, diff --git a/app/RemoteSite/Connection.php b/app/RemoteSite/Connection.php index 7d7bd83..3f32adf 100644 --- a/app/RemoteSite/Connection.php +++ b/app/RemoteSite/Connection.php @@ -9,6 +9,7 @@ use App\RemoteSite\Responses\GetUpdate as GetUpdateResponse; use App\RemoteSite\Responses\HealthCheck as HealthCheckResponse; use App\RemoteSite\Responses\PrepareUpdate as PrepareUpdateResponse; +use App\RemoteSite\Responses\Notification as NotificationResponse; use App\RemoteSite\Responses\ResponseInterface; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; @@ -22,6 +23,8 @@ * @method GetUpdateResponse getUpdate() * @method PrepareUpdateResponse prepareUpdate(array $data) * @method FinalizeUpdateResponse finalizeUpdate(array $data) + * @method NotificationResponse notificationSuccess(array $data) + * @method NotificationResponse notificationFailed(array $data) */ class Connection { diff --git a/app/RemoteSite/Responses/Notification.php b/app/RemoteSite/Responses/Notification.php new file mode 100644 index 0000000..0fb19a7 --- /dev/null +++ b/app/RemoteSite/Responses/Notification.php @@ -0,0 +1,13 @@ +name: case self::finalizeUpdate->name: + case self::notificationSuccess->name: + case self::notificationFailed->name: return HttpMethod::POST; } @@ -42,6 +47,9 @@ public function getResponseClass(): string return PrepareUpdate::class; case self::finalizeUpdate->name: return FinalizeUpdate::class; + case self::notificationSuccess->name: + case self::notificationFailed->name: + return Notification::class; } } From ab108c154a3c497862533e8330a1f898aafbce85 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 13 May 2025 10:38:08 +0200 Subject: [PATCH 2/3] fix test --- tests/Unit/Jobs/UpdateSiteTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Jobs/UpdateSiteTest.php b/tests/Unit/Jobs/UpdateSiteTest.php index 725a959..569df9a 100644 --- a/tests/Unit/Jobs/UpdateSiteTest.php +++ b/tests/Unit/Jobs/UpdateSiteTest.php @@ -9,6 +9,7 @@ use App\RemoteSite\Responses\FinalizeUpdate; use App\RemoteSite\Responses\GetUpdate; use App\RemoteSite\Responses\HealthCheck; +use App\RemoteSite\Responses\Notification; use App\RemoteSite\Responses\PrepareUpdate; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\App; @@ -147,7 +148,8 @@ public function testJobWritesFailLogOnFailing() 'checkHealth' => $this->getHealthCheckMock(), 'getUpdate' => $this->getGetUpdateMock("1.0.1"), 'prepareUpdate' => $this->getPrepareUpdateMock(), - 'finalizeUpdate' => $this->getFinalizeUpdateMock(false) + 'finalizeUpdate' => $this->getFinalizeUpdateMock(false), + 'notificationFailed' => $this->getNotificationMock(true) ], [ 'result' => false, @@ -169,7 +171,8 @@ public function testJobWritesSuccessLogForSuccessfulJobs() 'checkHealth' => $this->getHealthCheckMock(), 'getUpdate' => $this->getGetUpdateMock("1.0.1"), 'prepareUpdate' => $this->getPrepareUpdateMock(), - 'finalizeUpdate' => $this->getFinalizeUpdateMock(true) + 'finalizeUpdate' => $this->getFinalizeUpdateMock(true), + 'notificationSuccess' => $this->getNotificationMock(true) ], [ 'result' => true, @@ -261,6 +264,13 @@ protected function getFinalizeUpdateMock(bool $success) ]); } + protected function getNotificationMock(bool $success) + { + return Notification::from([ + "success" => $success + ]); + } + protected function getPrepareUpdateMock($overrides = []) { $defaults = [ From 4bb85cebe7cb8198d37a907d1ea65f8b17defe16 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 13 May 2025 10:39:07 +0200 Subject: [PATCH 3/3] fix stan --- app/RemoteSite/WebserviceEndpoint.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/RemoteSite/WebserviceEndpoint.php b/app/RemoteSite/WebserviceEndpoint.php index 9abe6be..c5063d2 100644 --- a/app/RemoteSite/WebserviceEndpoint.php +++ b/app/RemoteSite/WebserviceEndpoint.php @@ -51,6 +51,8 @@ public function getResponseClass(): string case self::notificationFailed->name: return Notification::class; } + + throw new \ValueError("No response defined"); } public function getUrl(): string