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

<?php
namespace App\Console\Commands;
use App\Ingest\DocumentHandler;
use Illuminate\Console\Command;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Redis;
class AnalyzePerformance extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'analyze:run {path : The directory path}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run analyzer on multiple files in a directory.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
*/
public function handle()
{
$directoryPath = $this->argument('path');
if ( ! is_dir($directoryPath)) {
$this->error('The path is invalid: not a directory.');
return;
}
$redis = Redis::connection();
$redis->set('analyze_performance_time', Carbon::now()->format('U'));
$redis->set('analyze_performance_path', $directoryPath);
$allFiles = $this->getDirContents($directoryPath);
$redis->set('analyze_performance_remaining_files', count($allFiles));
foreach ($allFiles as $index => $file) {
$handler = new DocumentHandler(
$index,
'md',
new UploadedFile($file, "File {$index}"),
false
);
$handler->handle();
}
$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.');
}
protected function getDirContents($dir, &$results = array())
{
$files = scandir($dir);
foreach ($files as $key => $value) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!is_dir($path)) {
$results[] = $path;
} else if ($value != "." && $value != "..") {
$this->getDirContents($path, $results);
}
}
return $results;
}
}