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

Add command to keep original files aside from edited

+ fix reload of edited image in edition popup
parent cb4ec9f1
No related branches found
No related tags found
1 merge request!93Edit annotation picture
Pipeline #1081 failed
......@@ -569,6 +569,7 @@ function setEditionControls() {
var file = new File([uar], keyDoc.value.substr(1), {type: type+'/'+subtype});
$('#left_menu_item_btn_addfile').files = [file];
uploadFiles([file], {'edited': 1});
$('#popupImg').attr('src', $('#popupImg').attr('src') + '&time=' + performance.now());
});
markerArea.addEventListener('close', () => $('#edit_pic_modal').hide());
markerArea.renderAtNaturalSize = true;
......
......@@ -88,7 +88,7 @@ Document.prototype.isLink = function(version) {
}
Document.prototype.getDownloadLink = function(original = false) {
var path = Utils.getLocalFilePath(this, "file");
return original ? path.replace('file.php?r=', 'file.php?r=original_') : path;
return original ? path.replace('file.php?r=', 'file.php?r=rk_original_af7ef02e_') : path;
}
Document.prototype.getFileName = function() {
var path = Utils.getLocalFilePath(this, "file");
......
<?php
namespace App\Command;
use LogicException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
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',
)]
class RekallProjectDuplicateImagesCommand extends Command
{
private Filesystem $file_system;
private KernelInterface $kernel;
private string $legacy_root;
private static string $LEGACY_DIRECTORY_NAME = 'legacy';
private static string $IMG_GLOB = '*.{[pP][nN][gG],[jJ][pP][gG],[jJ][pP][eE][gG],[gG][iI][fF]}';
private static string $ORIGINAL_FILE_PREPEND_WITH = 'rk_original_af7ef02e_';
public function __construct(Filesystem $filesystem, KernelInterface $kernel)
{
parent::__construct();
$this->file_system = $filesystem;
$this->kernel = $kernel;
$this->legacy_root = Path::join($this->kernel->getProjectDir(), self::$LEGACY_DIRECTORY_NAME);
}
protected function configure(): void { }
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$output instanceof ConsoleOutputInterface) {
throw new LogicException('This command accepts only an instance of "ConsoleOutputInterface".');
}
ProgressBar::setFormatDefinition(
'project_update_message',
' %current%/%max% [%bar%] %percent%% : Updating project :%project% %elapsed%'
);
$output->writeln('Updating images for all projects started');
$all_file_in_directory = $this->getProjectsDirectories();
if (false === $all_file_in_directory) {
return Command::FAILURE;
}
$all_projects_progress_bar = new ProgressBar($output->section());
$all_projects_progress_bar->setFormat(
'%current%/%max% [%bar%] %percent%% : Overall project update progressing (%elapsed%)'
);
$all_projects_progress_bar->SetMessage('Projects update progress');
$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');
if (!$this->file_system->exists($current_legacy_path)) {
$output->writeln("'$current_legacy_path' don't exists");
continue;
}
if (!is_dir($current_legacy_path)) {
$output->writeln("'$current_legacy_path' is not a directory");
continue;
}
$this->updateProjectDirectory(
$output,
$current_legacy_path
);
$all_projects_progress_bar->advance();
}
$all_projects_progress_bar->finish();
return Command::SUCCESS;
}
/**
* @return string[]|false
*/
private function getProjectsDirectories(): array|false
{
$all_directories_and_files = glob($this->legacy_root . '/*');
if (false === $all_directories_and_files) {
return false;
}
return $all_directories_and_files;
}
/**
* @param ConsoleOutputInterface $output
* @param string $current_legacy_path
* @return void
*/
protected function updateProjectDirectory(
ConsoleOutputInterface $output,
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++;
}
}
$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