PluginProbe
Disk Usage Insights / 1.3
Disk Usage Insights v1.3
trunk 1.0 1.10 1.11 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
disk-usage-insights / src / Domain / DatabaseRepository.php

DatabaseRepository.php in Disk Usage Insights 1.3, at src/Domain/DatabaseRepository.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Mgleis\DiskUsageInsights\Domain;
4
5 use Mgleis\PhpSqliteJobQueue\Queue;
6
7 class DatabaseRepository {
8
9 public function listDatabases(): array {
10
11 $dir = realpath(__DIR__ . '/../../output');
12 $pattern = $dir . '/*.db';
13 $files = glob($pattern);
14 rsort($files);
15 $results = [];
16 foreach ($files as $file) {
17 $results[] = [
18 'filename' => substr(basename($file), 0, strlen(basename($file)) - 3),
19 'filesize' => filesize($file)
20 ];
21 }
22 return $results;
23 }
24
25 public function loadDatabase(string $databaseName): Database {
26 // TODO verify $databaseName
27 $dir = realpath(__DIR__ . '/../../output');
28 $file = $dir . '/' . $databaseName . '.db';
29
30 $db = new Database();
31 $db->q = new Queue($file);
32 $db->fileEntryRepository = new FileEntryRepository($db->q->db);
33 $db->snapshotRepository = new SnapshotRepository($db->q->db);
34
35 return $db;
36 }
37
38 public function deleteDatabase(string $databaseName) {
39 // TODO verify $databaseName
40 $dir = realpath(__DIR__ . '/../../output');
41 $file = $dir . '/' . $databaseName . '.db';
42 $success = wp_delete_file($file);
43 }
44
45 }
46