backups = $backups ?? new WpBackupRepository(); $this->storage = $storage ?? new WpObjectStorage(); $this->logger = $logger ?? new WpLogger(); } /** * @return bool true when the object exists and matches the recorded size */ public function verify(int $backupId): bool { $backup = $this->backups->findById($backupId); if (!$backup || empty($backup->cloud_path)) { $this->logger->log('warning', 'backup', "Cannot verify backup #{$backupId}: no cloud path recorded"); return false; } $result = (new ArchiveVerifier($this->storage))->verify( (string) $backup->cloud_path, (int) ($backup->file_size_bytes ?? 0) ); // Only a PROVEN mismatch condemns the backup. An inconclusive result means the // storage did not answer — marking the record failed on that would destroy a // perfectly good restore point over a network hiccup. if ($result->isCorrupt()) { $this->logger->log('error', 'backup', "Backup #{$backupId} verification failed: {$result->reason}"); $this->backups->markVerificationFailed($backupId, (string) $result->reason); return false; } if ($result->isInconclusive()) { $this->logger->log('warning', 'backup', "Backup #{$backupId} non vérifié : {$result->reason}"); return false; } $this->logger->log('info', 'backup', "Backup #{$backupId} vérifié ({$result->sizeBytes} octets)"); return true; } }