| 1 |
<?php |
| 2 |
namespace Mgleis\DiskUsageInsights\Frontend\Controller; |
| 3 |
|
| 4 |
use Mgleis\DiskUsageInsights\Domain\Collect\ScanDirForSubDirsJob; |
| 5 |
use Mgleis\DiskUsageInsights\Domain\DatabaseRepository; |
| 6 |
use Mgleis\DiskUsageInsights\Domain\FileEntry; |
| 7 |
use Mgleis\DiskUsageInsights\Plugin; |
| 8 |
use Mgleis\DiskUsageInsights\WpHelper; |
| 9 |
|
| 10 |
class ScanController { |
| 11 |
|
| 12 |
|
| 13 |
public function scan() { |
| 14 |
check_ajax_referer(Plugin::NONCE); |
| 15 |
|
| 16 |
// Create a new Snapshot Database |
| 17 |
$snapshotName = gmdate('Ymd_His_') . random_int(10000, 99999); |
| 18 |
$database = (new DatabaseRepository())->loadDatabase($snapshotName); |
| 19 |
$snapshot = $database->snapshotRepository->load(); |
| 20 |
$snapshot->root = rtrim(ABSPATH, '/'); |
| 21 |
$database->snapshotRepository->save($snapshot); |
| 22 |
|
| 23 |
// create root entry "" |
| 24 |
$rootFileEntry = new FileEntry(); |
| 25 |
$rootFileEntry->type = FileEntry::TYPE_DIR; |
| 26 |
$database->fileEntryRepository->createOrUpdate($rootFileEntry); |
| 27 |
|
| 28 |
$database->q->push((new ScanDirForSubDirsJob($rootFileEntry->id))->toArray()); |
| 29 |
|
| 30 |
// NEW Code |
| 31 |
$WP_NONCE = wp_create_nonce(Plugin::NONCE); |
| 32 |
$WP_ADMIN_AJAX_URL = admin_url('admin-ajax.php'); |
| 33 |
$WP_SNAPSHOT_FILE = $snapshotName; |
| 34 |
$WP_PLUGIN_URL = WpHelper::getPluginUrl(); |
| 35 |
|
| 36 |
include_once __DIR__ . '/../../../views/scan.php'; |
| 37 |
|
| 38 |
wp_die(); // All ajax handlers should die when finished |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|