35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Agent\Controller\Adminhtml\Application;
|
|
|
|
use Esun\Agent\Model\ApplicationFactory;
|
|
use Magento\Backend\App\Action;
|
|
use Magento\Framework\Controller\Result\Redirect;
|
|
|
|
class Delete extends Action
|
|
{
|
|
public const ADMIN_RESOURCE = 'Esun_Agent::applications_delete';
|
|
|
|
public function __construct(Action\Context $context, private readonly ApplicationFactory $applicationFactory)
|
|
{
|
|
parent::__construct($context);
|
|
}
|
|
|
|
public function execute(): Redirect
|
|
{
|
|
try {
|
|
$application = $this->applicationFactory->create()->load((int)$this->getRequest()->getParam('entity_id'));
|
|
if (!$application->getId()) {
|
|
throw new \RuntimeException('Application not found.');
|
|
}
|
|
$application->delete();
|
|
$this->messageManager->addSuccessMessage(__('The application has been deleted.'));
|
|
} catch (\Throwable $exception) {
|
|
$this->messageManager->addErrorMessage(__('The application could not be deleted.'));
|
|
}
|
|
|
|
return $this->resultRedirectFactory->create()->setPath('*/*/');
|
|
}
|
|
}
|