mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-27 18:10:42 +00:00
141 lines
6.4 KiB
PHP
141 lines
6.4 KiB
PHP
<?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);
|
|
|
|
if (!is_writable($settings->_cacheDir)) {
|
|
$output->writeln(sprintf("<error>The cache dir '%s' is not writable for the system user running this script.</error>", $settings->_cacheDir));
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$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 (isset($extconfs[$extname])) {
|
|
if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($extconfs[$extname]['version'], $extversion) > 0) {
|
|
$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
|