Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jun 18, 2020
2 parents 9c55fb7 + 29cbbce commit 7f58df2
Show file tree
Hide file tree
Showing 46 changed files with 2,258 additions and 2,253 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Job/Edit/Tab/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
array $data = []
) {
$this->jobStatus = $jobStatus;
$this->group = $group;
$this->group = $group;

parent::__construct($context, $registry, $formFactory, $data);
}
Expand Down
14 changes: 7 additions & 7 deletions Block/Adminhtml/Timetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function __construct(
CollectionFactory $collectionFactory,
array $data = []
) {
$this->helper = $helper;
$this->datetime = $datetime;
$this->helper = $helper;
$this->datetime = $datetime;
$this->collectionFactory = $collectionFactory;

parent::__construct($context, $data);
Expand All @@ -78,7 +78,7 @@ public function __construct(
*/
public function getCronJobData()
{
$data = [];
$data = [];
$count = 0;

$schedules = $this->collectionFactory->create();
Expand All @@ -88,16 +88,16 @@ public function getCronJobData()
/** @var Schedule $schedule */
foreach ($schedules->getItems() as $schedule) {
$status = $schedule->getStatus();
$start = $schedule->getScheduledAt();
$end = $start;
$start = $schedule->getScheduledAt();
$end = $start;

switch ($status) {
case Schedule::STATUS_RUNNING:
$end = $this->helper->getTime();
break;
case Schedule::STATUS_SUCCESS:
$start = $schedule->getExecutedAt();
$end = $schedule->getFinishedAt();
$end = $schedule->getFinishedAt();
break;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ private function getToolTip($schedule, $status)
$tooltip .= sprintf('<tr><th>%s</th><td>%s</td></tr>', __('ID'), $schedule->getId());

$statusHtml = sprintf('<span class="tooltip-severity %s">%s</span>', $status, $status);
$tooltip .= sprintf('<tr><th>%s</th><td>%s</td></tr>', __('Status'), $statusHtml);
$tooltip .= sprintf('<tr><th>%s</th><td>%s</td></tr>', __('Status'), $statusHtml);

if ($message = $schedule->getMessages()) {
$tooltip .= sprintf('<tr><th>%s</th><td>%s</td></tr>', __('Message'), $this->escapeQuote($message));
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHANGELOG: https://www.mageplaza.com/releases/cron-schedule/
CHANGELOG: https://www.mageplaza.com/releases/cron-schedule/
16 changes: 8 additions & 8 deletions Controller/Adminhtml/AbstractJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public function __construct(
TypeListInterface $cacheTypeList
) {
$this->resultPageFactory = $resultPageFactory;
$this->jsonFactory = $jsonFactory;
$this->registry = $registry;
$this->helper = $helper;
$this->jobFactory = $jobFactory;
$this->scheduleFactory = $scheduleFactory;
$this->logger = $logger;
$this->cacheTypeList = $cacheTypeList;
$this->jsonFactory = $jsonFactory;
$this->registry = $registry;
$this->helper = $helper;
$this->jobFactory = $jobFactory;
$this->scheduleFactory = $scheduleFactory;
$this->logger = $logger;
$this->cacheTypeList = $cacheTypeList;

parent::__construct($context);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ protected function getSelectedRecords($data)
});
}

$jobs = array_values($allJobs);
$jobs = array_values($allJobs);
$filters = (array) $data['filters'];
unset($filters['placeholder']);
foreach ($filters as $column => $value) {
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/AbstractLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(
CollectionFactory $collectionFactory
) {
$this->resultPageFactory = $resultPageFactory;
$this->filter = $filter;
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;

parent::__construct($context);
Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Job/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Edit extends AbstractJob
public function execute()
{
$object = $this->_initJob();
$name = $this->getRequest()->getParam('name');
$name = $this->getRequest()->getParam('name');

if ($name !== null) {
if ($object->getData() === null) {
Expand All @@ -61,7 +61,7 @@ public function execute()

$this->registry->register('mpcronschedule_job', $object);

$pageTitle = $name !== null ? __('Edit Cron Job "%1"', $name) : __('Create New Cron Job');
$pageTitle = $name !== null ? __('Edit Cron Job "%1"', $name) : __('Create New Cron Job');
$resultPage = $this->_initAction();
$resultPage->getConfig()->getTitle()->prepend($pageTitle);

Expand Down
8 changes: 4 additions & 4 deletions Controller/Adminhtml/Job/InlineEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
$items = $this->getRequest()->getParam('items', []);
$error = false;
$messages = [];
$items = $this->getRequest()->getParam('items', []);

if (empty($items) && !$this->getRequest()->getParam('isAjax')) {
return $resultJson->setData([
Expand All @@ -57,7 +57,7 @@ public function execute()
$object->changeJobStatus($items[$name]['status']);
} catch (Exception $e) {
$messages[] = '[Cron Job: ' . $object->getName() . '] ' . $e->getMessage();
$error = true;
$error = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Controller/Adminhtml/Job/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function execute()
$error = false;

$request = $this->getRequest();
$name = $request->getParam('code');
$name = $request->getParam('code');

$validator = new Zend_Validate_Regex('/^[a-z][a-z_0-9]{0,30}$/');
if (!$validator->isValid($name)) {
Expand All @@ -57,15 +57,15 @@ public function execute()
}

$orgName = $request->getParam('org_name');
$jobs = $this->helper->getJobs();
$jobs = $this->helper->getJobs();

if ($name !== $orgName && isset($jobs[$name])) {
$this->messageManager->addErrorMessage(__('A cron job with this code already exists.'));
$error = true;
}

$schedule = $request->getParam('schedule');
$e = count(preg_split('#\s+#', $schedule, null, PREG_SPLIT_NO_EMPTY));
$e = count(preg_split('#\s+#', $schedule, null, PREG_SPLIT_NO_EMPTY));
if ($e < 5 || $e > 6) {
$this->messageManager->addErrorMessage(__('Invalid cron expression: %1', $schedule));
$error = true;
Expand Down
8 changes: 4 additions & 4 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function __construct(
DateTime $dateTime
) {
$this->cronConfig = $cronConfig;
$this->timezone = $timezone;
$this->dateTime = $dateTime;
$this->timezone = $timezone;
$this->dateTime = $dateTime;

parent::__construct($context, $objectManager, $storeManager);
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getJobs($name = null)
*/
private function getJobData($job, $code, $group)
{
$job['name'] = $code;
$job['name'] = $code;
$job['group'] = $group;

if (!isset($job['schedule'])) {
Expand Down Expand Up @@ -174,7 +174,7 @@ public function isJobDisabled($name)
*/
public function getTime($isFloor = false)
{
$time = $this->versionCompare('2.2.0') ? $this->dateTime->gmtTimestamp() : $this->timezone->scopeTimeStamp();
$time = $this->versionCompare('2.2.0') ? $this->dateTime->gmtTimestamp() : $this->timezone->scopeTimeStamp();
$format = $isFloor ? '%Y-%m-%d %H:%M:00' : '%Y-%m-%d %H:%M:%S';

return strftime($format, $time);
Expand Down
3 changes: 2 additions & 1 deletion Helper/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Magento\Framework\App\Area;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\MailException;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\ObjectManagerInterface;
Expand Down Expand Up @@ -115,7 +116,7 @@ public function getSchedule($storeId = null)
* @param array $templateVars
*
* @throws MailException
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function sendEmail($templateVars = [])
{
Expand Down
40 changes: 20 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
The MIT License

Copyright (c) 2015-present Mageplaza, Co. Ltd. https://www.mageplaza.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
The MIT License
Copyright (c) 2015-present Mageplaza, Co. Ltd. https://www.mageplaza.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion Model/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(
ShellInterface $shell,
PhpExecutableFinderFactory $phpExecutableFinderFactory
) {
$this->shell = $shell;
$this->shell = $shell;
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
}

Expand Down
10 changes: 6 additions & 4 deletions Model/EmailNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
namespace Mageplaza\CronSchedule\Model;

use Magento\Cron\Model\Schedule;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\MailException;
use Mageplaza\CronSchedule\Helper\Email;
use Mageplaza\CronSchedule\Model\ResourceModel\Schedule\Collection;
use Mageplaza\CronSchedule\Model\ResourceModel\Schedule\CollectionFactory;
Expand Down Expand Up @@ -53,13 +55,13 @@ public function __construct(
Email $helper,
CollectionFactory $collectionFactory
) {
$this->helper = $helper;
$this->helper = $helper;
$this->collectionFactory = $collectionFactory;
}

/**
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\MailException
* @throws LocalizedException
* @throws MailException
*/
public function sendEmail()
{
Expand All @@ -74,7 +76,7 @@ public function sendEmail()
->addFieldToFilter('mpcronschedule_email_sent', ['null' => true])
->addFieldToFilter('status', ['in' => [Schedule::STATUS_ERROR, Schedule::STATUS_MISSED]]);

if (!$collection->getSize()) {
if (!$collection->getSize() || empty($this->helper->getConfigGeneral('send_to'))) {
return;
}

Expand Down
10 changes: 6 additions & 4 deletions Model/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
AbstractDb $resourceCollection = null,
array $data = []
) {
$this->helper = $helper;
$this->helper = $helper;
$this->valueFactory = $valueFactory;

parent::__construct($context, $registry, $resource, $resourceCollection, $data);
Expand Down Expand Up @@ -140,7 +140,7 @@ public function deleteJob()
public function executeJob(&$schedule)
{
$instance = $this->getInstance();
$method = $this->getMethod();
$method = $this->getMethod();

if (!isset($instance, $method)) {
throw new RuntimeException(__('No callbacks found'));
Expand Down Expand Up @@ -171,10 +171,12 @@ public function executeJob(&$schedule)
*/
public function changeJobStatus($statusValue)
{
$path = $this->getCronPath(self::STATUS_PATH);

/** @var Value $config */
$config = $this->valueFactory->create();
$config->load($this->getCronPath(self::STATUS_PATH), 'path');
$config->setValue($statusValue);
$config->load($path, 'path');
$config->setPath($path)->setValue($statusValue);
$config->save();

return $this;
Expand Down
4 changes: 2 additions & 2 deletions Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function __construct(
UrlInterface $urlBuilder,
CollectionFactory $collectionFactory
) {
$this->helper = $helper;
$this->urlBuilder = $urlBuilder;
$this->helper = $helper;
$this->urlBuilder = $urlBuilder;
$this->collectionFactory = $collectionFactory;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
Data $helper
) {
$this->modelConfig = $modelConfig;
$this->helper = $helper;
$this->helper = $helper;
}

/**
Expand Down
Loading

0 comments on commit 7f58df2

Please sign in to comment.