forked from j-guyon/CommandSchedulerBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadScheduledCommandData.php
74 lines (66 loc) · 2.32 KB
/
LoadScheduledCommandData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace JMose\CommandSchedulerBundle\Fixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Persistence\ObjectManager;
use JMose\CommandSchedulerBundle\Entity\ScheduledCommand;
/**
* Class LoadScheduledCommandData.
*
* @author Julien Guyon <julienguyon@hotmail.com>
*/
class LoadScheduledCommandData implements FixtureInterface
{
/**
* @var ObjectManager
*/
protected $manager;
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$this->manager = $manager;
$now = new \DateTime();
$today = clone $now;
$beforeYesterday = $now->modify('-2 days');
$this->createScheduledCommand('one', 'debug:container', '--help', '@daily', 'one.log', 100, $beforeYesterday);
$this->createScheduledCommand('two', 'debug:container', '', '@daily', 'two.log', 80, $beforeYesterday, true);
$this->createScheduledCommand('three', 'debug:container', '', '@daily', 'three.log', 60, $today, false, true);
$this->createScheduledCommand('four', 'debug:router', '', '@daily', 'four.log', 40, $today, false, false, true, -1);
}
/**
* Create a new ScheduledCommand in database.
*
* @param $name
* @param $command
* @param $arguments
* @param $cronExpression
* @param $logFile
* @param $priority
* @param $lastExecution
* @param bool $locked
* @param bool $disabled
* @param bool $executeNow
* @param int $lastReturnCode
*/
protected function createScheduledCommand(
$name, $command, $arguments, $cronExpression, $logFile, $priority, $lastExecution,
$locked = false, $disabled = false, $executeNow = false, $lastReturnCode = null)
{
$scheduledCommand = new ScheduledCommand();
$scheduledCommand
->setName($name)
->setCommand($command)
->setArguments($arguments)
->setCronExpression($cronExpression)
->setLogFile($logFile)
->setPriority($priority)
->setLastExecution($lastExecution)
->setLocked($locked)
->setDisabled($disabled)
->setLastReturnCode($lastReturnCode)
->setExecuteImmediately($executeNow);
$this->manager->persist($scheduledCommand);
$this->manager->flush();
}
}