setName("apply"); $this->setDescription("Apply a hotfix from a file or the Internet"); $this->addOption("insecure", "I", InputOption::VALUE_NONE, "Disable signature checks. Don't use unless you know what you are doing!"); $this->addOption("preview", "p", InputOption::VALUE_NONE, "Only preview the hotfix script, don't apply anything"); $this->addArgument("hotfix", InputArgument::OPTIONAL, "The identifier, path or filename of the hotfix"); } protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $fix = $input->getArgument("hotfix"); $insecure = $input->getOption("insecure"); $loader = new Loader(); if (!$fix) { $loaders = $loader->getLoaders(); $output->writeln("Supported loaders:\n"); foreach ($loaders as $loader) { $output->writeln(" * ".$loader->getInfo()); } return; } $output->writeln("Reading hotfix {$fix}..."); try { $hotfix = $loader->load($fix, $insecure); } catch (\Exception $e) { $output->writeln("Error: ".$e->getMessage().""); return; } if (!$hotfix) { $output->writeln("Could not load hotfix"); return; } $output->writeln(""); if (($signer = $hotfix->getSignedBy())) { $keyid = $hotfix->getKeyId(); $output->writeln("Hotfix has good signature from {$signer} (keyid {$keyid})"); } else { $output->writeln("Warning: Hotfix is not signed or signature not valid!"); } $requires = $hotfix->getRequirements(); if (count($requires)>0) { $engine = new ExpressionLanguage(); $facts = Facts::getSystemFacts()->getFacts(); while (true) { $expr = array_shift($requires); $ret = $engine->evaluate($expr, $facts); if ($ret) { //$output->writeln("Hotfix is compatible with the current distribution"); break; } if (count($requires)==0) { $output->writeln("Error: This hotfix it not compatible with the current distribution"); return false; } } //} else { //$output->writeln("Hotfix indicates universal compatibility."); } $output->writeln(""); $output->writeln(" Hotfix: ".$hotfix->getName().""); $output->writeln(" Author: ".$hotfix->getAuthor().""); $info = explode("\n",wordwrap(trim($hotfix->getInfo()), 60)); $info = "".join("\n ", $info).""; $output->writeln(" Info: ".$info); $output->writeln(""); if ($input->getOption("preview")) { $output->writeln("This is the script that will be executed:"); $body = $hotfix->getBody(); $body = " ".join("\n ", explode("\n",$body)).""; $output->writeln($body); return; } $helper = $this->getHelper("question"); $question = new ConfirmationQuestion("Do you want to apply this hotfix? [y/N] ", false); if (!$helper->ask($input, $output, $question)) { return; } $output->writeln("\nApplying hotfix...\n"); try { $hotfix->apply(); } catch (\Exception $e) { $output->writeln("\nError: ".$e->getMessage().""); } $output->writeln("\nHotfix applied successfully"); } }