backup = $backup ?? static fn (WP_Post $post): int => (new PostCloner())->backup($post); $this->trashEnabled = $trashEnabled ?? static fn (): bool => ! defined('EMPTY_TRASH_DAYS') || (bool) EMPTY_TRASH_DAYS; } /** * Ruling P9: a backup (only made when revisions are off) must be faithful and must survive. $label * names the entry in the message ("Bibliothekseintrag 12"), $hint says what to do instead. */ public function backupRefusal(WP_Post $post, string $label, string $hint): ?WP_Error { if (wp_revisions_enabled($post)) { return null; } if (! current_user_can('unfiltered_html')) { return Errors::unsupported( sprintf( 'Revisionen sind für %s abgeschaltet, und die Sicherungskopie wäre für dieses Konto nicht ' . 'verlustfrei (WordPress filtert HTML); nichts wurde gespeichert.', $label ), $hint ); } if (! ($this->trashEnabled)()) { return Errors::unsupported( sprintf( 'Revisionen sind für %s abgeschaltet, und der Papierkorb ist deaktiviert (EMPTY_TRASH_DAYS = 0) ' . '– die Sicherungskopie würde sofort gelöscht; nichts wurde gespeichert.', $label ), $hint ); } return null; } /** * The backup of $post when revisions are off for it (call backupRefusal() first): ['backup_id' => …], * else nothing – the revision DiviSaver takes is the restore point. * * @return array{backup_id?: int} * @throws WriteFailed When the backup could not be made (nothing was saved). */ public function backup(WP_Post $post): array { return wp_revisions_enabled($post) ? [] : ['backup_id' => ($this->backup)($post)]; } /** * A tool's own confirm_required $error extended by $note (appended to its message) and $details (the * entry's answer fields), keeping the tool's own fields. * * @param array $details */ public static function merged(WP_Error $error, string $note, array $details): WP_Error { $data = $error->get_error_data(); $own = is_array($data) ? array_diff_key($data, ['status' => true, 'hint' => true]) : []; return Errors::confirmRequired(Errors::clientMessage($error) . ' ' . $note, array_merge($own, $details)); } /** * Ruling P14: a backup was made (revisions off) before the save failed – the error names it, because it * stays in the trash and is the only earlier state. $entry names what it saved ("des Bibliothekseintrags"). */ public static function keepingBackup(WriteFailed $e, mixed $backupId, string $entry): WriteFailed { if (! is_int($backupId)) { return $e; } $kept = sprintf( 'Sicherung %d liegt im Papierkorb (vorheriger Stand %s, in WordPress wiederherstellbar).', $backupId, $entry ); if ($e->rolledBack) { return $e->withDetails( ['backup_id' => $backupId], $kept . ' Den Aufruf erst nach Prüfung mit lit-divi-outline wiederholen.', Errors::notSavedKeeping(sprintf('Sicherung %d im Papierkorb', $backupId)) ); } return $e->withDetails( ['backup_id' => $backupId], 'Den Aufruf nicht einfach wiederholen. ' . $kept . ' Zuerst den Stand mit lit-divi-outline prüfen und ' . 'dem Nutzer Bescheid geben.' ); } }