PluginProbe
Disk Usage Insights / 1.9
Disk Usage Insights v1.9
trunk 1.0 1.10 1.11 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
← All changes | src/Plugin.php +29 -11 1.21.9 View file →
@@ -2,16 +2,18 @@
2 2 namespace Mgleis\DiskUsageInsights;
3 3
4 4 use Mgleis\DiskUsageInsights\Frontend\Controller\DeleteSnapshotController;
5 5 use Mgleis\DiskUsageInsights\Frontend\Controller\IndexController;
6 -use Mgleis\DiskUsageInsights\Frontend\Controller\ResultsController;
7 6 use Mgleis\DiskUsageInsights\Frontend\Controller\ScanController;
8 7 use Mgleis\DiskUsageInsights\Frontend\Controller\ScanStatusController;
9 8 use Mgleis\DiskUsageInsights\Frontend\Controller\ScanWorkerController;
9 +use Mgleis\DiskUsageInsights\Frontend\Controller\ShowResultsController;
10 +use Mgleis\DiskUsageInsights\Frontend\Controller\ShowResultsTableController;
10 11 use Mgleis\DiskUsageInsights\Frontend\Controller\ShowSnapshotsController;
11 12
12 13 class Plugin {
13 14
15 + const TITLE = 'Disk Usage Insights';
14 16 const NONCE = 'disk_usage_insights';
15 17 /** @var string */
16 18 private $version = '';
17 19
@@ -34,10 +36,10 @@
34 36 // Add to Tools menue
35 37 add_action('admin_menu', function () {
36 38 add_submenu_page(
37 39 'tools.php',
38 - 'Disk Usage Insights',
39 - 'Disk Usage Insights',
40 + self::TITLE,
41 + self::TITLE,
40 42 'administrator',
41 43 'disk-usage-insights',
42 44 [$this, 'index']
43 45 );
@@ -49,15 +51,31 @@
49 51 // Add JavaScript libs + CSS
50 52 add_action('admin_enqueue_scripts', [$this, 'addScripts']);
51 53
52 54 // Add AJAX
53 - add_action('wp_ajax_dui_scan', function() { (new ScanController())->scan(); });
54 - add_action('wp_ajax_dui_worker', function() { (new ScanWorkerController())->worker(); });
55 - add_action('wp_ajax_dui_status', function() { (new ScanStatusController())->status(); });
56 - add_action('wp_ajax_dui_delete_snapshot', function() { (new DeleteSnapshotController())->delete(); });
57 - add_action('wp_ajax_dui_list_snapshots', function() { (new ShowSnapshotsController())->execute(); });
55 + add_action('wp_ajax_dui_scan', $this->wrapErrors(function() { (new ScanController())->scan(); }));
56 + add_action('wp_ajax_dui_worker', $this->wrapErrors(function() { (new ScanWorkerController())->worker(); }));
57 + add_action('wp_ajax_dui_status', $this->wrapErrors(function() { (new ScanStatusController())->status(); }));
58 + add_action('wp_ajax_dui_delete_snapshot', $this->wrapErrors(function() { (new DeleteSnapshotController())->delete(); }));
59 + add_action('wp_ajax_dui_list_snapshots', $this->wrapErrors(function() { (new ShowSnapshotsController())->execute(); }));
60 + add_action('wp_ajax_dui_results_table', $this->wrapErrors(function() { (new ShowResultsTableController())->execute(); }));
58 61 }
59 62
63 + public function wrapErrors(callable $fn) {
64 + return function() use ($fn) {
65 + try {
66 + return $fn();
67 + } catch (\Throwable $e) {
68 + status_header(500, 'Interner Fehler');
69 + //echo 'Fehler: Interner Serverfehler.';
70 + echo "\n\n";
71 + echo $e->getMessage();
72 + echo $e->getTraceAsString();
73 + wp_die();
74 + }
75 + };
76 + }
77 +
60 78 public function addScripts($hook_suffix) {
61 79 if ($hook_suffix != 'tools_page_disk-usage-insights') {
62 80 return;
63 81 }
@@ -86,12 +104,12 @@
86 104 $admin_bar->add_menu(array(
87 105 'id' => 'menu-id',
88 106 'parent' => null,
89 107 'group' => null,
90 - 'title' => '<img src="' . WpHelper::getPluginUrl() . '/res/pie.svg" style="margin-top:5px; width:20px" alt="Disk Usage Insights">',
108 + 'title' => '<img src="' . WpHelper::getPluginUrl() . '/res/pie.svg" style="margin-top:5px; width:20px" alt="'. self::TITLE .'">',
91 109 'href' => admin_url('tools.php?page=disk-usage-insights'),
92 110 'meta' => [
93 - 'title' => 'Disk Usage Insights'
111 + 'title' => self::TITLE
94 112 ]
95 113 ));
96 114 }
97 115
@@ -98,9 +116,9 @@
98 116 public function index() {
99 117 if (!isset($_GET['snapshot'])) {
100 118 return (new IndexController())->execute();
101 119 } else {
102 - return (new ResultsController())->execute();
120 + return (new ShowResultsController())->execute();
103 121 }
104 122 }
105 123
106 124 }