dont update newer versions

This commit is contained in:
Denis Duliçi 2022-03-02 12:02:34 +03:00
parent 2c86535d44
commit ea4a968f0f
3 changed files with 20 additions and 8 deletions

View File

@ -2,6 +2,8 @@
namespace App\Abstracts\Listeners;
use App\Utilities\Versions;
abstract class Update
{
const ALIAS = '';
@ -21,12 +23,7 @@ abstract class Update
return true;
}
// Do not apply to the same or newer versions
if (version_compare($event->old, static::VERSION, '>=')) {
return true;
}
return false;
return Versions::shouldUpdate(static::VERSION, $event->old, $event->new);
}
/**

View File

@ -7,6 +7,7 @@ use App\Interfaces\Listener\ShouldUpdateAllCompanies;
use App\Models\Module\Module;
use App\Traits\Modules;
use App\Utilities\Console;
use App\Utilities\Versions;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
@ -114,8 +115,7 @@ class FinishUpdate extends Job
// Thank you PSR-4
$class = '\Modules\\' . $module->getStudlyName() . str_replace('/', '\\', $path);
// Skip if listener is same or lower than old version
if (version_compare($class::VERSION, $this->old, '<=')) {
if (! Versions::shouldUpdate($class::VERSION, $this->old, $this->new)) {
continue;
}

View File

@ -157,4 +157,19 @@ class Versions
return $updates;
}
public static function shouldUpdate($listener_version, $old_version, $new_version): bool
{
// Don't update if "listener" is same or lower than "old" version
if (version_compare($listener_version, $old_version, '<=')) {
return false;
}
// Don't update if "listener" is higher than "new" version
if (version_compare($listener_version, $new_version, '>')) {
return false;
}
return true;
}
}