# disk-usage-insights/1.2/src/Frontend/Controller/ScanStatusController.php

Disk Usage Insights, version 1.2. 41 lines.

- Page: https://pluginprobe.com/plugins/disk-usage-insights/1.2/code/src/Frontend/Controller/ScanStatusController.php
- Raw: https://pluginprobe.com/plugins/disk-usage-insights/1.2/raw/src/Frontend/Controller/ScanStatusController.php
- Modified: 2024-12-19T11:33:52+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.2/code/src/Frontend/Controller/ScanStatusController.php#L10-L20`.

```php
<?php
namespace Mgleis\DiskUsageInsights\Frontend\Controller;

use Mgleis\DiskUsageInsights\Domain\DatabaseRepository;
use Mgleis\DiskUsageInsights\Plugin;

class ScanStatusController {

    public function status() {
        check_ajax_referer(Plugin::NONCE);

        // TODO validate value: ensure file exists in data directory
        $snapshotName = sanitize_file_name(wp_unslash($_POST['snapshot'] ?? ''));

        $database = (new DatabaseRepository())->loadDatabase($snapshotName);

        // if process finished = stop reloading
        $_snapshot = $database->snapshotRepository->load();
        if ($_snapshot->collectPhaseFinished === 1) {
            http_response_code(286); // htmx stops timer
            header('HX-Redirect: ' . admin_url('tools.php?page=disk-usage-insights&snapshot=' . $snapshotName));
            exit;
        }

        $job = $database->q->top();
        if ($job !== null) {

            $reflect = new \ReflectionClass($job->payload['type']);
            $instance = $reflect->newInstanceArgs($job->payload['args']);
            echo sprintf('Phase %s / %s<br>%s',
                $_snapshot->phase + 1,
                10,
                $instance->toDescription()
            );
        }

        wp_die(); // All ajax handlers should die when finished
    }

}

```
