jobs = $jobs; $this->swap = $swap; $this->db = $db; } public function list(): array { $out = []; foreach ($this->jobs->with_restore_points() as $job) { $tables = array_keys($job->restore_point['tables'] ?? []); $status = $this->db->table_status(array_values($job->restore_point['tables'] ?? [])); $out[] = [ 'job_id' => $job->id, 'type' => $job->type, 'created_at' => $job->created_at, 'finished_at' => $job->finished_at, 'tables' => $tables, 'bytes' => array_sum(array_column($status, 'bytes')), 'files' => !empty($job->restore_point['files']), ]; } return $out; } public function prune(int $keep): void { foreach (array_slice($this->jobs->with_restore_points(), max(0, $keep)) as $job) { $this->delete($job); } } public function delete(Job $job): void { if ($job->restore_point === null || !empty($job->restore_point['pruned'])) { return; } $this->swap->drop($job->restore_point); if (!empty($job->restore_point['users'])) { $this->db->raw('DROP TABLE IF EXISTS ' . Db::ident((string) $job->restore_point['users'])); } if (!empty($job->restore_point['files'])) { PointArchive::discard($job->restore_point['files']); } $job->restore_point['pruned'] = true; $this->jobs->save($job); } }