| @@ 36-109 (lines=74) @@ | ||
| 33 | * @author Josef Kříž <[email protected]> |
|
| 34 | * @author Adam Kadlec <[email protected]> |
|
| 35 | */ |
|
| 36 | class DisableCommand extends Command |
|
| 37 | { |
|
| 38 | /** |
|
| 39 | * @return void |
|
| 40 | */ |
|
| 41 | protected function configure() |
|
| 42 | { |
|
| 43 | $this |
|
| 44 | ->setName('ipub:packages:disable') |
|
| 45 | ->addArgument('package', Input\InputArgument::REQUIRED, 'Package name') |
|
| 46 | ->addOption('noconfirm', NULL, Input\InputOption::VALUE_NONE, 'do not ask for any confirmation') |
|
| 47 | ->setDescription('Disable package.'); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param Input\InputInterface $input |
|
| 52 | * @param Output\OutputInterface $output |
|
| 53 | * |
|
| 54 | * @return void |
|
| 55 | */ |
|
| 56 | protected function execute(Input\InputInterface $input, Output\OutputInterface $output) |
|
| 57 | { |
|
| 58 | // Register available |
|
| 59 | foreach ($this->packageManager->registerAvailable() as $item) { |
|
| 60 | foreach ($item as $name => $action) { |
|
| 61 | $output->writeln(sprintf('<info>%s : %s</info>', $action, $name)); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | $package = $this->repository->findPackage($input->getArgument('package')); |
|
| 66 | ||
| 67 | try { |
|
| 68 | $problem = $this->packageManager->testDisable($package); |
|
| 69 | ||
| 70 | } catch (Exceptions\InvalidArgumentException $e) { |
|
| 71 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
| 72 | ||
| 73 | return; |
|
| 74 | } |
|
| 75 | ||
| 76 | if (!$input->getOption('noconfirm') && count($problem->getSolutions()) > 0) { |
|
| 77 | foreach ($problem->getSolutions() as $job) { |
|
| 78 | $output->writeln(sprintf('<info>%s : %s</info>', $job->getAction(), $job->getPackage()->getName())); |
|
| 79 | } |
|
| 80 | ||
| 81 | $output->writeln(sprintf('<info>disabling : %s</info>', $package->getName())); |
|
| 82 | ||
| 83 | $dialog = $this->getHelperSet()->get('dialog'); |
|
| 84 | if (!$dialog->askConfirmation($output, '<question>Continue with this actions? [y/N]</question> ', FALSE)) { |
|
| 85 | return; |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||
| 89 | try { |
|
| 90 | foreach ($problem->getSolutions() as $job) { |
|
| 91 | if ($job->getAction() === DependencyResolver\Job::ACTION_ENABLE) { |
|
| 92 | $this->packageManager->disable($job->getPackage()); |
|
| 93 | $output->writeln(sprintf('Package \'%s\' has been enabled.', $job->getPackage()->getName())); |
|
| 94 | ||
| 95 | } elseif ($job->getAction() === DependencyResolver\Job::ACTION_DISABLE) { |
|
| 96 | $this->packageManager->enable($job->getPackage()); |
|
| 97 | $output->writeln(sprintf('Package \'%s\' has been disabled.', $job->getPackage()->getName())); |
|
| 98 | ||
| 99 | } |
|
| 100 | } |
|
| 101 | ||
| 102 | $this->packageManager->disable($package); |
|
| 103 | $output->writeln(sprintf('Package \'%s\' has been disabled.', $input->getArgument('package'))); |
|
| 104 | ||
| 105 | } catch (Exceptions\InvalidArgumentException $e) { |
|
| 106 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
| 107 | } |
|
| 108 | } |
|
| 109 | } |
|
| 110 | ||
| @@ 36-110 (lines=75) @@ | ||
| 33 | * @author Josef Kříž <[email protected]> |
|
| 34 | * @author Adam Kadlec <[email protected]> |
|
| 35 | */ |
|
| 36 | final class EnableCommand extends Command |
|
| 37 | { |
|
| 38 | /** |
|
| 39 | * @return void |
|
| 40 | */ |
|
| 41 | protected function configure() |
|
| 42 | { |
|
| 43 | $this |
|
| 44 | ->setName('ipub:packages:enable') |
|
| 45 | ->addArgument('package', Input\InputArgument::REQUIRED, 'Package name') |
|
| 46 | ->addOption('noconfirm', NULL, Input\InputOption::VALUE_NONE, 'do not ask for any confirmation') |
|
| 47 | ->setDescription('Enable package.'); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param Input\InputInterface $input |
|
| 52 | * @param Output\OutputInterface $output |
|
| 53 | * |
|
| 54 | * @return void |
|
| 55 | */ |
|
| 56 | protected function execute(Input\InputInterface $input, Output\OutputInterface $output) |
|
| 57 | { |
|
| 58 | // Register available |
|
| 59 | foreach ($this->packageManager->registerAvailable() as $item) { |
|
| 60 | foreach ($item as $name => $action) { |
|
| 61 | $output->writeln(sprintf('<info>%s : %s</info>', $action, $name)); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | $package = $this->repository->findPackage($input->getArgument('package')); |
|
| 66 | ||
| 67 | try { |
|
| 68 | $problem = $this->packageManager->testEnable($package); |
|
| 69 | ||
| 70 | } catch (Exceptions\InvalidArgumentException $e) { |
|
| 71 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
| 72 | ||
| 73 | return; |
|
| 74 | } |
|
| 75 | ||
| 76 | if (!$input->getOption('noconfirm') && count($problem->getSolutions()) > 0) { |
|
| 77 | $output->writeln(sprintf('<info>enabling : %s</info>', $package->getName())); |
|
| 78 | ||
| 79 | foreach ($problem->getSolutions() as $job) { |
|
| 80 | $output->writeln(sprintf('<info>%s : %s</info>', $job->getAction(), $job->getPackage()->getName())); |
|
| 81 | } |
|
| 82 | ||
| 83 | $dialog = $this->getHelperSet()->get('dialog'); |
|
| 84 | ||
| 85 | if (!$dialog->askConfirmation($output, '<question>Continue with this actions? [y/N]</question> ', FALSE)) { |
|
| 86 | return; |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||
| 90 | try { |
|
| 91 | foreach ($problem->getSolutions() as $job) { |
|
| 92 | if ($job->getAction() === DependencyResolver\Job::ACTION_ENABLE) { |
|
| 93 | $this->packageManager->enable($job->getPackage()); |
|
| 94 | $output->writeln(sprintf('Package \'%s\' has been enabled.', $job->getPackage()->getName())); |
|
| 95 | ||
| 96 | } elseif ($job->getAction() === DependencyResolver\Job::ACTION_DISABLE) { |
|
| 97 | $this->packageManager->disable($job->getPackage()); |
|
| 98 | $output->writeln(sprintf('Package \'%s\' has been disabled.', $job->getPackage()->getName())); |
|
| 99 | } |
|
| 100 | } |
|
| 101 | ||
| 102 | $this->packageManager->enable($package); |
|
| 103 | ||
| 104 | $output->writeln(sprintf('Package \'%s\' has been enabled.', $input->getArgument('package'))); |
|
| 105 | ||
| 106 | } catch (Exceptions\InvalidArgumentException $e) { |
|
| 107 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
| 108 | } |
|
| 109 | } |
|
| 110 | } |
|
| 111 | ||