Files
KantSites/src/Twig/VersionExtension.php
T
kantarci 3391fea58b
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s
Add visual button presets, jump targets and menu controls
2026-09-14 13:47:49 +02:00

42 lines
1.4 KiB
PHP

<?php
namespace App\Twig;
use App\Ops\Updater;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* The running version, for the administration shell.
*
* A function rather than a global, so the templates get exactly this one read-only answer and not
* a whole updater with an update() method on it.
*/
final class VersionExtension extends AbstractExtension
{
public function __construct(private Updater $updater, private \Doctrine\DBAL\Connection $db)
{
}
public function getFunctions(): array
{
return [new TwigFunction('kant_version', $this->updater->version(...)), new TwigFunction('kant_update_version', $this->available(...))];
}
public function available(): ?string
{
// The daily worker already checks releases. Rendering navigation never contacts Git.
try {
$message = $this->db->fetchOne('SELECT last_message FROM scheduled_task WHERE name = ?', ['update-check']);
if (is_string($message) && 1 === preg_match('/^Fassung (\d+\.\d+\.\d+) ist verfügbar/', $message, $match)
&& version_compare($match[1], $this->updater->version(), '>')) {
return $match[1];
}
} catch (\Doctrine\DBAL\Exception) {
// An installation still waiting for migrations has no task table yet.
}
return null;
}
}