Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/Jobs/UpdateSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions app/RemoteSite/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@
* @method GetUpdateResponse getUpdate()
* @method PrepareUpdateResponse prepareUpdate(array<string,string> $data)
* @method FinalizeUpdateResponse finalizeUpdate(array<string,string> $data)
* @method NotificationResponse notificationSuccess(array<string,string> $data)
* @method NotificationResponse notificationFailed(array<string,string> $data)
*/
class Connection
{
Expand Down
13 changes: 13 additions & 0 deletions app/RemoteSite/Responses/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\RemoteSite\Responses;

use App\DTO\BaseDTO;

class Notification extends BaseDTO implements ResponseInterface
{
public function __construct(
public bool $success
) {
}
}
10 changes: 10 additions & 0 deletions app/RemoteSite/WebserviceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
use App\RemoteSite\Responses\GetUpdate;
use App\RemoteSite\Responses\HealthCheck;
use App\RemoteSite\Responses\PrepareUpdate;
use App\RemoteSite\Responses\Notification;

enum WebserviceEndpoint: string
{
case checkHealth = "/api/index.php/v1/joomlaupdate/healthcheck";
case getUpdate = "/api/index.php/v1/joomlaupdate/getUpdate";
case prepareUpdate = "/api/index.php/v1/joomlaupdate/prepareUpdate";
case finalizeUpdate = "/api/index.php/v1/joomlaupdate/finalizeUpdate";
case notificationSuccess = "/api/index.php/v1/joomlaupdate/notificationSuccess";
case notificationFailed = "/api/index.php/v1/joomlaupdate/notificationFailed";

public function getMethod(): HttpMethod
{
Expand All @@ -25,6 +28,8 @@ public function getMethod(): HttpMethod
// no break
case self::prepareUpdate->name:
case self::finalizeUpdate->name:
case self::notificationSuccess->name:
case self::notificationFailed->name:
return HttpMethod::POST;
}

Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions tests/Unit/Jobs/UpdateSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -261,6 +264,13 @@ protected function getFinalizeUpdateMock(bool $success)
]);
}

protected function getNotificationMock(bool $success)
{
return Notification::from([
"success" => $success
]);
}

protected function getPrepareUpdateMock($overrides = [])
{
$defaults = [
Expand Down