PluginProbe
Disk Usage Insights / 1.5
Disk Usage Insights v1.5
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 / Frontend / Controller / ScanStatusController.php

ScanStatusController.php in Disk Usage Insights 1.5, at src/Frontend/Controller/ScanStatusController.php

41 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Mgleis\DiskUsageInsights\Frontend\Controller;
3
4 use Mgleis\DiskUsageInsights\Domain\DatabaseRepository;
5 use Mgleis\DiskUsageInsights\Plugin;
6
7 class ScanStatusController {
8
9 public function status() {
10 check_ajax_referer(Plugin::NONCE);
11
12 // TODO validate value: ensure file exists in data directory
13 $snapshotName = sanitize_file_name(wp_unslash($_POST['snapshot'] ?? ''));
14
15 $database = (new DatabaseRepository())->loadDatabase($snapshotName);
16
17 // if process finished = stop reloading
18 $_snapshot = $database->snapshotRepository->load();
19 if ($_snapshot->collectPhaseFinished === 1) {
20 http_response_code(286); // htmx stops timer
21 header('HX-Redirect: ' . admin_url('tools.php?page=disk-usage-insights&snapshot=' . $snapshotName));
22 exit;
23 }
24
25 $job = $database->q->top();
26 if ($job !== null) {
27
28 $reflect = new \ReflectionClass($job->payload['type']);
29 $instance = $reflect->newInstanceArgs($job->payload['args']);
30 echo sprintf('Phase %s / %s<br>%s',
31 $_snapshot->phase + 1,
32 10,
33 $instance->toDescription()
34 );
35 }
36
37 wp_die(); // All ajax handlers should die when finished
38 }
39
40 }
41