File tree Expand file tree Collapse file tree 7 files changed +63
-19
lines changed Expand file tree Collapse file tree 7 files changed +63
-19
lines changed Original file line number Diff line number Diff line change 44
55enum WebserviceEndpoint: string
66{
7- case HEALTH_CHECK = "health.json " ;
7+ case HEALTH_CHECK = "/api/index.php/v1/updates/health " ;
8+ case FETCH_UPDATES = "/api/index.php/v1/updates/fetch " ;
9+ case PREPARE_UPDATE = "/api/index.php/v1/updates/prepare " ;
10+ case FINALIZE_UPDATE = "/api/index.php/v1/updates/finalize " ;
811}
Original file line number Diff line number Diff line change 55namespace App \Jobs ;
66
77use App \Models \Site ;
8- use App \ Services \ SiteConnectionService ;
8+ use app \ Remotesite \ Connection ;
99use Carbon \Carbon ;
1010use Illuminate \Contracts \Queue \ShouldQueue ;
1111use Illuminate \Foundation \Queue \Queueable ;
@@ -26,7 +26,7 @@ public function __construct(protected readonly Site $site)
2626 */
2727 public function handle (): void
2828 {
29- /** @var SiteConnectionService $connection */
29+ /** @var Connection $connection */
3030 $ connection = $ this ->site ->connection ;
3131
3232 $ response = $ connection ->checkHealth ();
Original file line number Diff line number Diff line change 44
55namespace App \Jobs ;
66
7+ use App \Models \Site ;
8+ use app \Remotesite \Connection ;
79use Illuminate \Contracts \Queue \ShouldQueue ;
810use Illuminate \Foundation \Queue \Queueable ;
911
@@ -14,16 +16,19 @@ class UpdateSite implements ShouldQueue
1416 /**
1517 * Create a new job instance.
1618 */
17- public function __construct ()
19+ public function __construct (protected readonly Site $ site , protected string $ targetVersion )
1820 {
19- //
2021 }
2122
2223 /**
2324 * Execute the job.
2425 */
2526 public function handle (): void
2627 {
27- //
28+ /** @var Connection $connection */
29+ $ connection = $ this ->site ->connection ;
30+
31+ // Test connection and get current version
32+ $ healthResult = $ connection ->checkHealth ();
2833 }
2934}
Original file line number Diff line number Diff line change 44
55namespace App \Models ;
66
7- use App \Services \ SiteConnectionService ;
7+ use App \Remotesite \ Connection ;
88use Illuminate \Database \Eloquent \Model ;
99
1010class Site extends Model
@@ -38,11 +38,11 @@ protected function casts(): array
3838
3939 public function getUrlAttribute (string $ value ): string
4040 {
41- return rtrim ($ value , "/ " ) . " / " ;
41+ return rtrim ($ value , "/ " );
4242 }
4343
44- public function getConnectionAttribute (): SiteConnectionService
44+ public function getConnectionAttribute (): Connection
4545 {
46- return new SiteConnectionService ($ this ->url , $ this ->key );
46+ return new Connection ($ this ->url , $ this ->key );
4747 }
4848}
Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5- namespace App \Services ;
5+ namespace App \RemoteSite ;
66
77use App \Enum \HttpMethod ;
88use App \Enum \WebserviceEndpoint ;
9+ use App \RemoteSite \Responses \HealthCheck ;
10+ use App \RemoteSite \Responses \HealthCheck as HealthCheckResponse ;
911use GuzzleHttp \Client ;
1012use GuzzleHttp \Exception \RequestException ;
1113use GuzzleHttp \Psr7 \Request ;
1214use GuzzleHttp \Psr7 \Response ;
1315use Illuminate \Support \Facades \App ;
1416use Psr \Http \Message \RequestInterface ;
1517
16- class SiteConnectionService
18+ class Connection
1719{
1820 public function __construct (protected readonly string $ baseUrl , protected readonly string $ key )
1921 {
2022 }
2123
22- public function checkHealth (): array
24+ public function checkHealth (): HealthCheck
2325 {
2426 $ healthData = $ this ->performWebserviceRequest (
2527 HttpMethod::GET ,
2628 WebserviceEndpoint::HEALTH_CHECK
2729 );
2830
29- // Perform a sanity check
30- if (empty ($ healthData ['cms_version ' ])) {
31- throw new \Exception ("Invalid health response content " );
32- }
33-
34- return $ healthData ;
31+ return HealthCheckResponse::from ($ healthData );
3532 }
3633
3734 public function performExtractionRequest (array $ data ): array
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \RemoteSite \Responses ;
4+
5+ abstract class BaseResponse
6+ {
7+ public static function from (array $ data ): self
8+ {
9+ $ reflect = new \ReflectionClass (static ::class);
10+ $ properties = $ reflect ->getProperties (\ReflectionProperty::IS_PUBLIC );
11+
12+ $ arguments = [];
13+
14+ foreach ($ properties as $ property ) {
15+ if (!array_key_exists ($ property ->name , $ data )) {
16+ continue ;
17+ }
18+
19+ $ arguments [$ property ->name ] = $ data [$ property ->name ];
20+ }
21+
22+ return $ reflect ->newInstanceArgs ($ arguments );
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \RemoteSite \Responses ;
4+
5+ class HealthCheck extends BaseResponse
6+ {
7+ public function __construct (
8+ public string $ php_version ,
9+ public string $ db_type ,
10+ public string $ db_version ,
11+ public string $ cms_version ,
12+ public string $ server_os
13+ ) {
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments