-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDelete.php
54 lines (46 loc) · 1.71 KB
/
Delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);
namespace Opengento\Document\Controller\Adminhtml\Index;
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use Opengento\Document\Api\DocumentRepositoryInterface;
class Delete extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Opengento_Document::document_delete';
/**
* @var DocumentRepositoryInterface
*/
private $documentRepository;
public function __construct(
Context $context,
DocumentRepositoryInterface $documentRepository
) {
$this->documentRepository = $documentRepository;
parent::__construct($context);
}
public function execute()
{
try {
$this->documentRepository->delete(
$this->documentRepository->getById((int) $this->getRequest()->getParam('id'))
);
$this->messageManager->addSuccessMessage(new Phrase('The document has been successfully deleted.'));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
}