settings = $settings;
$this->logger = $logger;
$this->translator = $translator;
$this->extmgr = $extmgr;
parent::__construct();
}
protected function configure()
{
$this->setName('ext:update')
->setDescription('Check for extension upates')
->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);
if (!is_writable($settings->_cacheDir)) {
$output->writeln(sprintf("The cache dir '%s' is not writable for the system user running this script.", $settings->_cacheDir));
return Command::FAILURE;
}
$reposurl = $input->getOption('url');
if($reposurl)
$extmgr->setRepositoryUrl($reposurl);
$updates = [];
$installs = [];
/* 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();
foreach($list as $extname=>$data) {
$extversions = $extmgr->getExtensionListByName($extname);
// $updates[$extname] = [];
// $installs[$extname] = [];
foreach($extversions as $version=>$extversion) {
/* Only version which pass the check will be offered for
* update or install.
*/
$check = $extmgr->checkExtensionByName($extname, $extversion);
if ($check) {
if (isset($extconfs[$extname])) {
if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($version, $extconfs[$extname]['version']) > 0) {
$updates[$extname][$version] = $extversion;
}
} else {
$installs[$extname][$version] = $extversion;
}
}
}
}
$helper = new QuestionHelper();
if($updates) {
$output->writeln(sprintf("%d extensions can be updated.>", count($updates)));
foreach($updates as $extname=>$update) {
$availableversions = array_keys($update);
if ($update) {
$output->writeln(sprintf("Extension '%s' can be updated from %s to %s.", $extname, $extconfs[$extname]['version'], implode(', ', $availableversions)));
$question = new Question(sprintf("Enter version to update: "), '');
if ($answer = $helper->ask($input, $output, $question)) {
if (in_array($answer, $availableversions)) {
$output->writeln(sprintf("Update extension '%s' to version %s.", $extname, $answer));
if ($tmpfile = $extmgr->getExtensionFromRepository($update[$answer]['filename'])) {
if (0&&!$extmgr->updateExtension($tmpfile)) {
foreach ($extmgr->getErrorMsgs() as $msg) {
$output->writeln(sprintf("%s", $msg));
}
unlink($tmpfile);
return Command::FAILURE;
} else {
unlink($tmpfile);
}
}
} else {
$output->writeln(sprintf("Invalid version %s.", $answer));
}
}
}
}
}
if($installs) {
$output->writeln(sprintf("%d extensions can be installed.>", count($installs)));
foreach($installs as $extname=>$install) {
$availableversions = array_keys($install);
if ($install) {
$output->writeln(sprintf("Extension '%s' can be installed as version %s.", $extname, implode(', ', $availableversions)));
$question = new Question(sprintf("Enter version to install: "), '');
if ($answer = $helper->ask($input, $output, $question)) {
if (in_array($answer, $availableversions)) {
$output->writeln(sprintf("Install extension '%s' to version %s.", $extname, $answer));
if ($tmpfile = $extmgr->getExtensionFromRepository($install[$answer]['filename'])) {
if (0&&!$extmgr->updateExtension($tmpfile)) {
foreach ($extmgr->getErrorMsgs() as $msg) {
$output->writeln(sprintf("%s", $msg));
}
unlink($tmpfile);
return Command::FAILURE;
} else {
unlink($tmpfile);
}
}
} else {
$output->writeln(sprintf("Invalid version %s.", $answer));
}
}
}
}
}
return Command::SUCCESS;
} else {
$output->writeln(sprintf("Could not get extension list from repository."));
return Command::FAILURE;
}
}
}
// vim: ts=4 sw=4 expandtab