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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Extmag\Shiplab\Controller\Adminhtml\ConfigurationStore;

use Extmag\Shiplab\Api\ConfigurationDirectionRepositoryInterface;
use Extmag\Shiplab\Api\ConfigurationScopeRepositoryInterface;
use Extmag\Shiplab\Model\ConfigurationScopeFactory;
use Extmag\Shiplab\Model\ConfigurationStoreRepository;
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_configurationstore_delete';

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

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

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

    /**
     * @var ConfigurationStoreRepository
     */
    private $configurationStoreRepository;

    /**
     * @param Context $context
     * @param ResourceConnection $transactionFactory
     * @param ConfigurationScopeFactory $scopeFactory
     * @param ConfigurationScopeRepositoryInterface $scopeRepository
     * @param ConfigurationStoreRepository $configurationStoreRepository
     */
    public function __construct(
        Context $context,
        ResourceConnection $transactionFactory,
        ConfigurationScopeFactory $scopeFactory,
        ConfigurationScopeRepositoryInterface $scopeRepository,
        ConfigurationStoreRepository $configurationStoreRepository
    ) {
        $this->saveTransaction = $transactionFactory->getConnection();
        $this->scopeFactory = $scopeFactory;
        $this->scopeRepository = $scopeRepository;
        parent::__construct($context);
        $this->configurationStoreRepository = $configurationStoreRepository;
    }

    /**
     * @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('store', $id)
                    ->addFieldToFilter('direction', ['neq' => 'NULL']);

                if (count($scopeIsCountry) == 0) {
                    $this->saveTransaction->beginTransaction();
                    $model = $this->configurationStoreRepository->getById($id);

                    $title = $model->getTitle();

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

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

                    $this->saveTransaction->commit();

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

                    // go to grid
                    $this->_eventManager->dispatch(
                        'adminhtml_extmag_shiplab_configurationstore_on_delete',
                        [
                            'title' => $title,
                            'status' => 'success',
                        ]
                    );
                } else {
                    $this->messageManager->addErrorMessage(
                        __('We can\'t delete a Store 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_configurationstore_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 Store Scope to delete.'));

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

Spamworldpro Mini