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;
#[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
{
......@@ -109,20 +111,32 @@ class RekallProjectDuplicateImagesCommand extends Command
string $current_legacy_path
): void {
$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) {
if (str_starts_with($filename, $current_legacy_path.'/'.self::$ORIGINAL_FILE_PREPEND_WITH))
$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);
}
$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
} else {
$success++;
}
}
}
$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