Skip to content
Snippets Groups Projects
Commit 92b05979 authored by Loïs Poujade's avatar Loïs Poujade
Browse files

Fix php

parent 975675a6
No related branches found
No related tags found
1 merge request!93Edit annotation picture
Pipeline #1082 passed
...@@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\KernelInterface; ...@@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\KernelInterface;
#[AsCommand( #[AsCommand(
name: 'rekall:project:duplicate-images', 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 class RekallProjectDuplicateImagesCommand extends Command
{ {
...@@ -36,7 +36,9 @@ class RekallProjectDuplicateImagesCommand extends Command ...@@ -36,7 +36,9 @@ class RekallProjectDuplicateImagesCommand extends Command
$this->legacy_root = Path::join($this->kernel->getProjectDir(), self::$LEGACY_DIRECTORY_NAME); $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 protected function execute(InputInterface $input, OutputInterface $output): int
{ {
...@@ -109,20 +111,32 @@ class RekallProjectDuplicateImagesCommand extends Command ...@@ -109,20 +111,32 @@ class RekallProjectDuplicateImagesCommand extends Command
string $current_legacy_path string $current_legacy_path
): void { ): void {
$output->writeln("Updating project :$current_legacy_path"); $output->writeln("Updating project :$current_legacy_path");
$success = $failed = 0; $success = 0;
$failed = 0;
foreach (glob("$current_legacy_path/".self::$IMG_GLOB, GLOB_BRACE) as $filename) { $ar = glob("$current_legacy_path/" . self::$IMG_GLOB, GLOB_BRACE);
if (str_starts_with($filename, $current_legacy_path.'/'.self::$ORIGINAL_FILE_PREPEND_WITH)) 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; continue;
$target = str_replace($current_legacy_path.'/', $current_legacy_path.'/'.self::$ORIGINAL_FILE_PREPEND_WITH, $filename); }
$target = str_replace(
$current_legacy_path . '/',
$current_legacy_path . '/' . self::$ORIGINAL_FILE_PREPEND_WITH,
$filename
);
if (!file_exists($target)) { if (!file_exists($target)) {
if (!copy($filename, $target)) { if (!copy($filename, $target)) {
$output->writeln("Failed to copy '$filename' to '$target'"); $output->writeln("Failed to copy '$filename' to '$target'");
$failed++; $failed++;
} else } else {
$success++; $success++;
} }
} }
}
$output->writeln("Updated project :$current_legacy_path, $success files duplicated, $failed failed ---> DONE"); $output->writeln("Updated project :$current_legacy_path, $success files duplicated, $failed failed ---> DONE");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment