|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Commander project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Daniel Schröder <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace GravityMedia\Commander\Console\Command; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* New command class. |
|
17
|
|
|
* |
|
18
|
|
|
* @package GravityMedia\Commander\Console\Command |
|
19
|
|
|
*/ |
|
20
|
|
|
class NewCommand extends Command |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::configure(); |
|
28
|
|
|
|
|
29
|
|
|
$this |
|
30
|
|
|
->setName('task:new') |
|
31
|
|
|
->setDescription('Create a new task') |
|
32
|
|
|
->addArgument( |
|
33
|
|
|
'commandline', |
|
34
|
|
|
InputArgument::REQUIRED, |
|
35
|
|
|
'The commandline to run with the task' |
|
36
|
|
|
) |
|
37
|
|
|
->addOption( |
|
38
|
|
|
'priority', |
|
39
|
|
|
null, |
|
40
|
|
|
InputOption::VALUE_REQUIRED, |
|
41
|
|
|
'The task priority' |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
|
|
$taskManager = $this->getCommander()->getTaskManager(); |
|
51
|
|
|
|
|
52
|
|
|
$commandline = $input->getArgument('commandline'); |
|
53
|
|
|
$task = $taskManager->findNextTask(['commandline' => $commandline]); |
|
54
|
|
|
|
|
55
|
|
|
$priority = filter_var($input->getOption('priority'), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
56
|
|
|
|
|
57
|
|
|
if (null === $task) { |
|
58
|
|
|
$task = $taskManager->newTask($commandline, $priority); |
|
59
|
|
|
$output->writeln(sprintf('Created new task %s', $task->getEntity()->getId())); |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($priority !== $task->getEntity()->getPriority()) { |
|
64
|
|
|
$task->prioritize($priority); |
|
65
|
|
|
$output->writeln(sprintf('Updated task priority of %s', $task->getEntity()->getId())); |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$output->writeln(sprintf('Task %s already present, ignoring', $task->getEntity()->getId())); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|