ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Cron Schedule List for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\CronScheduleList\Controller\Adminhtml\Schedule;
|
||||
|
||||
use Amasty\CronScheduleList\Controller\Adminhtml\AbstractSchedule;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
|
||||
class Index extends AbstractSchedule
|
||||
{
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return \Magento\Backend\Model\View\Result\Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
|
||||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
$resultPage->setActiveMenu('Amasty_CronScheduleList::schedule_list');
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Cron Tasks List'));
|
||||
$resultPage->addBreadcrumb(__('Cron Tasks List'), __('Cron Tasks List'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Cron Schedule List for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\CronScheduleList\Controller\Adminhtml\Schedule;
|
||||
|
||||
use Amasty\CronScheduleList\Controller\Adminhtml\AbstractSchedule;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Magento\Cron\Model\ResourceModel\Schedule\CollectionFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class MassDelete extends AbstractSchedule
|
||||
{
|
||||
/**
|
||||
* Authorization level of a basic admin session
|
||||
*
|
||||
* @see _isAllowed()
|
||||
*/
|
||||
public const ADMIN_RESOURCE = 'Amasty_CronScheduleList::schedule_list';
|
||||
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $jobsCollectionFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
LoggerInterface $logger,
|
||||
CollectionFactory $jobsCollectionFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->filter = $filter;
|
||||
$this->logger = $logger;
|
||||
$this->jobsCollectionFactory = $jobsCollectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass action execution
|
||||
*
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->filter->applySelectionOnTargetProvider();
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = $this->filter->getCollection($this->jobsCollectionFactory->create());
|
||||
$deletedJobs = 0;
|
||||
|
||||
if ($collection->count() > 0) {
|
||||
try {
|
||||
foreach ($collection->getItems() as $job) {
|
||||
$job->delete();
|
||||
$deletedJobs++;
|
||||
}
|
||||
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('%1 task(s) has been successfully deleted', $deletedJobs)
|
||||
);
|
||||
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage(__('An error has occurred'));
|
||||
$this->logger->critical($e);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setRefererUrl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Cron Schedule List for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\CronScheduleList\Controller\Adminhtml\Schedule;
|
||||
|
||||
use Amasty\CronScheduleList\Controller\Adminhtml\AbstractSchedule;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\CacheInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Shell;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
class RunCron extends AbstractSchedule
|
||||
{
|
||||
/**
|
||||
* @var CacheInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var Shell
|
||||
*/
|
||||
private $shell;
|
||||
|
||||
/**
|
||||
* @var PhpExecutableFinder
|
||||
*/
|
||||
private $phpExecutableFinder;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectUrl = 'amasty_cronschedulelist/schedule/index';
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CacheInterface $cache,
|
||||
Shell $shell,
|
||||
PhpExecutableFinder $phpExecutableFinder
|
||||
) {
|
||||
parent::__construct($context);
|
||||
|
||||
$this->cache = $cache;
|
||||
$this->shell = $shell;
|
||||
$this->phpExecutableFinder = $phpExecutableFinder;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$phpPath = $this->phpExecutableFinder->find() ?: 'php';
|
||||
$this->cache->clean(['crontab']);
|
||||
|
||||
try {
|
||||
$this->shell->execute($phpPath . ' %s cron:run', [BP . '/bin/magento']);
|
||||
$this->messageManager->addSuccessMessage(__('Job\'s generation started'));
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addNoticeMessage($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath($this->redirectUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user