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
6 changes: 6 additions & 0 deletions app/Console/Commands/PerformUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function handle(): int
/** @var Site $site */
$site = Site::findOrFail($this->input->getArgument('siteId'));

if (!$site->update_requirement_state) {
$this->output->writeln('Update requirements not met, aborting!');

return Command::FAILURE;
}

UpdateSite::dispatchSync(
$site,
$targetVersion
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/QueueUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function handle(): int
$this->output->writeln('Pushing update jobs');

$sites = Site::query()
->where('update_requirement_state', '=', true)
->where(
'cms_version',
'like',
Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/CheckSiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function handle(): void
$this->site->last_seen = Carbon::now();
$this->site->save();

// Check if conditions are met
if (!$this->site->update_requirement_state) {
return;
}

// Check if a newer Joomla version for that site is available
/** @var TufFetcher $tufFetcher */
$tufFetcher = App::make(TufFetcher::class);
Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/UpdateSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function handle(): void
return;
}

if (!$healthResult->update_requirement_state) {
Log::info("Site does not meet requirements, abort");

return;
}

// Do not make a major version update
$majorVersionCms = (int) $healthResult->cms_version;
$majorTargetVersion = (int) $this->targetVersion;
Expand Down
8 changes: 2 additions & 6 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class Site extends Model
'db_version',
'cms_version',
'server_os',
'update_patch',
'update_minor',
'update_major'
'update_requirement_state'
];

protected $hidden = [
Expand All @@ -33,9 +31,7 @@ protected function casts(): array
{
return [
'last_seen' => 'datetime',
'update_patch' => 'bool',
'update_minor' => 'bool',
'update_major' => 'bool'
'update_requirement_state' => 'bool',
];
}

Expand Down
3 changes: 2 additions & 1 deletion app/RemoteSite/Responses/HealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public function __construct(
public string $db_type,
public string $db_version,
public string $cms_version,
public string $server_os
public string $server_os,
public ?bool $update_requirement_state = null
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('sites', function (Blueprint $table) {
$table->boolean('update_requirement_state')->default(false)->nullable(true);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('sites', function (Blueprint $table) {
$table->dropColumn('update_requirement_state');
});
}
};
6 changes: 4 additions & 2 deletions tests/Feature/Api/SiteControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function testRegisteringASiteWithUrlAndKeyCreatesRow(): void
"db_type" => "mysqli",
"db_version" => "1.0.0",
"cms_version" => "1.0.0",
"server_os" => "Joomla OS 1.0.0"
"server_os" => "Joomla OS 1.0.0",
"update_requirement_state" => true
]));

$this->app->bind(Connection::class, fn () => $mock);
Expand Down Expand Up @@ -170,7 +171,8 @@ protected function createMockSiteInDb(): Site
"db_version" => "1.0.0",
"cms_version" => "1.0.0",
"server_os" => "Joomla OS 1.0.0",
"last_seen" => Carbon::now()
"last_seen" => Carbon::now(),
"update_requirement_state" => true
]);

$site->key = 'foobar123foobar123foobar123foobar123';
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Jobs/CheckSiteHealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function () use ($healthMock) {
$siteMock->id = 1;
$siteMock->url = "http://example.org";
$siteMock->cms_version = "1.0.0";
$siteMock->update_requirement_state = true;

return $siteMock;
}
Expand All @@ -95,7 +96,8 @@ protected function getHealthCheckMock($overrides = [])
"db_type" => "mysqli",
"db_version" => "1.0.0",
"cms_version" => "1.0.0",
"server_os" => "Joomla OS 1.0.0"
"server_os" => "Joomla OS 1.0.0",
"update_requirement_state" => true
];

return HealthCheck::from([
Expand Down
25 changes: 24 additions & 1 deletion tests/Unit/Jobs/UpdateSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public function testJobQuitsIfNoUpdateIsAvailable()
$this->assertTrue(true);
}

public function testJobQuitsIfRequirementsArentMet()
{
$site = $this->getSiteMock(
[
'checkHealth' => $this->getHealthCheckMock(['update_requirement_state' => false])
]
);

Log::spy();

$object = new UpdateSite($site, "1.0.1");
$object->handle();

Log::shouldHaveReceived('info')
->once()
->withArgs(function ($message) {
return str_contains($message, 'Site does not meet requirements, abort');
});

$this->assertTrue(true);
}

public function testJobQuitsIfWeDetectALoopForAVersion()
{
$site = $this->getSiteMock([], null, 6);
Expand Down Expand Up @@ -241,7 +263,8 @@ protected function getHealthCheckMock($overrides = [])
"db_type" => "mysqli",
"db_version" => "1.0.0",
"cms_version" => "1.0.0",
"server_os" => "Joomla OS 1.0.0"
"server_os" => "Joomla OS 1.0.0",
"update_requirement_state" => true
];

return HealthCheck::from([
Expand Down