# disk-usage-insights/1.9/src/Domain/DatabaseRepository.php

Disk Usage Insights, version 1.9. 48 lines.

- Page: https://pluginprobe.com/plugins/disk-usage-insights/1.9/code/src/Domain/DatabaseRepository.php
- Raw: https://pluginprobe.com/plugins/disk-usage-insights/1.9/raw/src/Domain/DatabaseRepository.php
- Modified: 2025-11-18T12:28:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/disk-usage-insights/1.9/code/src/Domain/DatabaseRepository.php#L10-L20`.

```php
<?php

namespace Mgleis\DiskUsageInsights\Domain;

use Mgleis\PhpSqliteJobQueue\Queue;

class DatabaseRepository {

    private const OUTPUT_DIR = __DIR__ . '/../../output';

    public function listDatabases(): array {

        $dir = realpath(self::OUTPUT_DIR);
        $pattern = $dir . '/*.db';
        $files = glob($pattern);
        rsort($files);
        $results = [];
        foreach ($files as $file) {
            $results[] = [
                'filename' => substr(basename($file), 0, strlen(basename($file)) - 3),
                'filesize' => filesize($file)
            ];
        }
        return $results;
    }

    public function loadDatabase(string $databaseName): Database {
        // TODO verify $databaseName
        $dir = realpath(self::OUTPUT_DIR);
        $file = $dir . '/' . $databaseName . '.db';

        $db = new Database();
        $db->q = new Queue($file);
        $db->fileEntryRepository = new FileEntryRepository($db->q->db);
        $db->snapshotRepository = new SnapshotRepository($db->q->db);

        return $db;
    }

    public function deleteDatabase(string $databaseName) {
        // TODO verify $databaseName
        $dir = realpath(self::OUTPUT_DIR);
        $file = $dir . '/' . $databaseName . '.db';
        $success = wp_delete_file($file);
    }

}

```
