![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/ConfigurationCountry/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Controller\Adminhtml\ConfigurationCountry; use Extmag\Shiplab\Api\ConfigurationDirectionRepositoryInterface; use Extmag\Shiplab\Api\ConfigurationScopeRepositoryInterface; use Extmag\Shiplab\Model\ConfigurationCountryRepository; use Extmag\Shiplab\Model\ConfigurationScopeFactory; use Exception; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\Redirect; use Magento\Framework\App\ResourceConnection; class Delete extends Action { /** * Authorization level of a basic admin session * * @see _isAllowed() */ public const ADMIN_RESOURCE = 'Extmag_Shiplab::shiplab_configurationcountry_delete'; /** * @var ConfigurationScopeFactory */ private $scopeFactory; /** * @var ConfigurationScopeRepositoryInterface */ private $scopeRepository; /** * @var ConfigurationDirectionRepositoryInterface */ private $saveTransaction; /** * @var ConfigurationCountryRepository */ private $configurationCountryRepository; /** * @param Context $context * @param ResourceConnection $transactionFactory * @param ConfigurationScopeFactory $scopeFactory * @param ConfigurationScopeRepositoryInterface $scopeRepository * @param ConfigurationCountryRepository $configurationCountryRepository */ public function __construct( Context $context, ResourceConnection $transactionFactory, ConfigurationScopeFactory $scopeFactory, ConfigurationScopeRepositoryInterface $scopeRepository, ConfigurationCountryRepository $configurationCountryRepository ) { $this->saveTransaction = $transactionFactory->getConnection(); $this->scopeFactory = $scopeFactory; $this->scopeRepository = $scopeRepository; $this->configurationCountryRepository = $configurationCountryRepository; parent::__construct($context); } /** * @return Redirect */ public function execute() { // check if we know what should be deleted $id = $this->getRequest()->getParam('entity_id'); /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($id) { $title = ""; try { $this->saveTransaction->beginTransaction(); // init model and delete $model = $this->configurationCountryRepository->getById($id); $title = $model->getTitle(); $scopeSearch = $this->scopeFactory->create()->getCollection() ->addFieldToFilter('country', $model->getId()); if (count($scopeSearch) > 0) { foreach ($scopeSearch as $scope) { $scope->setCountry(null); $this->scopeRepository->save($scope); } } $this->configurationCountryRepository->delete($model); // display success message $this->messageManager->addSuccessMessage(__('The Country Configuration Scope has been deleted.')); $this->saveTransaction->commit(); // go to grid $this->_eventManager->dispatch( 'adminhtml_extmag_shiplab_configurationcountry_on_delete', [ 'title' => $title, 'status' => 'success', ] ); return $resultRedirect->setPath('*/configurationScope/'); } catch (Exception $e) { $this->saveTransaction->rollBack(); $this->_eventManager->dispatch( 'adminhtml_extmag_shiplab_configurationcountry_on_delete', ['title' => $title, 'status' => 'fail'] ); // display error message $this->messageManager->addErrorMessage($e->getMessage()); // go back to edit form return $resultRedirect->setPath('*/*/edit', ['entity_id' => $id]); } } // display error message $this->messageManager->addErrorMessage(__('We can\'t find a Country Configuration Scope to delete.')); // go to grid return $resultRedirect->setPath('*/configurationScope/'); } }