|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\System\Cron; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Cron\Model\Schedule; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class ScheduleCommand extends AbstractCronCommand |
|
11
|
|
|
{ |
|
12
|
|
|
protected function configure() |
|
13
|
|
|
{ |
|
14
|
|
|
$this |
|
15
|
|
|
->setName('sys:cron:schedule') |
|
16
|
|
|
->addArgument('job', InputArgument::OPTIONAL, 'Job code') |
|
17
|
|
|
->setDescription('Schedule a cronjob for execution right now, by job code'); |
|
18
|
|
|
$help = <<<HELP |
|
19
|
|
|
If no `job` argument is passed you can select a job from a list. |
|
20
|
|
|
HELP; |
|
21
|
|
|
$this->setHelp($help); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param InputInterface $input |
|
26
|
|
|
* @param OutputInterface $output |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
* @return int|void |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
|
|
list($jobCode, $jobConfig) = $this->getJobForExecuteMethod($input, $output); |
|
33
|
|
|
|
|
34
|
|
|
$output->write( |
|
35
|
|
|
'<info>Scheduling </info><comment>' . $jobConfig['instance'] . '::' . $jobConfig['method'] . '</comment> ' |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$createdAtTime = $this->timezone->scopeTimeStamp(); |
|
39
|
|
|
$scheduledAtTime = $createdAtTime; |
|
40
|
|
|
|
|
41
|
|
|
/* @var $schedule \Magento\Cron\Model\Schedule */ |
|
42
|
|
|
$schedule = $this->cronScheduleCollection->getNewEmptyItem(); |
|
43
|
|
|
$schedule |
|
44
|
|
|
->setJobCode($jobCode) |
|
45
|
|
|
->setStatus(Schedule::STATUS_PENDING) |
|
46
|
|
|
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $createdAtTime)) |
|
47
|
|
|
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $scheduledAtTime)) |
|
48
|
|
|
->save(); |
|
49
|
|
|
|
|
50
|
|
|
$output->writeln('<info>done</info>'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|