init
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Controller\Adminhtml\Log;
|
||||
|
||||
use Esun\MultiLocaleTranslation\Model\LogCleaner;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
|
||||
class ClearAll extends Action implements HttpPostActionInterface
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_MultiLocaleTranslation::translation_log_delete';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly LogCleaner $logCleaner
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): Redirect
|
||||
{
|
||||
try {
|
||||
$deleted = $this->logCleaner->clearAll();
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('%1 Translation API Log record(s) cleared.', $deleted)
|
||||
);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->messageManager->addErrorMessage($exception->getMessage());
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Controller\Adminhtml\Log;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_MultiLocaleTranslation::translation_log';
|
||||
|
||||
public function __construct(Context $context, private readonly PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): Page
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->setActiveMenu('Esun_MultiLocaleTranslation::translation_log');
|
||||
$page->getConfig()->getTitle()->prepend(__('Translation API Log'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\MultiLocaleTranslation\Controller\Adminhtml\Log;
|
||||
|
||||
use Esun\MultiLocaleTranslation\Model\ResourceModel\Log\CollectionFactory;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
|
||||
class MassDelete extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_MultiLocaleTranslation::translation_log_delete';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly Filter $filter,
|
||||
private readonly CollectionFactory $collectionFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): Redirect
|
||||
{
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
$deleted = 0;
|
||||
foreach ($collection as $log) {
|
||||
$log->delete();
|
||||
$deleted++;
|
||||
}
|
||||
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('A total of %1 translation log(s) have been deleted.', $deleted)
|
||||
);
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user