Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Jobs;
  3. use App\Ingest\Convertor;
  4. use App\Parser\ParseXml;
  5. use App\Parser\DocxParser\ParseDocx;
  6. use App\Parser\HtmlParser\ParseHtml;
  7. use App\Parser\ParseHtmlArray;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Support\Facades\Log;
  13. use Illuminate\Support\Facades\Storage;
  14. class IngestDocuments implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable;
  17. protected $id;
  18. private $path;
  19. protected $type;
  20. /**
  21. * @var \Illuminate\Contracts\Filesystem\Filesystem
  22. */
  23. private $storage;
  24. /**
  25. * @var \App\Parser\DocxParser\ParseDocx
  26. */
  27. private $parserDocx;
  28. /**
  29. * @var \App\Parser\ParseXml
  30. */
  31. private $parserXml;
  32. /**
  33. * @var \App\Parser\HtmlParser\ParseHtml
  34. */
  35. private $parserHtml;
  36. /**
  37. * @var \App\Parser\ParseHtmlArray
  38. */
  39. private $parseHtmlArray;
  40. /**
  41. * Create a new job instance.
  42. *
  43. * @param $id
  44. * @param string $path
  45. * @param $type
  46. */
  47. public function __construct($id, string $path, $type)
  48. {
  49. $this->id = $id;
  50. $this->path = $path;
  51. $this->type = $type;
  52. $this->storage = Storage::disk('local');
  53. $this->parserDocx = new ParseDocx();
  54. $this->parserXml = new ParseXml();
  55. $this->parserHtml = new ParseHtml();
  56. $this->parseHtmlArray = new ParseHtmlArray();
  57. }
  58. /**
  59. * Execute the job.
  60. *
  61. * @return void
  62. */
  63. public function handle()
  64. {
  65. $convertor = new Convertor($this->path, $this->type);
  66. try {
  67. $convertor->execute();
  68. } catch (\Exception $exception) {
  69. \Illuminate\Support\Facades\Log::info($exception->getMessage());
  70. $this->failed();
  71. return;
  72. }
  73. SendToCore::dispatch($this->id, pathinfo($this->path, PATHINFO_DIRNAME));
  74. }
  75. public function failed()
  76. {
  77. if ( ! $this->storage) {
  78. $this->storage = Storage::disk('local');
  79. }
  80. Log::error('Ingest documents failed.');
  81. // // @TODO Delete docx, txt and md files.
  82. // if ($this->storage->exists($this->path)) {
  83. // $this->storage->delete($this->path);
  84. // }
  85. SendToCore::dispatch($this->id, pathinfo($this->path, PATHINFO_DIRNAME), true);
  86. }
  87. }