CronRemoveCommand.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cron\Console\Command;
  7. use Magento\Framework\Crontab\CrontabManagerInterface;
  8. use Symfony\Component\Console\Command\Command;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Magento\Framework\Console\Cli;
  12. use Magento\Framework\Exception\LocalizedException;
  13. /**
  14. * CronRemoveCommand removes Magento cron tasks
  15. */
  16. class CronRemoveCommand extends Command
  17. {
  18. /**
  19. * @var CrontabManagerInterface
  20. */
  21. private $crontabManager;
  22. /**
  23. * @param CrontabManagerInterface $crontabManager
  24. */
  25. public function __construct(CrontabManagerInterface $crontabManager)
  26. {
  27. $this->crontabManager = $crontabManager;
  28. parent::__construct();
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. protected function configure()
  34. {
  35. $this->setName('cron:remove')
  36. ->setDescription('Removes tasks from crontab');
  37. parent::configure();
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function execute(InputInterface $input, OutputInterface $output)
  43. {
  44. try {
  45. $this->crontabManager->removeTasks();
  46. } catch (LocalizedException $e) {
  47. $output->writeln('<error>' . $e->getMessage() . '</error>');
  48. return Cli::RETURN_FAILURE;
  49. }
  50. $output->writeln('<info>Magento cron tasks have been removed</info>');
  51. return Cli::RETURN_SUCCESS;
  52. }
  53. }