diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php index 0dd9b9c..b4c381c 100644 --- a/app/Http/Controllers/FileController.php +++ b/app/Http/Controllers/FileController.php @@ -72,8 +72,6 @@ public function update() $file->save(); return redirect()->route('mygraphs')->with('notification', 'File updated!!!'); - - } public function destroy(File $file) @@ -88,34 +86,8 @@ public function download(Request $request, File $file){ } public function parse(File $file) - { - /* - * Read the graph - */ - try{ - if($file->filetype != 'ntriples'){ - $this->convert($file); - $file->cacheGraph(); - } - else{ - $file->cacheGraph(); - } - return redirect()->route('mygraphs')->with('notification', 'Graph Parsed!!!'); - - } catch (\Exception $ex) { - $file->parsed = false; - $file->save(); - error_log($ex); - return redirect()->route('mygraphs')->with('error', 'Failed to parse the graph. Please check the logs.' . $ex); - } - } - - public function convert(File $file){ - $command = 'rapper -i ' . $file->filetype . ' -o ntriples ' . $file->resource->path() . ' > ' . $file->resource->path(). '.nt'; - $out = []; - logger($command); - exec( $command, $out); - logger(var_dump($out)); - return; - } + { + dispatch(new \App\Jobs\Parse($file, auth()->user())); + return redirect()->back()->with('notification', 'Parsing Job Dispatched, check your logs.'); + } } diff --git a/app/Jobs/Parse.php b/app/Jobs/Parse.php new file mode 100644 index 0000000..6ce52b6 --- /dev/null +++ b/app/Jobs/Parse.php @@ -0,0 +1,75 @@ +file = $file; + $this->user = $user; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $this->parse($this->file); + } + + public function parse(File $file) + { + /* + * Read the graph + */ + try{ + if($file->filetype != 'ntriples'){ + $this->reserialize($file); + } + $file->cacheGraph(); + } catch (\Exception $ex) { + $file->parsed = false; + $file->save(); + error_log($ex); + } + } + + public function reserialize(File $file){ + $command = [ + 'rapper', + '-i ', + $file->filetype, + '-o', + 'ntriples', + $file->resource->path(), + '>', + $file->resource->path(). '.nt' + ]; + + $process = new Process($command); + $process->run(); + return; + } +}