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 / Domain / Collect / ScanDirForFilesJob.php

ScanDirForFilesJob.php in Disk Usage Insights 1.5, at src/Domain/Collect/ScanDirForFilesJob.php

60 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Mgleis\DiskUsageInsights\Domain\Collect;
4
5 use Mgleis\DiskUsageInsights\Domain\FileEntry;
6 use Mgleis\DiskUsageInsights\Domain\Jobs\BaseJob;
7
8 class ScanDirForFilesJob extends BaseJob {
9
10 private int $skip;
11 private int $count;
12 private int $totalCount;
13
14 public function __construct(int $skip, int $count, int $totalCount) {
15 $this->skip = $skip;
16 $this->count = $count;
17 $this->totalCount = $totalCount;
18 }
19
20 public function work() {
21
22 $dirEntries = $this->fileEntryRepository->get($this->skip, $this->count, FileEntry::TYPE_DIR);
23 $root = $this->snapshotRepository->load()->root;
24
25 foreach ($dirEntries as $dirEntry) {
26
27 $realDir = $this->fileEntryRepository->calcFullPath($dirEntry, $root);
28 //$this->log("Scanning " . $realDir . " for files...");
29
30 $files = scandir($realDir . '/');
31
32 foreach ($files as $file) {
33 if (!is_file($realDir . '/' . $file)) {
34 continue;
35 }
36
37 // persist file info
38 $fileEntry = new FileEntry();
39 $fileEntry->parent_id = $dirEntry->id;
40 $fileEntry->name = $file;
41 $fileEntry->type = FileEntry::TYPE_FILE;
42 $fileEntry->size = 0;
43 $this->fileEntryRepository->createOrUpdate($fileEntry);
44 }
45 }
46 }
47
48 public function toArray() {
49 return ['type' => self::class, 'args' => [$this->skip, $this->count, $this->totalCount]];
50 }
51
52 public function toDescription(): string {
53 $percent = $this->totalCount > 0
54 ? round(100 * $this->skip / $this->totalCount)
55 : '0';
56 return sprintf('Scanning dirs for files... %s%%', $percent);
57 }
58
59 }
60