Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
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.

40 lines
1.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\SearchDisplace\Ingest;
  3. use App\Events\IngestDocumentReceived;
  4. use Illuminate\Support\Facades\Storage;
  5. class HandleReceivedDocument
  6. {
  7. protected $id;
  8. protected $content;
  9. protected $status;
  10. public function __construct($payload)
  11. {
  12. $this->id = $payload['data']['id'];
  13. $this->content = $payload['data']['content'];
  14. $this->status = $payload['data']['status'];
  15. }
  16. public function handle()
  17. {
  18. $storage = Storage::disk('local');
  19. $fileName = $this->id;
  20. // The .md extension signals the success status, the lack of signals the fail status.
  21. if ($this->status === 'success') {
  22. $fileName = $fileName . '.md';
  23. }
  24. try {
  25. $storage->put("contracts/${fileName}", $this->content);
  26. IngestDocumentReceived::dispatch($this->id);
  27. } catch (\Exception $exception) {
  28. \Illuminate\Support\Facades\Log::info('Exception: ' . $exception->getTraceAsString());
  29. }
  30. }
  31. }