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,7 +47,12 @@ 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; } + + throw new \ValueError("No response defined"); } public function getUrl(): string 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 = [