diff --git a/app/Abstracts/Listeners/Update.php b/app/Abstracts/Listeners/Update.php index 15da794dc..6b32efe80 100644 --- a/app/Abstracts/Listeners/Update.php +++ b/app/Abstracts/Listeners/Update.php @@ -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); } /** diff --git a/app/Jobs/Install/FinishUpdate.php b/app/Jobs/Install/FinishUpdate.php index 2a374e67e..dfde982e9 100644 --- a/app/Jobs/Install/FinishUpdate.php +++ b/app/Jobs/Install/FinishUpdate.php @@ -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; } diff --git a/app/Utilities/Versions.php b/app/Utilities/Versions.php index 6a0ac06bf..fb0bb8588 100644 --- a/app/Utilities/Versions.php +++ b/app/Utilities/Versions.php @@ -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; + } }