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.

85 lines
2.1 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Ingest\DocumentHandler;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Http\UploadedFile;
  6. use Illuminate\Support\Carbon;
  7. use Illuminate\Support\Facades\Redis;
  8. class AnalyzePerformance extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'analyze:run {path : The directory path}';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Run analyzer on multiple files in a directory.';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. */
  35. public function handle()
  36. {
  37. $directoryPath = $this->argument('path');
  38. if ( ! is_dir($directoryPath)) {
  39. $this->error('The path is invalid: not a directory.');
  40. return;
  41. }
  42. $redis = Redis::connection();
  43. $redis->set('analyze_performance_time', Carbon::now()->format('U'));
  44. $redis->set('analyze_performance_path', $directoryPath);
  45. $allFiles = $this->getDirContents($directoryPath);
  46. $redis->set('analyze_performance_remaining_files', count($allFiles));
  47. foreach ($allFiles as $index => $file) {
  48. $handler = new DocumentHandler($index, new UploadedFile($file, "File {$index}"), false);
  49. $handler->handle();
  50. }
  51. $this->info('Processing... When it\'s done the results will be added to the \'ingest_analyze_performance.txt\' file in the directory you have provided.');
  52. }
  53. protected function getDirContents($dir, &$results = array())
  54. {
  55. $files = scandir($dir);
  56. foreach ($files as $key => $value) {
  57. $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
  58. if (!is_dir($path)) {
  59. $results[] = $path;
  60. } else if ($value != "." && $value != "..") {
  61. $this->getDirContents($path, $results);
  62. }
  63. }
  64. return $results;
  65. }
  66. }