*/ public function get(): array { $value = get_option(self::OPTION, []); return is_array($value) ? $value : []; } /** @param array $run */ public function record(array $run): void { $run += ['time' => time()]; $success = ($run['outcome'] ?? '') === 'ok' ? (int) $run['time'] : (int) $this->success(); if ($success > 0) { $run['success'] = $success; } update_option(self::OPTION, $run, false); } /** * When a backup last worked, or null when none ever has. A row written by * 1.0.0 has no `success`; when its own run was a good one, that run's time * is the answer. */ public function success(): ?int { $last = $this->get(); $at = (int) ($last['success'] ?? 0); if ($at <= 0 && ($last['outcome'] ?? '') === 'ok') { $at = (int) ($last['time'] ?? 0); } return $at > 0 ? $at : null; } /** The message an admin notice should carry, or null when the last run is nothing to worry about. */ public function problem(): ?string { $last = $this->get(); return in_array($last['outcome'] ?? '', ['failed', 'refused', 'kept'], true) ? (string) ($last['message'] ?? '') : null; } }