Skip to content

Commit c7c951c

Browse files
authored
Merge branch 'master' into support-symfony5
2 parents 4940dfc + 46dedbe commit c7c951c

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

Command/ExecuteCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
119119
$noneExecution = true;
120120
foreach ($commands as $command) {
121121

122-
$this->em->refresh($this->em->merge($command));
122+
$this->em->refresh($this->em->find(ScheduledCommand::class, $command));
123123
if ($command->isDisabled() || $command->isLocked()) {
124124
continue;
125125
}
@@ -143,7 +143,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
143143
$output->writeln(
144144
'Command <comment>'.$command->getCommand().
145145
'</comment> should be executed - last execution : <comment>'.
146-
$command->getLastExecution()->format('d/m/Y H:i:s').'.</comment>'
146+
$command->getLastExecution()->format(\DateTimeInterface::ATOM).'.</comment>'
147147
);
148148

149149
if (!$input->getOption('dump')) {
@@ -181,7 +181,7 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
181181
$scheduledCommand = $notLockedCommand;
182182
$scheduledCommand->setLastExecution(new \DateTime());
183183
$scheduledCommand->setLocked(true);
184-
$scheduledCommand = $this->em->merge($scheduledCommand);
184+
$this->em->persist($scheduledCommand);
185185
$this->em->flush();
186186
$this->em->getConnection()->commit();
187187
} catch (\Exception $e) {
@@ -196,6 +196,9 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
196196

197197
return;
198198
}
199+
200+
$scheduledCommand = $this->em->find(ScheduledCommand::class, $scheduledCommand);
201+
199202
try {
200203
$command = $this->getApplication()->find($scheduledCommand->getCommand());
201204
} catch (\InvalidArgumentException $e) {
@@ -247,10 +250,10 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
247250
$this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
248251
}
249252

250-
$scheduledCommand = $this->em->merge($scheduledCommand);
251253
$scheduledCommand->setLastReturnCode($result);
252254
$scheduledCommand->setLocked(false);
253255
$scheduledCommand->setExecuteImmediately(false);
256+
$this->em->persist($scheduledCommand);
254257
$this->em->flush();
255258

256259
/*

Command/MonitorCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
114114
$command->getName(),
115115
$command->getLastReturnCode(),
116116
$command->getLocked(),
117-
$command->getLastExecution()->format('Y-m-d H:i')
117+
$command->getLastExecution()->format(\DateTimeInterface::ATOM)
118118
);
119119
}
120120

Resources/doc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ See the [Usage](#usage) section to have more information
100100

101101
### 4 - Available configuration
102102

103-
Here is the default bundle configuration.
103+
Here is the default bundle configuration. The flex recipe will create the scheduler.yaml file in your packages directory where you can change the base configuration.
104104

105105
```yaml
106106
jmose_command_scheduler:

Tests/Constraints/CronExpressionValidatorTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ protected function createValidator()
2222
*/
2323
public function testValidValues($value)
2424
{
25-
$this->validator->validate($value, new CronExpression());
25+
$this->validator->validate($value, new CronExpression(array('message' => '')));
2626

2727
$this->assertNoViolation();
2828
}
2929

3030
public function getValidValues()
3131
{
3232
return array(
33-
array('* * * * * *'),
33+
array('* * * * *'),
3434
array('@daily'),
3535
array('@yearly'),
3636
array('*/10 * * * *'),
37+
array('* * * * * *'), // Remove this value from valid options at 3.0 release.
3738
);
3839
}
3940

@@ -61,6 +62,10 @@ public function getInvalidValues()
6162
array('*/5 * * * ?'),
6263
array('sometimes'),
6364
array('never'),
65+
array('*****'),
66+
// Uncomment following values at 3.0 release.
67+
// array('* * * * * * *'),
68+
// array('* * * * * *'),
6469
);
6570
}
6671
}

Validator/Constraints/CronExpressionValidator.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@ class CronExpressionValidator extends ConstraintValidator
2222
*/
2323
public function validate($value, Constraint $constraint)
2424
{
25-
$value = (string)$value;
25+
$value = (string) $value;
2626

27-
if (null === $value || '' === $value) {
27+
if ('' === $value) {
2828
return;
2929
}
3030

3131
try {
3232
CronExpressionLib::factory($value);
3333
} catch (\InvalidArgumentException $e) {
34+
// This condition is required in order to respect BC with "mtdowling/cron-expression".
35+
// It must be removed at 3.0 release.
36+
// @see https://github.com/mtdowling/cron-expression/commit/56e89730e60a0e945bf4ea10c48b80a406c7e7a0.
37+
if ('6 is not a valid position' === $e->getMessage()) {
38+
@trigger_error($e->getMessage().' and its support is deprecated since jmose/command-scheduler-bundle 2.x.', E_USER_DEPRECATED);
39+
40+
return;
41+
}
42+
3443
$this->context->addViolation($constraint->message, array(), $value);
3544
}
36-
37-
return;
3845
}
3946
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"liip/functional-test-bundle": "^4.2",
3434
"symfony/css-selector": "^3.4|^4.0|^5.0",
3535
"symfony/security-bundle": "^3.4|^4.0|^5.0",
36-
"liip/test-fixtures-bundle": "^1.0.0"
36+
"liip/test-fixtures-bundle": "^1.4.0"
3737
},
3838
"suggest": {
3939
"ext-pcntl": "For using the scheduler daemon"

0 commit comments

Comments
 (0)