Rebuild DEEG as a fifth installation, add stepped forms and a plugin system, and clear the review backlog
Forms gained steps, conditions, image choices, number fields with units and a summary step; the DEEG price finder uses all of it. Plugins are manifest plus Twig: blocks, settings, containers, routes, presets and theme packs, switched per installation. The review backlog is done: archive pages render through the normal page pipeline, forms and post lists work inside areas and sections, repeated sections get their own ids, breakpoints and colours come from the palette, backup and update work on MySQL and lock each other out. The task worker no longer shortens a process that has no time limit: set_time_limit() sets the limit instead of extending it, which turned an unlimited CLI run into eighty seconds and killed the full test suite far away from the scheduler. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66ff68abf8
commit
c8a8fa7460
74 files changed
+5352
-243
No files matched your search
+70
-1
@@ -24,15 +24,46 @@ final class Updater
|
||||
public const MAINTENANCE_FILE = 'var/maintenance';
|
||||
public const LOG_FILE = 'var/updates.log';
|
||||
|
||||
/** Eine Datei, die waehrend eines Updates gesperrt ist - Git-Weg und Archiv-Weg teilen sie sich. */
|
||||
public const LOCK_FILE = 'var/update.lock';
|
||||
|
||||
/** Der Name der Sicherung, die vor dem Update entstand - der Rueckweg spielt sie ein. */
|
||||
private ?string $backupName = null;
|
||||
|
||||
public function __construct(
|
||||
private string $root,
|
||||
private string $databaseUrl,
|
||||
private CommandRunner $runner,
|
||||
private Connection $db,
|
||||
private ?string $php = null,
|
||||
private ?Backup $backups = null,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sperrt Updates gegeneinander. Zwei Klicks auf "Aktualisieren", ein Cronjob neben der
|
||||
* Verwaltung, der Archiv-Weg neben dem Git-Weg: jeder zweite Lauf bekommt null und faengt
|
||||
* nichts an. Die Sperre faellt mit dem Handle, also spaetestens mit dem Prozess.
|
||||
*
|
||||
* @return resource|null
|
||||
*/
|
||||
public function lock(): mixed
|
||||
{
|
||||
$file = $this->root.'/'.self::LOCK_FILE;
|
||||
@mkdir(dirname($file), 0o775, true);
|
||||
$handle = @fopen($file, 'c');
|
||||
if (!is_resource($handle)) {
|
||||
return null;
|
||||
}
|
||||
if (!flock($handle, LOCK_EX | LOCK_NB)) {
|
||||
fclose($handle);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $handle;
|
||||
}
|
||||
|
||||
/** The version that is installed, from the file that ships inside the tag. */
|
||||
public function version(): string
|
||||
{
|
||||
@@ -224,6 +255,21 @@ final class Updater
|
||||
}
|
||||
|
||||
// ---- from here on the installation is being changed ----
|
||||
$lock = $this->lock();
|
||||
if (!$step($steps, 'Sperre', null !== $lock, null !== $lock ? 'Kein anderes Update läuft.' : 'Ein anderes Update läuft gerade (var/update.lock). Bitte warten.')) {
|
||||
return ['ok' => false, 'steps' => $steps, 'target' => $target];
|
||||
}
|
||||
try {
|
||||
return $this->apply($steps, $step, $target, $from, $lockBefore);
|
||||
} finally {
|
||||
flock($lock, LOCK_UN);
|
||||
fclose($lock);
|
||||
}
|
||||
}
|
||||
|
||||
/** Der Teil des Updates, der die Installation veraendert - unter der Sperre. */
|
||||
private function apply(array &$steps, callable $step, string $target, string $from, string $lockBefore): array
|
||||
{
|
||||
$backup = $this->backup();
|
||||
if (!$step($steps, 'Sicherung', null !== $backup, $backup ?? 'Die Datenbank ließ sich nicht sichern. Ohne Sicherung wird nicht aktualisiert.')) {
|
||||
return ['ok' => false, 'steps' => $steps, 'target' => $target];
|
||||
@@ -350,7 +396,19 @@ final class Updater
|
||||
}
|
||||
$step($steps, 'Zurück auf den alten Stand', $back['ok'], $back['ok'] ? 'Auf '.substr($commit, 0, 8).' zurückgesetzt.' : $back['output']);
|
||||
|
||||
if (null !== $backup && null !== $this->databaseFile()) {
|
||||
if (null !== $backup && null !== $this->backupName && null !== $this->backups) {
|
||||
// Ueber die Sicherung, nicht ueber eine rohe Kopie: derselbe konsistente Weg fuer
|
||||
// SQLite (VACUUM INTO) und MySQL (Dump und Client).
|
||||
$restored = $this->backups->restore($this->backupName, true)['ok'];
|
||||
$step($steps, 'Datenbank zurückschreiben', $restored, $restored
|
||||
? 'Die Sicherung von vor der Migration ist wieder eingespielt.'
|
||||
: 'Die Sicherung ließ sich nicht zurückschreiben. Sie liegt unter var/backups/'.$this->backupName.'.');
|
||||
if (!$restored) {
|
||||
$step($steps, 'Wartungszustand bleibt', false, 'Die Datenbank konnte nicht wiederhergestellt werden. Der Betrieb bleibt angehalten.');
|
||||
|
||||
return;
|
||||
}
|
||||
} elseif (null !== $backup && null !== $this->databaseFile()) {
|
||||
$file = $this->databaseFile();
|
||||
$copy = $this->backupDirectory.'/'.basename((string) $file);
|
||||
$restored = is_readable($copy) && @copy($copy, (string) $file);
|
||||
@@ -398,6 +456,17 @@ final class Updater
|
||||
private function backup(): ?string
|
||||
{
|
||||
$this->backupDirectory = null;
|
||||
$this->backupName = null;
|
||||
if (null !== $this->backups) {
|
||||
try {
|
||||
$sicherung = $this->backups->create('vor dem Update');
|
||||
$this->backupName = $sicherung['name'];
|
||||
|
||||
return sprintf('var/backups/%s (Datenbank %s, Medien %d Datei(en)).', $sicherung['name'], $this->bytes((int) ($sicherung['manifest']['datenbank']['bytes'] ?? 0)), (int) ($sicherung['manifest']['medien']['dateien'] ?? 0));
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$directory = $this->root.'/var/backups/update-'.gmdate('Ymd-His').'-'.bin2hex(random_bytes(4));
|
||||
if (!@mkdir($directory, 0o700, true)) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user