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

Disk Usage Insights, version trunk. 64 lines.

- Page: https://pluginprobe.com/plugins/disk-usage-insights/trunk/code/src/Frontend/Controller/ScanStatusController.php
- Raw: https://pluginprobe.com/plugins/disk-usage-insights/trunk/raw/src/Frontend/Controller/ScanStatusController.php
- Modified: 2026-06-26T07:10:40+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/trunk/code/src/Frontend/Controller/ScanStatusController.php#L10-L20`.

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

use Mgleis\DiskUsageInsights\Domain\DatabaseRepository;
use Mgleis\DiskUsageInsights\Domain\Jobs\PhaseCoordinatorJob;
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;
        }
        $currentPhase = $_snapshot->phase;

        echo "<br>\n";
        foreach(PhaseCoordinatorJob::PHASES as $idx => $phaseText) {

            $phaseStatus = $currentPhase > $idx ? '✓ ' : '';
            $taskDescription = '';

            if ($currentPhase == $idx) {

                $job = $database->q->peek();
                if ($job !== null) {
                    $reflect = new \ReflectionClass($job->payload['type']);
                    $instance = $reflect->newInstanceArgs($job->payload['args']);

                    $taskDescription = ' -- ' . $instance->toDescription();
                }

            }
            if ($idx == $currentPhase) {
                echo "<b>";
            }
            echo sprintf('%s%s%s', esc_html($phaseStatus), esc_html($phaseText), esc_html($taskDescription));
            if ($idx == $currentPhase) {
                echo "</b>";
            }
            echo "<br>\n";
        }

        // debug counter
        $counter = (int) sanitize_text_field(wp_unslash($_POST['counter'] ?? 0));
        $counter++;
        echo '<input type="hidden" name="counter" value="' . esc_attr($counter) . '">';
        echo "<br>\nRunning for " . esc_html($counter) . " seconds...<br>\n";

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

}

```
