You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.4 KiB
107 lines
2.4 KiB
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Ingest\Convertor;
|
|
use App\Parser\ParseXml;
|
|
use App\Parser\DocxParser\ParseDocx;
|
|
use App\Parser\HtmlParser\ParseHtml;
|
|
use App\Parser\ParseHtmlArray;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class IngestDocuments implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable;
|
|
|
|
protected $id;
|
|
private $path;
|
|
protected $type;
|
|
|
|
/**
|
|
* @var \Illuminate\Contracts\Filesystem\Filesystem
|
|
*/
|
|
private $storage;
|
|
|
|
/**
|
|
* @var \App\Parser\DocxParser\ParseDocx
|
|
*/
|
|
private $parserDocx;
|
|
|
|
/**
|
|
* @var \App\Parser\ParseXml
|
|
*/
|
|
private $parserXml;
|
|
|
|
/**
|
|
* @var \App\Parser\HtmlParser\ParseHtml
|
|
*/
|
|
private $parserHtml;
|
|
|
|
/**
|
|
* @var \App\Parser\ParseHtmlArray
|
|
*/
|
|
private $parseHtmlArray;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @param $id
|
|
* @param string $path
|
|
* @param $type
|
|
*/
|
|
public function __construct($id, string $path, $type)
|
|
{
|
|
$this->id = $id;
|
|
$this->path = $path;
|
|
$this->type = $type;
|
|
|
|
$this->storage = Storage::disk('local');
|
|
$this->parserDocx = new ParseDocx();
|
|
$this->parserXml = new ParseXml();
|
|
$this->parserHtml = new ParseHtml();
|
|
$this->parseHtmlArray = new ParseHtmlArray();
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$convertor = new Convertor($this->path, $this->type);
|
|
|
|
try {
|
|
$convertor->execute();
|
|
} catch (\Exception $exception) {
|
|
\Illuminate\Support\Facades\Log::info($exception->getMessage());
|
|
|
|
$this->failed();
|
|
|
|
return;
|
|
}
|
|
|
|
SendToCore::dispatch($this->id, pathinfo($this->path, PATHINFO_DIRNAME));
|
|
}
|
|
|
|
public function failed()
|
|
{
|
|
if ( ! $this->storage) {
|
|
$this->storage = Storage::disk('local');
|
|
}
|
|
|
|
Log::error('Ingest documents failed.');
|
|
|
|
// // @TODO Delete docx, txt and md files.
|
|
// if ($this->storage->exists($this->path)) {
|
|
// $this->storage->delete($this->path);
|
|
// }
|
|
|
|
SendToCore::dispatch($this->id, pathinfo($this->path, PATHINFO_DIRNAME), true);
|
|
}
|
|
}
|