|
|
@ -9,6 +9,8 @@ use GuzzleHttp\Client; |
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
use \Illuminate\Contracts\Filesystem\Filesystem; |
|
|
|
use App\SearchDisplace\Convertor\Convertor; |
|
|
|
|
|
|
|
class HandleReceivedDocument |
|
|
|
{ |
|
|
@ -17,6 +19,7 @@ class HandleReceivedDocument |
|
|
|
protected $fileResultType; |
|
|
|
protected $documentFormat; |
|
|
|
protected $status; |
|
|
|
protected Filesystem $storage; |
|
|
|
|
|
|
|
public function __construct($payload) |
|
|
|
{ |
|
|
@ -28,6 +31,8 @@ class HandleReceivedDocument |
|
|
|
if (isset($payload['data']['document_format'])) { |
|
|
|
$this->documentFormat = $payload['data']['document_format']; |
|
|
|
} |
|
|
|
|
|
|
|
$this->storage = Storage::disk('local'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -58,6 +63,7 @@ class HandleReceivedDocument |
|
|
|
|
|
|
|
// The .md extension signals the success status, the lack of signals the fail status.
|
|
|
|
if ($this->status === 'success') { |
|
|
|
$intermediateFileName = $fileName . '.odt'; |
|
|
|
$fileName = $fileName . '.html'; |
|
|
|
} |
|
|
|
|
|
|
@ -68,6 +74,11 @@ class HandleReceivedDocument |
|
|
|
|
|
|
|
$storage->put("$dir/$fileName", $this->content['document']); |
|
|
|
|
|
|
|
// HTML document cannot be converted directly to xml. So we convert to ODT first, then to XML
|
|
|
|
Convertor::convert('odt', $this->storage->path("$dir/$fileName")); |
|
|
|
Convertor::convert('xml', $this->storage->path("$dir/$intermediateFileName")); |
|
|
|
$this->storage->delete("$dir/$intermediateFileName"); |
|
|
|
|
|
|
|
foreach ($this->content['images'] as $image) { |
|
|
|
$name = $image['name']; |
|
|
|
$type = $image['type']; |
|
|
@ -81,7 +92,8 @@ class HandleReceivedDocument |
|
|
|
// Emit event so other sections of the app can work on it.
|
|
|
|
IngestDocumentReceived::dispatch($this->id); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
\Illuminate\Support\Facades\Log::info('Exception: ' . $exception->getTraceAsString()); |
|
|
|
Log::error('Exception: ' . $exception->getMessage()); |
|
|
|
Log::error($exception->getTraceAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|