option('before')) ? null : CarbonImmutable::parse((string) $this->option('before')); } catch (Throwable) { $before = null; } if ($before === null) { $this->error('Bitte --before mit einem gültigen Zeitpunkt angeben.'); return self::FAILURE; } $apply = (bool) $this->option('apply'); $rows = []; foreach (Page::query()->whereNotNull('published_revision_id')->with('publishedRevision')->orderBy('path')->get() as $page) { $current = $page->publishedRevision; if ($current === null || $current->created_at < $before) { continue; } $previous = PageRevision::query() ->where('page_id', $page->id) ->where('created_at', '<', $before) ->latest('id') ->first(); if ($previous === null) { $rows[] = [$page->path, $current->id, '–', 'keine ältere Revision: Seite wird zurückgezogen']; if ($apply) { $page->published_revision_id = null; $page->save(); } continue; } $rows[] = [$page->path, $current->id, $previous->id, $apply ? 'zurückgesetzt' : 'würde zurückgesetzt']; if ($apply) { $page->published_revision_id = $previous->id; $page->save(); } } if ($rows === []) { $this->info('Keine veröffentlichte Seite stammt aus der Zeit ab '.$before->format('d.m.Y H:i').'.'); return self::SUCCESS; } $this->table(['Pfad', 'veröffentlicht', 'neu veröffentlicht', 'Ergebnis'], $rows); if (! $apply) { $this->warn('Probelauf. Mit --apply ausführen.'); } return self::SUCCESS; } }