1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Glooby\TaskBundle\Command\Task; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\NoResultException; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Emil Kilhage |
14
|
|
|
*/ |
15
|
|
|
class RunCommand extends ContainerAwareCommand |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Configures the current command. |
19
|
|
|
*/ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this->setName('task:run'); |
23
|
|
|
$this->addArgument('service', InputArgument::OPTIONAL); |
24
|
|
|
$this->addOption('silent', 'S', InputOption::VALUE_NONE); |
25
|
|
|
$this->addOption('id', null, InputOption::VALUE_REQUIRED); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
|
|
$runner = $this->getContainer()->get('glooby_task.task_runner'); |
34
|
|
|
$runner->setOutput($output); |
35
|
|
|
|
36
|
|
|
if ($input->getOption('id')) { |
37
|
|
|
$task = $this->getContainer() |
38
|
|
|
->get('doctrine') |
39
|
|
|
->getManager() |
40
|
|
|
->getRepository('GloobyTaskBundle:QueuedTask') |
41
|
|
|
->find($input->getOption('id')); |
42
|
|
|
|
43
|
|
|
if (null === $task) { |
44
|
|
|
throw new NoResultException(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$runner->run($task); |
48
|
|
|
} else { |
49
|
|
|
$response = $runner->runTask($input->getArgument('service')); |
50
|
|
|
|
51
|
|
|
if (!$input->getOption('silent')) { |
52
|
|
|
$output->writeln($response); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|