PluginProbe
Disk Usage Insights / trunk
Disk Usage Insights vtrunk
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 / DetermineFileSizesJob.php

DetermineFileSizesJob.php in Disk Usage Insights trunk, at src/Domain/Collect/DetermineFileSizesJob.php

43 lines 1.2 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 DetermineFileSizesJob 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 $this->log(self::class);
22 $fileEntries = $this->fileEntryRepository->get($this->skip, $this->count, FileEntry::TYPE_FILE);
23
24 $root = $this->snapshotRepository->load()->root;
25 foreach ($fileEntries as $fileEntry) {
26
27 $absoluteFilename = $this->fileEntryRepository->calcFullPath($fileEntry, $root);
28
29 $fileEntry->size = filesize($absoluteFilename);
30 $this->fileEntryRepository->createOrUpdate($fileEntry);
31 }
32 }
33
34 public function toArray() {
35 return ['type' => self::class, 'args' => [$this->skip, $this->count, $this->totalCount]];
36 }
37
38 public function toDescription(): string {
39 return sprintf('Determining file sizes... %s%%', round(100 * $this->skip / $this->totalCount));
40 }
41
42 }
43