mirror of
https://git.code.sf.net/p/seeddms/code
synced 2026-01-16 06:16:45 +00:00
add new commands to download and list extensions from/in repository
This commit is contained in:
parent
851d338d4a
commit
c0a6cb5d34
135
utils/Commands/DownloadextensionCommand.php
Normal file
135
utils/Commands/DownloadextensionCommand.php
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
namespace Seeddms\Console\Commands;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
use Seeddms\Seeddms\Settings;
|
||||
use Seeddms\Seeddms\Translator;
|
||||
use SeedDMS_Core_File;
|
||||
use SeedDMS_View_Common;
|
||||
use SeedDMS_Extension_Mgr;
|
||||
use Log_file;
|
||||
|
||||
class DownloadextensionCommand extends Command
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
protected $logger;
|
||||
|
||||
protected $translator;
|
||||
|
||||
protected $extmgr;
|
||||
|
||||
public function __construct(Settings $settings, Log_file $logger, Translator $translator, SeedDMS_Extension_Mgr $extmgr)
|
||||
{
|
||||
$this->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("<comment>Using configuration from '".$settings->_configFilePath."'.</comment>", OutputInterface::VERBOSITY_VERBOSE);
|
||||
|
||||
$reposurl = $input->getOption('url');
|
||||
if($reposurl)
|
||||
$extmgr->setRepositoryUrl($reposurl);
|
||||
|
||||
$extname = $input->getOption('name');
|
||||
if (!$extname) {
|
||||
$output->writeln(sprintf("<error>You must specify an extension name.</error>"));
|
||||
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("<info>Downloaded extension file '%s'</info>", $extversions[$extversion]['filename']));
|
||||
if (!$noupload) {
|
||||
if ($extconfs[$extname]) {
|
||||
if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($extconfs[$extname]['version'], $extversion)) {
|
||||
$helper = new QuestionHelper();
|
||||
$question = new ConfirmationQuestion(sprintf("<question>You are updating extension '%s' with an older version %s < %s. Do you want to proceed?</question> ", $extname, $extversion, $extconfs[$extname]['version']), false);
|
||||
if (!$helper->ask($input, $output, $question)) {
|
||||
unlink($tmpfile);
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
$output->writeln(sprintf("<info>Updating existing extension '%s' with version %s</info>", $extname, $extversion));
|
||||
} else {
|
||||
$output->writeln(sprintf("<info>Installing new extension '%s' with version %s</info>", $extname, $extversion));
|
||||
}
|
||||
if (!$extmgr->updateExtension($tmpfile)) {
|
||||
foreach ($extmgr->getErrorMsgs() as $msg) {
|
||||
$output->writeln(sprintf("<error>%s</error>", $msg));
|
||||
}
|
||||
unlink($tmpfile);
|
||||
return Command::FAILURE;
|
||||
} else {
|
||||
unlink($tmpfile);
|
||||
}
|
||||
} else {
|
||||
rename($tmpfile, $extversions[$extversion]['filename']);
|
||||
}
|
||||
} else {
|
||||
$output->writeln(sprintf("<error>Could not download file '%s'</error>", $list[$extname]['filename']));
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$output->writeln(sprintf("<error>Requested version '%s' of extension '%s' does not exist in repository.</error>", $extversion, $extname));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} else {
|
||||
$output->writeln(sprintf("<error>Extension '%s' does not exist in repository.</error>", $extname));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} else {
|
||||
$output->writeln(sprintf("<error>Could not get extension list from repository.</error>", $filename));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4 sw=4 expandtab
|
||||
101
utils/Commands/RepositoryextensionCommand.php
Normal file
101
utils/Commands/RepositoryextensionCommand.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
namespace Seeddms\Console\Commands;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
|
||||
use Seeddms\Seeddms\Settings;
|
||||
use Seeddms\Seeddms\Translator;
|
||||
use SeedDMS_Core_File;
|
||||
use SeedDMS_View_Common;
|
||||
use SeedDMS_Extension_Mgr;
|
||||
use Log_file;
|
||||
|
||||
class RepositoryextensionCommand extends Command
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
protected $logger;
|
||||
|
||||
protected $translator;
|
||||
|
||||
protected $extmgr;
|
||||
|
||||
public function __construct(Settings $settings, Log_file $logger, Translator $translator, SeedDMS_Extension_Mgr $extmgr)
|
||||
{
|
||||
$this->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("<comment>Using configuration from '".$settings->_configFilePath."'.</comment>", 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("<info>Updated extension list from repository.</info>"));
|
||||
// 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[] = '<info>'.$version.'</info>';
|
||||
} else {
|
||||
$allowedversions[] = '<error>'.$version.'</error>';
|
||||
}
|
||||
}
|
||||
$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("<error>Could not get extension list from repository.</error>", $filename));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4 sw=4 expandtab
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user