PluginProbe
Disk Usage Insights / trunk
Disk Usage Insights vtrunk
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 trunk, at src/Domain/DatabaseRepository.php

48 lines 1.3 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 private const OUTPUT_DIR = __DIR__ . '/../../output';
10
11 public function listDatabases(): array {
12
13 $dir = realpath(self::OUTPUT_DIR);
14 $pattern = $dir . '/*.db';
15 $files = glob($pattern);
16 rsort($files);
17 $results = [];
18 foreach ($files as $file) {
19 $results[] = [
20 'filename' => substr(basename($file), 0, strlen(basename($file)) - 3),
21 'filesize' => filesize($file)
22 ];
23 }
24 return $results;
25 }
26
27 public function loadDatabase(string $databaseName): Database {
28 // TODO verify $databaseName
29 $dir = realpath(self::OUTPUT_DIR);
30 $file = $dir . '/' . $databaseName . '.db';
31
32 $db = new Database();
33 $db->q = new Queue($file);
34 $db->fileEntryRepository = new FileEntryRepository($db->q->db);
35 $db->snapshotRepository = new SnapshotRepository($db->q->db);
36
37 return $db;
38 }
39
40 public function deleteDatabase(string $databaseName) {
41 // TODO verify $databaseName
42 $dir = realpath(self::OUTPUT_DIR);
43 $file = $dir . '/' . $databaseName . '.db';
44 $success = wp_delete_file($file);
45 }
46
47 }
48