->setDescription('distributes the existing previews into subfolders')
->addOption('batch','b',InputOption::VALUE_NONE,'Batch mode - will not ask to start the migration and start it right away.')
->addOption('dry','d',InputOption::VALUE_NONE,'Dry mode - will not create, move or delete any files - in combination with the verbose mode one could check the operations.');
$output->writeln("Memory limit is $limitInMiB MiB");
$output->writeln("Memory threshold is $thresholdInMiB MiB");
$output->writeln("");
$memoryCheckEnabled=true;
}else{
$output->writeln("No memory limit in place - disabled memory check. Set a PHP memory limit to automatically stop the execution of this migration script once memory consumption is close to this limit.");
$output->writeln("");
$memoryCheckEnabled=false;
}
$dryMode=$input->getOption('dry');
if($dryMode){
$output->writeln("INFO: The migration is run in dry mode and will not modify anything.");
$output->writeln("All previews are already migrated.");
return0;
}
$output->writeln("A total of $total preview files need to be migrated.");
$output->writeln("");
$output->writeln("The migration will always migrate all previews of a single file in a batch. After each batch the process can be canceled by pressing CTRL-C. This fill finish the current batch and then stop the migration. This migration can then just be started and it will continue.");
if($input->getOption('batch')){
$output->writeln('Batch mode active: migration is started right away.');
}else{
$helper=$this->getHelper('question');
$question=newConfirmationQuestion('<info>Should the migration be started? (y/[n]) </info>',false);
if(!$helper->ask($input,$output,$question)){
return0;
}
}
// register the SIGINT listener late in here to be able to exit in the early process of this command
pcntl_signal(SIGINT,[$this,'sigIntHandler']);
$output->writeln("");
$output->writeln("");
$section1=$output->section();
$section2=$output->section();
$progressBar=newProgressBar($section2,$total);
$progressBar->setFormat("%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% Used Memory: %memory:6s%");
$time=(new\DateTime())->format('H:i:s');
$progressBar->setMessage("$time Starting …");
$progressBar->maxSecondsBetweenRedraws(0.2);
$progressBar->start();
foreach($directoryListingas$oldPreviewFolder){
pcntl_signal_dispatch();
$name=$oldPreviewFolder->getName();
$time=(new\DateTime())->format('H:i:s');
$section1->writeln("$time Migrating previews of file with fileId $name …");