/** * Execute the job. * * @return void */ public function handle(SourceRepository $sourceRepo) { $this->source->sync_status = "processing"; $this->source->save(); $id = $this->source->id; $rawFilePath = 'sources/' . $id . '/o/file.raw'; $procFilePath = 'sources/' . $id . '/p/file.processed'; // File exists in storage/app/sources/XX/o/file.raw ? if (!Storage::exists($rawFilePath)) { // update sync_status $this->source->sync_status = "error"; $sourceRepo->addRecord($this->source, "Raw file in {$rawFilePath} does not exists!", "error"); } elseif (Storage::mimeType($rawFilePath) != 'text/plain' && Storage::mimeType($rawFilePath) != 'application/octet-stream') { // update sync_status $this->source->sync_status = "error"; $fileMimeType = Storage::mimeType($rawFilePath); $sourceRepo->addRecord($this->source, "Mime type {$fileMimeType} of file in {$rawFilePath} not supported!", "error"); } else { $result = $sourceRepo->convertToGeoJSON($this->source, $rawFilePath, $procFilePath); if ($result == true) { $this->source->sync_status = "processed"; // Queue the source to be published $this->dispatch(new PublishSource($this->source)); } else { $this->source->sync_status = "error"; } } $this->source->save(); $sourceRepo->addRecord($this->source, "Source processed successfully!", "success"); }
/** * Execute the job. * * @return void */ public function handle(SourceRepository $sourceRepo) { $this->source->sync_status = "downloading"; $this->source->save(); $id = $this->source->id; $name = $this->source->name; $url = $this->source->origin_url; $sourceRepo->addRecord($this->source, "Starting download"); $response = $sourceRepo->copyRemoteFile($url, storage_path('app/sources/' . $id . '/o/file.raw')); if (!$response) { // update sync_status $this->source->sync_status = "error"; $sourceRepo->addRecord($this->source, "No response received from server origin", "error"); } elseif ($response->getStatusCode() == 200) { // update origin_format $this->source->origin_format = $sourceRepo->guessResponseType($response, $url); // update origin_size $this->source->origin_size = $sourceRepo->guessResponseLength($response); // update synced_at $this->source->synced_at = Carbon::now()->toDateTimeString(); // update sync_status $this->source->sync_status = "downloaded"; $this->source->save(); // Queue the source to be converted $this->dispatch(new ConvertSource($this->source)); $sourceRepo->addRecord($this->source, "Download success!", "success"); } else { // update sync_status $this->source->sync_status = "error"; $statusCode = $response->getStatusCode(); $sourceRepo->addRecord($this->source, "Server origin respondend with status code {$statusCode} while downloading" . "error"); } $this->source->save(); }
/** * Execute the job. * * @return void */ public function handle(SourceRepository $sourceRepo) { $this->source->sync_status = "publishing"; $this->source->save(); $id = $this->source->id; $hash = $this->source->hash; $procFilePath = 'storage/app/sources/' . $id . '/p/file.processed'; $pubFilePath = 'public/sources/' . $hash . '.geojson'; // File exists in storage/app/sources/p/file.processed ? if (!Storage::disk('base')->exists($procFilePath)) { // update sync_status $this->source->sync_status = "error"; $sourceRepo->addRecord($this->source, "Processed file in {$procFilePath} does not exists!", "error"); } else { $result = $sourceRepo->publish($this->source, $procFilePath, $pubFilePath); if ($result == true) { $this->source->sync_status = "ready"; } else { $this->source->sync_status = "error"; } } $this->source->save(); $sourceRepo->addRecord($this->source, "Source published successfully!", "success"); }