Skip to content

Commit

Permalink
Improves update check in case dbs have to be downgraded.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Aug 23, 2024
1 parent 0538d68 commit d58e164
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/Core/Middleware/Updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public function handle(IncomingRequest $request, Closure $next): Response
session(["dbVersion" => $dbVersion]);
}

session(["isUpdated" => $dbVersion == $settingsDbVersion]);
$dbVersionInt = $this->getVersionInt($dbVersion);
$settingsDbVersionInt = $this->getVersionInt($settingsDbVersion);

session(["isUpdated" => $dbVersionInt >= $settingsDbVersionInt]);

if (session("isUpdated")) {
return $next($request);
Expand Down Expand Up @@ -64,4 +67,17 @@ private function redirectToUpdate(): Response|false
$route = self::dispatch_filter("redirectroute", $route);
return $frontController::redirect($route);
}

private function getVersionInt($version)
{
$versionArray = explode(".", $version);
if (is_array($versionArray) && count($versionArray) == 3) {
$major = $versionArray[0];
$minor = str_pad($versionArray[1], 2, "0", STR_PAD_LEFT);
$patch = str_pad($versionArray[2], 2, "0", STR_PAD_LEFT);
$newDBVersion = $major . $minor . $patch;
return $newDBVersion;
}
return false;
}
}

0 comments on commit d58e164

Please sign in to comment.