| @@ 11-38 (lines=28) @@ | ||
| 8 | use Symfony\Component\Console\Input\InputInterface; |
|
| 9 | use Symfony\Component\Console\Output\OutputInterface; |
|
| 10 | ||
| 11 | class CronDisableJobCommand extends ContainerAwareCommand |
|
| 12 | { |
|
| 13 | protected function configure() |
|
| 14 | { |
|
| 15 | $this->setName('cron:disable-job') |
|
| 16 | ->setDescription('Disables a cron job') |
|
| 17 | ->addArgument('job', InputArgument::REQUIRED, 'Name of the job to disable'); |
|
| 18 | } |
|
| 19 | ||
| 20 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 21 | { |
|
| 22 | $jobName = $input->getArgument('job'); |
|
| 23 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
|
| 24 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
|
| 25 | ||
| 26 | $job = $jobRepo->findOneByCommand($jobName); |
|
| 27 | if (!$job) { |
|
| 28 | $output->writeln("Couldn't find a job by the name of ".$jobName); |
|
| 29 | ||
| 30 | return CronJobResult::FAILED; |
|
| 31 | } |
|
| 32 | ||
| 33 | $job->setEnabled(false); |
|
| 34 | $em->flush(); |
|
| 35 | ||
| 36 | $output->writeln('Disabled cron job by the name of '.$jobName); |
|
| 37 | } |
|
| 38 | } |
|
| 39 | ||
| @@ 11-38 (lines=28) @@ | ||
| 8 | use Symfony\Component\Console\Input\InputInterface; |
|
| 9 | use Symfony\Component\Console\Output\OutputInterface; |
|
| 10 | ||
| 11 | class CronEnableJobCommand extends ContainerAwareCommand |
|
| 12 | { |
|
| 13 | protected function configure() |
|
| 14 | { |
|
| 15 | $this->setName('cron:enable-job') |
|
| 16 | ->setDescription('Enables a cron job') |
|
| 17 | ->addArgument('job', InputArgument::REQUIRED, 'Name of the job to enable'); |
|
| 18 | } |
|
| 19 | ||
| 20 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 21 | { |
|
| 22 | $jobName = $input->getArgument('job'); |
|
| 23 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
|
| 24 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
|
| 25 | ||
| 26 | $job = $jobRepo->findOneByCommand($jobName); |
|
| 27 | if (!$job) { |
|
| 28 | $output->writeln("Couldn't find a job by the name of ".$jobName); |
|
| 29 | ||
| 30 | return CronJobResult::FAILED; |
|
| 31 | } |
|
| 32 | ||
| 33 | $job->setEnabled(true); |
|
| 34 | $em->flush(); |
|
| 35 | ||
| 36 | $output->writeln('Enabled cron job by the name of '.$jobName); |
|
| 37 | } |
|
| 38 | } |
|
| 39 | ||