# disk-usage-insights/1.6/src/Domain/Collect/DetermineWpCoreFileJob.php

Disk Usage Insights, version 1.6. 62 lines.

- Page: https://pluginprobe.com/plugins/disk-usage-insights/1.6/code/src/Domain/Collect/DetermineWpCoreFileJob.php
- Raw: https://pluginprobe.com/plugins/disk-usage-insights/1.6/raw/src/Domain/Collect/DetermineWpCoreFileJob.php
- Modified: 2025-04-08T13:02:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/disk-usage-insights/1.6/code/src/Domain/Collect/DetermineWpCoreFileJob.php#L10-L20`.

```php
<?php

namespace Mgleis\DiskUsageInsights\Domain\Collect;

use Mgleis\DiskUsageInsights\Domain\Jobs\BaseJob;

class DetermineWpCoreFileJob extends BaseJob {

    private int $skip;
    private int $count;
    private int $totalCount;

    public function __construct(int $skip, int $count, int $totalCount) {
        $this->skip = $skip;
        $this->count = $count;
        $this->totalCount = $totalCount;
    }

    public function work() {

        $this->log(self::class);

        $snapshot = $this->snapshotRepository->load();
        if (sizeof($snapshot->wpcorefiles) == 0) {

            // Fetch WP Core files and store them in kv store
            global $wp_version;
            $url = sprintf('https://api.wordpress.org/core/checksums/1.0/?version=%s&locale=en_US', $wp_version);
            $this->log("Fetching from url: " . $url);
            $str = wp_remote_get($url)['body'];
            $arr = json_decode($str, true, JSON_THROW_ON_ERROR);
            if ($arr['checksums'] === false) {
                throw new \Exception("Could not fetch the checksums of wordpress api.");
            }

            $snapshot->wpcorefiles = array_keys($arr['checksums']);
            $this->snapshotRepository->save($snapshot);
        }

        // TODO: batch it
        $fileEntries = $this->fileEntryRepository->get($this->skip, $this->count);
        foreach ($fileEntries as $fileEntry) {

            $relativeFilename = $this->fileEntryRepository->calcFullPath($fileEntry);
            if (in_array($relativeFilename, $snapshot->wpcorefiles)) {
                $fileEntry->is_wp_core_file = 1;
                $this->fileEntryRepository->createOrUpdate($fileEntry);
            }
        }

    }

    public function toArray() {
        return ['type' => self::class, 'args' => [$this->skip, $this->count, $this->totalCount]];
    }

    public function toDescription(): string {
        return sprintf('Determining WordPress core files... %s%%', round(100 * $this->skip / $this->totalCount));
    }

}

```
