-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSchedule.php
More file actions
67 lines (57 loc) · 1.78 KB
/
Copy pathSchedule.php
File metadata and controls
67 lines (57 loc) · 1.78 KB
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
<?php
/**
* @author Mygento Team
* @copyright 2014-2026 Mygento (https://www.mygento.com)
* @package Mygento_Base
*/
namespace Mygento\Base\Controller\Adminhtml\Cron;
class Schedule extends \Magento\Backend\App\Action
{
/**
* @var \Mygento\Base\Helper\Cron
*/
private $cronHelper;
/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
private $jsonResult;
/**
* @param \Mygento\Base\Helper\Cron $cronHelper
* @param \Magento\Framework\Controller\Result\JsonFactory $jsonResult
* @param \Magento\Backend\App\Action\Context $context
*/
public function __construct(
\Mygento\Base\Helper\Cron $cronHelper,
\Magento\Framework\Controller\Result\JsonFactory $jsonResult,
\Magento\Backend\App\Action\Context $context,
) {
parent::__construct($context);
$this->jsonResult = $jsonResult;
$this->cronHelper = $cronHelper;
}
/**
* Execute action based on request and return result
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$resultJson = $this->jsonResult->create();
$job = $this->getRequest()->getParam('job', null);
if (!$job) {
return $resultJson->setData([
'errorMessage' => __('Job Code is required'),
]);
}
if ($this->cronHelper->isRunning($job)) {
return $resultJson->setData([
'success' => true,
'successText' => __('Scheduled or Running'),
]);
}
$this->cronHelper->addSchedule($job);
return $resultJson->setData([
'success' => true,
'successText' => __('Scheduled'),
]);
}
}