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) > 0) { $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