42 lines
1.4 KiB
PHP
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;
|
|
}
|
|
}
|