Spamworldpro Mini Shell
Spamworldpro


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/ConfigurationDirection/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/ConfigurationDirection/Delete.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Controller\Adminhtml\ConfigurationDirection;

use Extmag\Shiplab\Api\ConfigurationDirectionRepositoryInterface;
use Extmag\Shiplab\Api\ConfigurationScopeRepositoryInterface;
use Extmag\Shiplab\Model\ConfigurationDirectionRepository;
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_configurationdirection_delete';

    /**
     * @var ConfigurationScopeFactory
     */
    private $scopeFactory;

    /**
     * @var ConfigurationScopeRepositoryInterface
     */
    private $scopeRepository;

    /**
     * @var ConfigurationDirectionRepositoryInterface
     */
    private $saveTransaction;

    /**
     * @var ConfigurationDirectionRepository
     */
    private $configurationDirectionRepository;

    /**
     * @param Context $context
     * @param ResourceConnection $transactionFactory
     * @param ConfigurationScopeFactory $scopeFactory
     * @param ConfigurationScopeRepositoryInterface $scopeRepository
     * @param ConfigurationDirectionRepository $configurationDirectionRepository
     */
    public function __construct(
        Context $context,
        ResourceConnection $transactionFactory,
        ConfigurationScopeFactory $scopeFactory,
        ConfigurationScopeRepositoryInterface $scopeRepository,
        ConfigurationDirectionRepository $configurationDirectionRepository
    ) {
        $this->saveTransaction = $transactionFactory->getConnection();
        $this->scopeFactory = $scopeFactory;
        $this->scopeRepository = $scopeRepository;
        $this->configurationDirectionRepository = $configurationDirectionRepository;
        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 {
                $scopeIsCountry = $this->scopeFactory->create()->getCollection()
                    ->addFieldToFilter('direction', $id)
                    ->addFieldToFilter('direction', ['neq' => 'NULL']);

                if (count($scopeIsCountry) == 0) {
                    $this->saveTransaction->beginTransaction();
                    // init model and delete
                    $model = $this->configurationDirectionRepository->getById($id);

                    $title = $model->getTitle();

                    $scopeSearch = $this->scopeFactory->create()->getCollection()
                        ->addFieldToFilter('direction', $id);
                    if (count($scopeSearch) > 0) {
                        foreach ($scopeSearch as $scope) {
                            $scope->setDirection(null);
                            $this->scopeRepository->save($scope);
                        }
                    }

                    $this->configurationDirectionRepository->delete($model);

                    $this->saveTransaction->commit();

                    // display success message
                    $this->messageManager->addSuccessMessage(__('The Direction Scope has been deleted.'));

                    // go to grid
                    $this->_eventManager->dispatch(
                        'adminhtml_extmag_shiplab_configurationdirection_on_delete',
                        [
                            'title' => $title,
                            'status' => 'success',
                        ]
                    );
                } else {
                    $this->messageManager->addErrorMessage(
                        __('We can\'t delete a Direction Scope because Direction Scope(s) depends on this scope.')
                    );
                }

                return $resultRedirect->setPath('*/configurationScope/');
            } catch (Exception $e) {
                $this->saveTransaction->rollBack();
                $this->_eventManager->dispatch(
                    'adminhtml_extmag_shiplab_configurationdirection_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 Direction Scope to delete.'));

        // go to grid
        return $resultRedirect->setPath('*/configurationScope/');
    }
}

Spamworldpro Mini