mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-27 18:10:42 +00:00
output number in updatable, installable extensions, code cleanup
This commit is contained in:
parent
886a5eaf62
commit
929a2acd25
|
|
@ -68,23 +68,21 @@ class UpdateextensionCommand extends Command
|
||||||
$installs = [];
|
$installs = [];
|
||||||
/* Get a list of available extensions from the repository */
|
/* Get a list of available extensions from the repository */
|
||||||
if($ret = $extmgr->updateExtensionList('', true)) {
|
if($ret = $extmgr->updateExtensionList('', true)) {
|
||||||
// $output->writeln(sprintf("<info>Updated extension list from repository.</info>"));
|
|
||||||
// list of installed extensions
|
// list of installed extensions
|
||||||
$extconfs = $extmgr->getExtensionConfiguration();
|
$extconfs = $extmgr->getExtensionConfiguration();
|
||||||
// list of extensions in repository, this will just return the
|
// list of extensions in repository, this will just return the
|
||||||
// latest version of an extension
|
// latest version of an extension
|
||||||
$list = $extmgr->getExtensionList();
|
$list = $extmgr->getExtensionList();
|
||||||
// print_r($list);
|
|
||||||
foreach($list as $extname=>$data) {
|
foreach($list as $extname=>$data) {
|
||||||
$extversions = $extmgr->getExtensionListByName($extname);
|
$extversions = $extmgr->getExtensionListByName($extname);
|
||||||
// print_r($extversions);
|
// $updates[$extname] = [];
|
||||||
$updates[$extname] = [];
|
// $installs[$extname] = [];
|
||||||
$installs[$extname] = [];
|
|
||||||
$allowedversions = [];
|
|
||||||
foreach($extversions as $version=>$extversion) {
|
foreach($extversions as $version=>$extversion) {
|
||||||
|
/* Only version which pass the check will be offered for
|
||||||
|
* update or install.
|
||||||
|
*/
|
||||||
$check = $extmgr->checkExtensionByName($extname, $extversion);
|
$check = $extmgr->checkExtensionByName($extname, $extversion);
|
||||||
if ($check) {
|
if ($check) {
|
||||||
$allowedversions[] = '<info>'.$version.'</info>';
|
|
||||||
if (isset($extconfs[$extname])) {
|
if (isset($extconfs[$extname])) {
|
||||||
if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($version, $extconfs[$extname]['version']) > 0) {
|
if (\Seeddms\Seeddms\ExtensionMgr::cmpVersion($version, $extconfs[$extname]['version']) > 0) {
|
||||||
$updates[$extname][$version] = $extversion;
|
$updates[$extname][$version] = $extversion;
|
||||||
|
|
@ -92,60 +90,64 @@ class UpdateextensionCommand extends Command
|
||||||
} else {
|
} else {
|
||||||
$installs[$extname][$version] = $extversion;
|
$installs[$extname][$version] = $extversion;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$allowedversions[] = '<error>'.$version.'</error>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$helper = new QuestionHelper();
|
$helper = new QuestionHelper();
|
||||||
foreach($updates as $extname=>$update) {
|
if($updates) {
|
||||||
$availableversions = array_keys($update);
|
$output->writeln(sprintf("<options=bold>%d extensions can be updated.</>", count($updates)));
|
||||||
if ($update) {
|
foreach($updates as $extname=>$update) {
|
||||||
$output->writeln(sprintf("<comment>Extension '%s' can be updated from %s to %s.</comment>", $extname, $extconfs[$extname]['version'], implode(', ', $availableversions)));
|
$availableversions = array_keys($update);
|
||||||
$question = new Question(sprintf("<question>Enter version to update:</question> "), '');
|
if ($update) {
|
||||||
if ($answer = $helper->ask($input, $output, $question)) {
|
$output->writeln(sprintf("<comment>Extension '%s' can be updated from %s to %s.</comment>", $extname, $extconfs[$extname]['version'], implode(', ', $availableversions)));
|
||||||
if (in_array($answer, $availableversions)) {
|
$question = new Question(sprintf("<question>Enter version to update:</question> "), '');
|
||||||
$output->writeln(sprintf("<info>Update extension '%s' to version %s.</info>", $extname, $answer));
|
if ($answer = $helper->ask($input, $output, $question)) {
|
||||||
if ($tmpfile = $extmgr->getExtensionFromRepository($update[$answer]['filename'])) {
|
if (in_array($answer, $availableversions)) {
|
||||||
|
$output->writeln(sprintf("<info>Update extension '%s' to version %s.</info>", $extname, $answer));
|
||||||
|
if ($tmpfile = $extmgr->getExtensionFromRepository($update[$answer]['filename'])) {
|
||||||
|
|
||||||
if (0&&!$extmgr->updateExtension($tmpfile)) {
|
if (0&&!$extmgr->updateExtension($tmpfile)) {
|
||||||
foreach ($extmgr->getErrorMsgs() as $msg) {
|
foreach ($extmgr->getErrorMsgs() as $msg) {
|
||||||
$output->writeln(sprintf("<error>%s</error>", $msg));
|
$output->writeln(sprintf("<error>%s</error>", $msg));
|
||||||
|
}
|
||||||
|
unlink($tmpfile);
|
||||||
|
return Command::FAILURE;
|
||||||
|
} else {
|
||||||
|
unlink($tmpfile);
|
||||||
}
|
}
|
||||||
unlink($tmpfile);
|
|
||||||
return Command::FAILURE;
|
|
||||||
} else {
|
|
||||||
unlink($tmpfile);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$output->writeln(sprintf("<error>Invalid version %s.</error>", $answer));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$output->writeln(sprintf("<error>Invalid version %s.</error>", $answer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($installs as $extname=>$install) {
|
if($installs) {
|
||||||
$availableversions = array_keys($install);
|
$output->writeln(sprintf("<options=bold>%d extensions can be installed.</>", count($installs)));
|
||||||
if ($install) {
|
foreach($installs as $extname=>$install) {
|
||||||
$output->writeln(sprintf("<comment>Extension '%s' can be installed as version %s.</comment>", $extname, implode(', ', $availableversions)));
|
$availableversions = array_keys($install);
|
||||||
$question = new Question(sprintf("<question>Enter version to install:</question> "), '');
|
if ($install) {
|
||||||
if ($answer = $helper->ask($input, $output, $question)) {
|
$output->writeln(sprintf("<comment>Extension '%s' can be installed as version %s.</comment>", $extname, implode(', ', $availableversions)));
|
||||||
if (in_array($answer, $availableversions)) {
|
$question = new Question(sprintf("<question>Enter version to install:</question> "), '');
|
||||||
$output->writeln(sprintf("<info>Install extension '%s' to version %s.</info>", $extname, $answer));
|
if ($answer = $helper->ask($input, $output, $question)) {
|
||||||
if ($tmpfile = $extmgr->getExtensionFromRepository($install[$answer]['filename'])) {
|
if (in_array($answer, $availableversions)) {
|
||||||
|
$output->writeln(sprintf("<info>Install extension '%s' to version %s.</info>", $extname, $answer));
|
||||||
|
if ($tmpfile = $extmgr->getExtensionFromRepository($install[$answer]['filename'])) {
|
||||||
|
|
||||||
if (0&&!$extmgr->updateExtension($tmpfile)) {
|
if (0&&!$extmgr->updateExtension($tmpfile)) {
|
||||||
foreach ($extmgr->getErrorMsgs() as $msg) {
|
foreach ($extmgr->getErrorMsgs() as $msg) {
|
||||||
$output->writeln(sprintf("<error>%s</error>", $msg));
|
$output->writeln(sprintf("<error>%s</error>", $msg));
|
||||||
|
}
|
||||||
|
unlink($tmpfile);
|
||||||
|
return Command::FAILURE;
|
||||||
|
} else {
|
||||||
|
unlink($tmpfile);
|
||||||
}
|
}
|
||||||
unlink($tmpfile);
|
|
||||||
return Command::FAILURE;
|
|
||||||
} else {
|
|
||||||
unlink($tmpfile);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$output->writeln(sprintf("<error>Invalid version %s.</error>", $answer));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$output->writeln(sprintf("<error>Invalid version %s.</error>", $answer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user