PluginProbe
Disk Usage Insights / 1.3
Disk Usage Insights v1.3
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 1.3, at src/Domain/Collect/DetermineFileSizesJob.php

45 lines 1.3 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 $this->log($absoluteFilename);
29
30 $fileEntry->size = filesize($absoluteFilename);
31
32 $this->fileEntryRepository->createOrUpdate($fileEntry);
33 }
34 }
35
36 public function toArray() {
37 return ['type' => self::class, 'args' => [$this->skip, $this->count, $this->totalCount]];
38 }
39
40 public function toDescription(): string {
41 return sprintf('Determining file sizes... %s%%', round(100 * $this->skip / $this->totalCount));
42 }
43
44 }
45