5 use Dkan\Datastore\Importer;
6 use FileFetcher\FileFetcher;
7 use Procrastinator\Job\Job;
119 private function buildItem() {
120 $this->fileName = $this->getFileName();
121 $this->fileFetcherStatus = $this->fileFetcher->getResult()->getStatus();
122 $this->fileFetcherBytes = $this->getBytesProcessed($this->fileFetcher);
123 $this->fileFetcherPercentDone = $this->getPercentDone($this->fileFetcher);
124 $this->importerStatus =
'waiting';
125 $this->importerBytes = 0;
126 $this->importerPercentDone = 0;
128 if (isset($this->importer)) {
129 $this->importerStatus = $this->importer->getResult()->getStatus();
130 $this->importerBytes = $this->getBytesProcessed($this->importer);
131 $this->importerPercentDone = $this->getPercentDone($this->importer);
138 private function getFileName(): string {
139 $fileLocation = $this->fileFetcher->getStateProperty(
'source');
140 $locationParts = explode(
'/', $fileLocation);
141 return end($locationParts);
153 private function getPercentDone(Job $job): float {
154 $bytes = $this->getBytesProcessed($job);
155 $filesize = $this->getFileSize();
156 return ($filesize > 0) ? round($bytes / $filesize * 100) : 0;
165 private function getFileSize(): int {
166 return $this->fileFetcher->getStateProperty(
'total_bytes');
178 private function getBytesProcessed(Job $job): int {
179 $className = get_class($job);
180 switch ($className) {
182 case Importer::class:
183 $chunksSize = $job->getStateProperty(
'chunksProcessed') * Importer::BYTES_PER_CHUNK;
184 $fileSize = $this->getFileSize();
185 return ($chunksSize > $fileSize) ? $fileSize : $chunksSize;
187 case FileFetcher::class:
188 return $job->getStateProperty(
'total_bytes_copied');