diff --git a/src/Command/RekallProjectDuplicateImagesCommand.php b/src/Command/RekallProjectDuplicateImagesCommand.php index 990581d91273d1a7760944d09f793540699b2432..74fbf3f902d040d173c7ce4ccef2cfb01a19c9c8 100644 --- a/src/Command/RekallProjectDuplicateImagesCommand.php +++ b/src/Command/RekallProjectDuplicateImagesCommand.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\KernelInterface; #[AsCommand( name: 'rekall:project:duplicate-images', - description: 'Duplicate each JPG/PNG/GIF file, creating for each a corresponding rk_original_af7ef02e_<filename>.xyz file', + description: 'Duplicate each JPG/PNG/GIF file to keep original separated from edited', )] class RekallProjectDuplicateImagesCommand extends Command { @@ -36,7 +36,9 @@ class RekallProjectDuplicateImagesCommand extends Command $this->legacy_root = Path::join($this->kernel->getProjectDir(), self::$LEGACY_DIRECTORY_NAME); } - protected function configure(): void { } + protected function configure(): void + { + } protected function execute(InputInterface $input, OutputInterface $output): int { @@ -63,7 +65,7 @@ class RekallProjectDuplicateImagesCommand extends Command $all_projects_progress_bar->start(); foreach ($all_projects_progress_bar->iterate($all_file_in_directory) as $project_directory) { - $current_legacy_path = Path::join( $project_directory, 'file'); + $current_legacy_path = Path::join($project_directory, 'file'); if (!$this->file_system->exists($current_legacy_path)) { $output->writeln("'$current_legacy_path' don't exists"); @@ -109,19 +111,31 @@ class RekallProjectDuplicateImagesCommand extends Command string $current_legacy_path ): void { $output->writeln("Updating project :$current_legacy_path"); - $success = $failed = 0; - - foreach (glob("$current_legacy_path/".self::$IMG_GLOB, GLOB_BRACE) as $filename) { - if (str_starts_with($filename, $current_legacy_path.'/'.self::$ORIGINAL_FILE_PREPEND_WITH)) - continue; - $target = str_replace($current_legacy_path.'/', $current_legacy_path.'/'.self::$ORIGINAL_FILE_PREPEND_WITH, $filename); - if (!file_exists($target)) { - if (!copy($filename, $target)) { - $output->writeln("Failed to copy '$filename' to '$target'"); - $failed++; - } else - $success++; - } + $success = 0; + $failed = 0; + + $ar = glob("$current_legacy_path/" . self::$IMG_GLOB, GLOB_BRACE); + if ($ar === false) { + $output->writeln("Failed to list projects images files for '$current_legacy_path'"); + return; + } + foreach ($ar as $filename) { + if (str_starts_with($filename, $current_legacy_path . '/' . self::$ORIGINAL_FILE_PREPEND_WITH)) { + continue; + } + $target = str_replace( + $current_legacy_path . '/', + $current_legacy_path . '/' . self::$ORIGINAL_FILE_PREPEND_WITH, + $filename + ); + if (!file_exists($target)) { + if (!copy($filename, $target)) { + $output->writeln("Failed to copy '$filename' to '$target'"); + $failed++; + } else { + $success++; + } + } } $output->writeln("Updated project :$current_legacy_path, $success files duplicated, $failed failed ---> DONE");