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.

54 lines
1.1 KiB

  1. <?php
  2. namespace App\SearchDisplace\Documents;
  3. use Illuminate\Support\Facades\Storage;
  4. class DocumentFile
  5. {
  6. protected $storage;
  7. public function __construct()
  8. {
  9. $this->storage = Storage::disk('local');
  10. }
  11. public function getAfterIngest($id)
  12. {
  13. $path = $this->getPath($id);
  14. // Ingest success.
  15. if ($this->storage->exists("$path.md")) {
  16. return $this->storage->get("$path.md");
  17. }
  18. // Ingest fail.
  19. if ($this->storage->exists($path)) {
  20. return '';
  21. }
  22. throw new \Exception('Document has not been processed yet.');
  23. }
  24. public function destroy($id)
  25. {
  26. $path = $this->getPath($id);
  27. // Ingest success.
  28. if ($this->storage->exists("$path.md")) {
  29. return $this->storage->delete("$path.md");
  30. }
  31. // Ingest fail.
  32. if ($this->storage->exists($path)) {
  33. return $this->storage->delete($path);
  34. }
  35. throw new \Exception('Document has not been processed yet.');
  36. }
  37. protected function getPath($id)
  38. {
  39. return "contracts/$id";
  40. }
  41. }