Skip to content

Commit f074ed5

Browse files
committed
Merge branch 'main' of github.com:joomla-projects/Automated-Updates-Server
2 parents f9b4508 + fe79ccf commit f074ed5

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

app/Jobs/UpdateSite.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public function handle(): void
110110
"Status code has changed after update for site: " . $this->site->id
111111
);
112112
}
113+
114+
// Notify users
115+
$connection->notificationSuccess(["fromVersion" => $healthResult->cms_version]);
113116
}
114117

115118
protected function performExtraction(PrepareUpdate $prepareResult): void
@@ -166,6 +169,12 @@ protected function performExtraction(PrepareUpdate $prepareResult): void
166169

167170
public function failed(\Exception $exception): void
168171
{
172+
/** @var Connection $connection */
173+
$connection = $this->site->connection;
174+
175+
// Notify users
176+
$connection->notificationFailed(["fromVersion" => $this->site->cms_version]);
177+
169178
// We log any issues during the update to the DB
170179
$this->site->updates()->create([
171180
'old_version' => $this->site->cms_version,

app/RemoteSite/Connection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\RemoteSite\Responses\GetUpdate as GetUpdateResponse;
1010
use App\RemoteSite\Responses\HealthCheck as HealthCheckResponse;
1111
use App\RemoteSite\Responses\PrepareUpdate as PrepareUpdateResponse;
12+
use App\RemoteSite\Responses\Notification as NotificationResponse;
1213
use App\RemoteSite\Responses\ResponseInterface;
1314
use GuzzleHttp\Client;
1415
use GuzzleHttp\Exception\RequestException;
@@ -22,6 +23,8 @@
2223
* @method GetUpdateResponse getUpdate()
2324
* @method PrepareUpdateResponse prepareUpdate(array<string,string> $data)
2425
* @method FinalizeUpdateResponse finalizeUpdate(array<string,string> $data)
26+
* @method NotificationResponse notificationSuccess(array<string,string> $data)
27+
* @method NotificationResponse notificationFailed(array<string,string> $data)
2528
*/
2629
class Connection
2730
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\RemoteSite\Responses;
4+
5+
use App\DTO\BaseDTO;
6+
7+
class Notification extends BaseDTO implements ResponseInterface
8+
{
9+
public function __construct(
10+
public bool $success
11+
) {
12+
}
13+
}

app/RemoteSite/WebserviceEndpoint.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
use App\RemoteSite\Responses\GetUpdate;
88
use App\RemoteSite\Responses\HealthCheck;
99
use App\RemoteSite\Responses\PrepareUpdate;
10+
use App\RemoteSite\Responses\Notification;
1011

1112
enum WebserviceEndpoint: string
1213
{
1314
case checkHealth = "/api/index.php/v1/joomlaupdate/healthcheck";
1415
case getUpdate = "/api/index.php/v1/joomlaupdate/getUpdate";
1516
case prepareUpdate = "/api/index.php/v1/joomlaupdate/prepareUpdate";
1617
case finalizeUpdate = "/api/index.php/v1/joomlaupdate/finalizeUpdate";
18+
case notificationSuccess = "/api/index.php/v1/joomlaupdate/notificationSuccess";
19+
case notificationFailed = "/api/index.php/v1/joomlaupdate/notificationFailed";
1720

1821
public function getMethod(): HttpMethod
1922
{
@@ -25,6 +28,8 @@ public function getMethod(): HttpMethod
2528
// no break
2629
case self::prepareUpdate->name:
2730
case self::finalizeUpdate->name:
31+
case self::notificationSuccess->name:
32+
case self::notificationFailed->name:
2833
return HttpMethod::POST;
2934
}
3035

@@ -42,7 +47,12 @@ public function getResponseClass(): string
4247
return PrepareUpdate::class;
4348
case self::finalizeUpdate->name:
4449
return FinalizeUpdate::class;
50+
case self::notificationSuccess->name:
51+
case self::notificationFailed->name:
52+
return Notification::class;
4553
}
54+
55+
throw new \ValueError("No response defined");
4656
}
4757

4858
public function getUrl(): string

tests/Unit/Jobs/UpdateSiteTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\RemoteSite\Responses\FinalizeUpdate;
1010
use App\RemoteSite\Responses\GetUpdate;
1111
use App\RemoteSite\Responses\HealthCheck;
12+
use App\RemoteSite\Responses\Notification;
1213
use App\RemoteSite\Responses\PrepareUpdate;
1314
use Illuminate\Database\Eloquent\Relations\HasMany;
1415
use Illuminate\Support\Facades\App;
@@ -147,7 +148,8 @@ public function testJobWritesFailLogOnFailing()
147148
'checkHealth' => $this->getHealthCheckMock(),
148149
'getUpdate' => $this->getGetUpdateMock("1.0.1"),
149150
'prepareUpdate' => $this->getPrepareUpdateMock(),
150-
'finalizeUpdate' => $this->getFinalizeUpdateMock(false)
151+
'finalizeUpdate' => $this->getFinalizeUpdateMock(false),
152+
'notificationFailed' => $this->getNotificationMock(true)
151153
],
152154
[
153155
'result' => false,
@@ -169,7 +171,8 @@ public function testJobWritesSuccessLogForSuccessfulJobs()
169171
'checkHealth' => $this->getHealthCheckMock(),
170172
'getUpdate' => $this->getGetUpdateMock("1.0.1"),
171173
'prepareUpdate' => $this->getPrepareUpdateMock(),
172-
'finalizeUpdate' => $this->getFinalizeUpdateMock(true)
174+
'finalizeUpdate' => $this->getFinalizeUpdateMock(true),
175+
'notificationSuccess' => $this->getNotificationMock(true)
173176
],
174177
[
175178
'result' => true,
@@ -261,6 +264,13 @@ protected function getFinalizeUpdateMock(bool $success)
261264
]);
262265
}
263266

267+
protected function getNotificationMock(bool $success)
268+
{
269+
return Notification::from([
270+
"success" => $success
271+
]);
272+
}
273+
264274
protected function getPrepareUpdateMock($overrides = [])
265275
{
266276
$defaults = [

0 commit comments

Comments
 (0)