From c0a6cb5d34446b4c5f14a730605e2ecf7758fe8e Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sat, 15 Nov 2025 11:29:17 +0100 Subject: [PATCH] add new commands to download and list extensions from/in repository --- utils/Commands/DownloadextensionCommand.php | 135 ++++++++++++++++++ utils/Commands/RepositoryextensionCommand.php | 101 +++++++++++++ utils/console | 4 + 3 files changed, 240 insertions(+) create mode 100644 utils/Commands/DownloadextensionCommand.php create mode 100644 utils/Commands/RepositoryextensionCommand.php diff --git a/utils/Commands/DownloadextensionCommand.php b/utils/Commands/DownloadextensionCommand.php new file mode 100644 index 000000000..3aaebf2a5 --- /dev/null +++ b/utils/Commands/DownloadextensionCommand.php @@ -0,0 +1,135 @@ +settings = $settings; + $this->logger = $logger; + $this->translator = $translator; + $this->extmgr = $extmgr; + parent::__construct(); + } + + protected function configure() + { + $this->setName('ext:download') + ->setDescription('Download extension from repository') + ->setHelp('') + ->addOption('url', '', InputOption::VALUE_REQUIRED, 'Url of repository.', null) + ->addOption('name', '', InputOption::VALUE_REQUIRED, 'Name of extension.', null) + ->addOption('extversion', '', InputOption::VALUE_REQUIRED, 'Version of extension.', null) + ->addOption('no-upload', '', InputOption::VALUE_NONE, 'Just download extension file') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) : int + { + $settings = $this->settings; + $logger = $this->logger; + $translator = $this->translator; + $extmgr = $this->extmgr; + + $output->writeln("Using configuration from '".$settings->_configFilePath."'.", OutputInterface::VERBOSITY_VERBOSE); + + $reposurl = $input->getOption('url'); + if($reposurl) + $extmgr->setRepositoryUrl($reposurl); + + $extname = $input->getOption('name'); + if (!$extname) { + $output->writeln(sprintf("You must specify an extension name.")); + return Command::FAILURE; + } + $extversion = $input->getOption('extversion'); + $noupload = $input->getOption('no-upload'); + + /* Get a list of available extensions from the repository */ + if($ret = $extmgr->updateExtensionList('', true)) { + // list of installed extensions + $extconfs = $extmgr->getExtensionConfiguration(); + // list of extensions in repository, this will just return the + // latest version of an extension + $list = $extmgr->getExtensionList(); + if (isset($list[$extname])) { + /* if specific version is not requested, then take the + * last version of the extension. + */ + if (!$extversion) + $extversion = $list[$extname]['version']; + $extversions = $extmgr->getExtensionListByName($extname); + if (isset($extversions[$extversion])) { + if ($tmpfile = $extmgr->getExtensionFromRepository($extversions[$extversion]['filename'])) { + $output->writeln(sprintf("Downloaded extension file '%s'", $extversions[$extversion]['filename'])); + if (!$noupload) { + if ($extconfs[$extname]) { + if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($extconfs[$extname]['version'], $extversion)) { + $helper = new QuestionHelper(); + $question = new ConfirmationQuestion(sprintf("You are updating extension '%s' with an older version %s < %s. Do you want to proceed? ", $extname, $extversion, $extconfs[$extname]['version']), false); + if (!$helper->ask($input, $output, $question)) { + unlink($tmpfile); + return Command::SUCCESS; + } + } + $output->writeln(sprintf("Updating existing extension '%s' with version %s", $extname, $extversion)); + } else { + $output->writeln(sprintf("Installing new extension '%s' with version %s", $extname, $extversion)); + } + if (!$extmgr->updateExtension($tmpfile)) { + foreach ($extmgr->getErrorMsgs() as $msg) { + $output->writeln(sprintf("%s", $msg)); + } + unlink($tmpfile); + return Command::FAILURE; + } else { + unlink($tmpfile); + } + } else { + rename($tmpfile, $extversions[$extversion]['filename']); + } + } else { + $output->writeln(sprintf("Could not download file '%s'", $list[$extname]['filename'])); + } + return Command::SUCCESS; + } else { + $output->writeln(sprintf("Requested version '%s' of extension '%s' does not exist in repository.", $extversion, $extname)); + return Command::FAILURE; + } + } else { + $output->writeln(sprintf("Extension '%s' does not exist in repository.", $extname)); + return Command::FAILURE; + } + } else { + $output->writeln(sprintf("Could not get extension list from repository.", $filename)); + return Command::FAILURE; + } + } +} + +// vim: ts=4 sw=4 expandtab diff --git a/utils/Commands/RepositoryextensionCommand.php b/utils/Commands/RepositoryextensionCommand.php new file mode 100644 index 000000000..9d8a33f67 --- /dev/null +++ b/utils/Commands/RepositoryextensionCommand.php @@ -0,0 +1,101 @@ +settings = $settings; + $this->logger = $logger; + $this->translator = $translator; + $this->extmgr = $extmgr; + parent::__construct(); + } + + protected function configure() + { + $this->setName('ext:repository') + ->setDescription('Get list of extensions from repository') + ->setHelp('') + ->addOption('url', '', InputOption::VALUE_REQUIRED, 'Url of repository.', null) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) : int + { + $settings = $this->settings; + $logger = $this->logger; + $translator = $this->translator; + $extmgr = $this->extmgr; + + $output->writeln("Using configuration from '".$settings->_configFilePath."'.", OutputInterface::VERBOSITY_VERBOSE); + + $reposurl = $input->getOption('url'); + if($reposurl) + $extmgr->setRepositoryUrl($reposurl); + + /* Get a list of available extensions from the repository */ + if($ret = $extmgr->updateExtensionList('', true)) { +// $output->writeln(sprintf("Updated extension list from repository.")); + // list of installed extensions + $extconfs = $extmgr->getExtensionConfiguration(); + // list of extensions in repository, this will just return the + // latest version of an extension + $list = $extmgr->getExtensionList(); +// print_r($list); + $tabledata = []; + foreach($list as $extname=>$data) { + $extversions = $extmgr->getExtensionListByName($extname); +// print_r($extversions); + $allowedversions = []; + foreach($extversions as $version=>$extversion) { + $check = $extmgr->checkExtensionByName($extname, $extversion); + if ($check) { + $allowedversions[] = ''.$version.''; + } else { + $allowedversions[] = ''.$version.''; + } + } + $tabledata[$extname] = [ + $extname, + $data['title'], + new TableCell(implode("\n", $allowedversions), ['rowspan' => count($allowedversions)]), + isset($extconfs[$extname]['version']) ? $extconfs[$extname]['version'] : '']; + } + $table = new Table($output); + $table + ->setHeaders(['Name', 'Title', 'Rep. ver.', 'Inst. ver.']) + ->setRows($tabledata); + $table->render(); + return Command::SUCCESS; + } else { + $output->writeln(sprintf("Could not get extension list from repository.", $filename)); + return Command::FAILURE; + } + } +} + +// vim: ts=4 sw=4 expandtab diff --git a/utils/console b/utils/console index d402da61d..9dc4c8c4b 100755 --- a/utils/console +++ b/utils/console @@ -20,6 +20,8 @@ use Seeddms\Console\Commands\UploadextensionCommand; use Seeddms\Console\Commands\PackageextensionCommand; use Seeddms\Console\Commands\ReloadextensionCommand; use Seeddms\Console\Commands\CheckextensionCommand; +use Seeddms\Console\Commands\RepositoryextensionCommand; +use Seeddms\Console\Commands\DownloadextensionCommand; use Seeddms\Seeddms\Settings; use Seeddms\Seeddms\Translator; @@ -55,6 +57,8 @@ $application->add(new UploadextensionCommand($settings, $logger, $translator, $e $application->add(new PackageextensionCommand($settings, $logger, $translator, $extmgr)); $application->add(new ReloadextensionCommand($settings, $logger, $translator, $extmgr)); $application->add(new CheckextensionCommand($settings, $logger, $translator, $extmgr)); +$application->add(new RepositoryextensionCommand($settings, $logger, $translator, $extmgr)); +$application->add(new DownloadextensionCommand($settings, $logger, $translator, $extmgr)); if(isset($GLOBALS['SEEDDMS_HOOKS']['console'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['console'] as $hookObj) {