コード例 #1
0
 /**
  * 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");
 }
コード例 #2
0
 /**
  * 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();
 }
コード例 #3
0
 public function checkUrl(Request $request)
 {
     $this->validate($request, ['origin_url' => 'required|url|max:2048']);
     $info = $this->source->getRemoteFileInfo($request->origin_url);
     if ($info['status'] == 200) {
         $data = ['data' => ['fileSize' => $info['size'], 'fileType' => $info['type']]];
     } else {
         $data = ['errors' => ['message' => 'File not reachable or moved']];
     }
     return response()->json($data, $info['status']);
 }
コード例 #4
0
 /**
  * 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");
 }
コード例 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->source->syncAllSources();
 }
コード例 #6
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(TagRepository $tag, SourceRepository $source, $id)
 {
     $routeName = 'map';
     $routeMethod = 'edit';
     $map = $this->map->getById($id);
     if (!$map) {
         return redirect()->route('admin.map.index');
     }
     $tags = $tag->getAllOrderedBy('name');
     $sources = $source->getAllOrderedBy('name');
     $environment = collect(['settings' => \Cache::get('settings')]);
     $environment = $environment->toJSON();
     $data = compact('routeName', 'routeMethod', 'map', 'tags', 'sources', 'environment');
     \Clockwork::info($data);
     return view('admin.sections.map.edit', $data);
 }