diff --git a/capsule-prototype/index.html b/capsule-prototype/index.html index 7ee885705fe9b68e931f1c62b895562c94bade6f..cf06a103a947121e72f8400440510a3fb8f6f9ba 100644 --- a/capsule-prototype/index.html +++ b/capsule-prototype/index.html @@ -245,14 +245,13 @@ </div> </tr></td> </table> - <div style="width: 100%; height: 30px; background: black"></div> - <video id="video" class="video-js vjs-default-skin vjs-big-play-centered"> - <p class="vjs-no-js">Your browser is not compatible with HTML5. Please upgrade!</p> - <!-- - <track kind="captions" src="demo.captions.vtt" srclang="en" label="English"></track> - <track kind="subtitles" src="demo.captions.vtt" srclang="en" label="English"></track> - --> - </video> + <video id="video" class="video-js vjs-default-skin vjs-big-play-centered"> + <p class="vjs-no-js">Your browser is not compatible with HTML5. Please upgrade!</p> + <!-- + <track kind="captions" src="demo.captions.vtt" srclang="en" label="English"></track> + <track kind="subtitles" src="demo.captions.vtt" srclang="en" label="English"></track> + --> + </video> <div id='flattentimeline'> <div id="flattentimeline_highlight"> </div> diff --git a/composer.json b/composer.json index 9e04f2e2b7f87b58588e4a31745d4950b4ea714a..74db1d7e7f9bc97df1daa1bf53bba86b8584b1b2 100644 --- a/composer.json +++ b/composer.json @@ -145,7 +145,8 @@ "@php bin/console doctrine:database:create --if-not-exists --no-interaction --env=dev", "@php bin/console doctrine:migration:migrate --all-or-nothing --no-interaction --env=dev", "@php bin/console doctrine:fixture:load --no-interaction --env=dev" - ] + ], + "update-projects": ["@php bin/console rekall:projects:update"] }, "conflict": { "symfony/symfony": "*" diff --git a/src/Command/UpdateAllProjects.php b/src/Command/UpdateAllProjects.php new file mode 100644 index 0000000000000000000000000000000000000000..144166a08844654885d7dd4f4e5a2724c047a630 --- /dev/null +++ b/src/Command/UpdateAllProjects.php @@ -0,0 +1,183 @@ +<?php + +namespace App\Command; + +use LogicException; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Boolean; +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:projects:update', + description: 'Update commons files on projects.', + aliases: ['rekall-update-projects'], + hidden: false +)] +class UpdateAllProjects extends Command +{ + private Filesystem $file_system; + private KernelInterface $kernel; + + private string $legacy_root; + private string $capsule_prototype_root; + + /** + * @var string[] $BLACK_LIST files and directories that should not be taken into account for projects update + */ + private static array $BLACK_LIST = + ['css', 'create.zip', 'favicon.ico', 'la-page-des-malins.php', 'js', 'php', 'shared', '.', '..']; + private static string $CAPSULE_PROTOTYPE_DIRECTORY_NAME = 'capsule-prototype'; + private static string $LEGACY_DIRECTORY_NAME = 'legacy'; + + + public function __construct(Filesystem $filesystem, KernelInterface $kernel) + { + parent::__construct(); + + // best practices recommend to call the parent constructor first and + // then set your own properties. That wouldn't work in this case + // because configure() needs the properties set in this constructor + $this->file_system = $filesystem; + $this->kernel = $kernel; + $this->legacy_root = Path::join($this->kernel->getProjectDir(), self::$LEGACY_DIRECTORY_NAME); + $this->capsule_prototype_root = Path::join( + $this->kernel->getProjectDir(), + self::$CAPSULE_PROTOTYPE_DIRECTORY_NAME + ); + } + + protected function configure(): void + { + $this + // If you don't like using the $defaultDescription static property, + // you can also define the short description using this method: + ->setDescription('Update every project php files and index.html') + + // the command help shown when running the command with the "--help" option + ->setHelp('This command allows update projects common files...'); + } + + 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 all projects started'); + + $all_file_in_directory = $this->getProjectsDirectories(); + if (false === $all_file_in_directory) { + return Command::FAILURE; + } + + $php_files_count_per_projects = $this->getPhpFilesCountPerProjects(); + + $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($this->legacy_root, $project_directory); + + if (!$this->file_system->exists($current_legacy_path)) { + continue; + } + + if (!is_dir($current_legacy_path)) { + continue; + } + + if (in_array($project_directory, self::$BLACK_LIST)) { + continue; + } + + $this->updateProjectDirectory( + $output, + $php_files_count_per_projects, + $current_legacy_path, + $this->capsule_prototype_root + ); + $all_projects_progress_bar->advance($php_files_count_per_projects); + } + + $all_projects_progress_bar->finish(); + + return Command::SUCCESS; + } + + /** + * @return string[]|false + */ + private function getProjectsDirectories(): array|false + { + + $all_directories_and_files = scandir($this->legacy_root); + if (false === $all_directories_and_files) { + return false; + } + return array_diff($all_directories_and_files, self::$BLACK_LIST); + } + + /** + * @return int + */ + protected function getPhpFilesCountPerProjects(): int + { + $php_files = glob($this->capsule_prototype_root . '/php/*.php'); + // add +1 for index.html file + return count($php_files ?: []) + 1; + } + + /** + * @param ConsoleOutputInterface $output + * @param int $php_files_count_per_projects + * @param string $current_legacy_path + * @param string $capsule_prototype_root + * @return void + */ + protected function updateProjectDirectory( + ConsoleOutputInterface $output, + int $php_files_count_per_projects, + string $current_legacy_path, + string $capsule_prototype_root + ): void { + $progress_bar = new ProgressBar($output->section(), $php_files_count_per_projects); + $progress_bar->setFormat('project_update_message'); + $progress_bar->setMessage($current_legacy_path, 'project'); + + $progress_bar->start(); + + // override index.html + $this->file_system->copy( + Path::normalize($capsule_prototype_root . '/index.html'), + Path::normalize($current_legacy_path . '/index.html'), + true + ); + $progress_bar->advance(); + + // override php files + $this->file_system->mirror( + Path::join($capsule_prototype_root, 'php'), + Path::join($current_legacy_path, 'php'), + null, + ['override' => true, 'delete' => true] + ); + $progress_bar->advance($php_files_count_per_projects - 1); + $progress_bar->finish(); + } +}