|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \Wicked\Timely\Command\Pause |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Bernhard Wick <[email protected]> |
|
15
|
|
|
* @copyright 2016 Bernhard Wick |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/wick-ed/timely |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Wicked\Timely\Command; |
|
21
|
|
|
|
|
22
|
|
|
use Symfony\Component\Console\Command\Command; |
|
23
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
25
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
27
|
|
|
use Wicked\Timely\Storage\StorageFactory; |
|
28
|
|
|
use Wicked\Timely\Entities\Pause as PauseEntity; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class for the "pause" command. Command used pause current tracking |
|
32
|
|
|
* |
|
33
|
|
|
* @author Bernhard Wick <[email protected]> |
|
34
|
|
|
* @copyright 2016 Bernhard Wick |
|
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
36
|
|
|
* @link https://github.com/wick-ed/timely |
|
37
|
|
|
*/ |
|
38
|
|
|
class Pause extends Command |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Constant for the "resume" option |
|
43
|
|
|
* |
|
44
|
|
|
* @var string OPTION_RESUME |
|
45
|
|
|
*/ |
|
46
|
|
|
const OPTION_RESUME = 'resume'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Configures the "pause" command |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
* |
|
53
|
|
|
* {@inheritDoc} |
|
54
|
|
|
* @see \Symfony\Component\Console\Command\Command::configure() |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function configure() |
|
57
|
|
|
{ |
|
58
|
|
|
$this |
|
59
|
|
|
->setName('pause') |
|
60
|
|
|
->setDescription('Pause current tracking') |
|
61
|
|
|
->addArgument( |
|
62
|
|
|
'comment', |
|
63
|
|
|
InputArgument::IS_ARRAY | InputArgument::OPTIONAL, |
|
64
|
|
|
'Comment why currently tracked task is paused' |
|
65
|
|
|
) |
|
66
|
|
|
->addOption( |
|
67
|
|
|
self::OPTION_RESUME, |
|
68
|
|
|
null, |
|
69
|
|
|
InputOption::VALUE_NONE, |
|
70
|
|
|
'Will resume the task tracked before a pause has happened' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Execute the command |
|
76
|
|
|
* |
|
77
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input The command input |
|
78
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output The command output |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
* |
|
82
|
|
|
* {@inheritDoc} |
|
83
|
|
|
* @see \Symfony\Component\Console\Command\Command::execute() |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
86
|
|
|
{ |
|
87
|
|
|
date_default_timezone_set('UTC'); |
|
88
|
|
|
try { |
|
89
|
|
|
// get the comment (if any) |
|
90
|
|
|
$comment = implode(' ', $input->getArgument('comment')); |
|
91
|
|
|
|
|
92
|
|
|
// check if we are resuming or pausing initially |
|
93
|
|
|
$resuming = false; |
|
94
|
|
|
$result = 'Pausing current tracking'; |
|
95
|
|
|
if ($input->getOption(self::OPTION_RESUME)) { |
|
96
|
|
|
$this->assertConsistentResume(); |
|
97
|
|
|
$resuming = true; |
|
98
|
|
|
$result = 'Resuming recent tracking'; |
|
99
|
|
|
} else { |
|
100
|
|
|
$this->assertConsistentPause(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// create a new pause instance |
|
104
|
|
|
$pause = new PauseEntity($comment, $resuming); |
|
105
|
|
|
|
|
106
|
|
|
// get the configured storage instance and store the booking |
|
107
|
|
|
$storage = StorageFactory::getStorage(); |
|
108
|
|
|
$storage->store($pause); |
|
109
|
|
|
|
|
110
|
|
|
} catch (\Exception $e) { |
|
111
|
|
|
$result = $e->getMessage(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
// write output |
|
115
|
|
|
$output->writeln($result); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Execute the command |
|
120
|
|
|
* |
|
121
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input The command input |
|
|
|
|
|
|
122
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output The command output |
|
|
|
|
|
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
* |
|
126
|
|
|
* {@inheritDoc} |
|
127
|
|
|
* @see \Symfony\Component\Console\Command\Command::execute() |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function assertConsistentResume () { |
|
130
|
|
|
$storage = StorageFactory::getStorage(); |
|
131
|
|
|
$lastBooking = $storage->retrieveLast(true); |
|
132
|
|
|
if ($lastBooking->getTicketId() !== PauseEntity::PAUSE_TAG_START) { |
|
133
|
|
|
throw new \Exception('Cannot resume without an ongoing pause (forgot to start?)'); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Execute the command |
|
139
|
|
|
* |
|
140
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input The command input |
|
|
|
|
|
|
141
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output The command output |
|
|
|
|
|
|
142
|
|
|
* |
|
143
|
|
|
* @return void |
|
144
|
|
|
* |
|
145
|
|
|
* {@inheritDoc} |
|
146
|
|
|
* @see \Symfony\Component\Console\Command\Command::execute() |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function assertConsistentPause () { |
|
149
|
|
|
$storage = StorageFactory::getStorage(); |
|
150
|
|
|
$lastBooking = $storage->retrieveLast(true);error_log(var_export($lastBooking, true)); |
|
151
|
|
|
if ($lastBooking instanceof PauseEntity) { |
|
152
|
|
|
throw new \Exception('There already seems to be an ongoing pause'); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.