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.

90 lines
2.2 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(
  49. $index,
  50. 'md',
  51. new UploadedFile($file, "File {$index}"),
  52. false
  53. );
  54. $handler->handle();
  55. }
  56. $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.');
  57. }
  58. protected function getDirContents($dir, &$results = array())
  59. {
  60. $files = scandir($dir);
  61. foreach ($files as $key => $value) {
  62. $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
  63. if (!is_dir($path)) {
  64. $results[] = $path;
  65. } else if ($value != "." && $value != "..") {
  66. $this->getDirContents($path, $results);
  67. }
  68. }
  69. return $results;
  70. }
  71. }