-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve UI to enable/disable cronjobs (#202)
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace EthanYehuda\CronjobManager\Controller\Adminhtml\Config\Job; | ||
|
||
use EthanYehuda\CronjobManager\Helper\JobConfig; | ||
use Exception; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Backend\App\Action; | ||
use Magento\Framework\App\CacheInterface; | ||
use Magento\Framework\App\Config as ConfigCache; | ||
|
||
class MassDisableJobs extends Action | ||
{ | ||
public const ADMIN_RESOURCE = "EthanYehuda_CronjobManager::cronjobmanager"; | ||
|
||
/** | ||
* @param Context $context | ||
* @param JobConfig $helper | ||
* @param CacheInterface $cache | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
private readonly JobConfig $helper, | ||
private readonly CacheInterface $cache, | ||
) { | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Save cronjob | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
$params = $this->getRequest()->getParam('selected'); | ||
if (!isset($params)) { | ||
$this->getMessageManager()->addErrorMessage("Something went wrong when receiving the request"); | ||
$this->_redirect('*/config/index'); | ||
return; | ||
} | ||
|
||
try { | ||
foreach ($params as $jobCode) { | ||
$path = $this->helper->constructFrequencyPath($jobCode); | ||
// Empty frequency disables the job | ||
$this->helper->saveJobFrequencyConfig($path, ''); | ||
} | ||
|
||
// Clear the config cache | ||
$this->cache->clean([ConfigCache::CACHE_TAG]); | ||
} catch (Exception $e) { | ||
$this->getMessageManager()->addErrorMessage($e->getMessage()); | ||
$this->_redirect('*/config/index/'); | ||
|
||
return; | ||
} | ||
|
||
$this->getMessageManager()->addSuccessMessage("Successfully disabled " . count($params) . " jobs"); | ||
$this->_redirect("*/config/index/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace EthanYehuda\CronjobManager\Ui\Component\Listing\Column; | ||
|
||
use Magento\Ui\Component\Listing\Columns\Column; | ||
use EthanYehuda\CronjobManager\Api\Data\ScheduleInterface; | ||
|
||
class Frequency extends Column | ||
{ | ||
/** | ||
* Prepare Data Source | ||
* | ||
* @param array $dataSource | ||
* | ||
* @return array | ||
*/ | ||
public function prepareDataSource(array $dataSource) | ||
{ | ||
if (isset($dataSource['data']['items'])) { | ||
foreach ($dataSource['data']['items'] as & $item) { | ||
if (empty($item['frequency'])) { | ||
$item['frequency'] = __('Disabled'); | ||
} | ||
} | ||
} | ||
|
||
return $dataSource; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters