dir = $dir; $this->results = []; } } class BulkAdd extends Extension { /** @var BulkAddTheme */ protected Themelet $theme; public function onPageRequest(PageRequestEvent $event): void { global $page, $user; if ($event->page_matches("bulk_add")) { $dir = $event->get_POST('dir'); if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && $dir) { shm_set_timeout(null); $bae = send_event(new BulkAddEvent($dir)); $this->theme->display_upload_results($page, $bae->results); } } } public function onCliGen(CliGenEvent $event): void { $event->app->register('bulk-add') ->addArgument('directory', InputArgument::REQUIRED) ->setDescription('Import a directory of images') ->setCode(function (InputInterface $input, OutputInterface $output): int { $dir = $input->getArgument('directory'); $bae = send_event(new BulkAddEvent($dir)); foreach ($bae->results as $r) { if(is_a($r, UploadError::class)) { $output->writeln($r->name." failed: ".$r->error); } else { $output->writeln($r->name." ok"); } } return Command::SUCCESS; }); } public function onAdminBuilding(AdminBuildingEvent $event): void { $this->theme->display_admin_block(); } public function onBulkAdd(BulkAddEvent $event): void { if (is_dir($event->dir) && is_readable($event->dir)) { $event->results = add_dir($event->dir); } else { $event->results = [new UploadError($event->dir, "is not a readable directory")]; } } }