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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Extmag\Shiplab\Controller\Adminhtml\AccessPoint;

use Exception;
use Extmag\Shiplab\Api\AccessPointRepositoryInterface;
use Extmag\Shiplab\Model\AccessPoint;
use Extmag\Shiplab\Model\AccessPointFactory;
use Magento\Backend\App\Action;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;

class Save extends Action
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    public const ADMIN_RESOURCE = 'Extmag_Shiplab::shiplab_accesspoint_save';

    /**
     * @var PostDataProcessor
     */
    protected $dataProcessor;

    /**
     * @var DataPersistorInterface
     */
    protected $dataPersistor;

    /**
     * @var AccessPointFactory
     */
    private $modelFactory;

    /**
     * @var AccessPointRepositoryInterface
     */
    private $modelRepository;

    /**
     * @param Action\Context                 $context
     * @param PostDataProcessor              $dataProcessor
     * @param DataPersistorInterface         $dataPersistor
     * @param AccessPointFactory             $modelFactory
     * @param AccessPointRepositoryInterface $modelRepository
     */
    public function __construct(
        Action\Context $context,
        PostDataProcessor $dataProcessor,
        DataPersistorInterface $dataPersistor,
        AccessPointFactory $modelFactory,
        AccessPointRepositoryInterface $modelRepository
    ) {
        $this->dataProcessor   = $dataProcessor;
        $this->dataPersistor   = $dataPersistor;
        $this->modelFactory    = $modelFactory;
        $this->modelRepository = $modelRepository;
        parent::__construct($context);
    }

    /**
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @return ResultInterface
     */
    public function execute()
    {
        $data = $this->getRequest()->getPostValue();
        /** @var Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        if ($data) {
            $data = $this->dataProcessor->filter($data);
            if (empty($data['entity_id'])) {
                $data['entity_id'] = null;
            }

            /** @var AccessPoint $model */
            $id = $this->getRequest()->getParam('entity_id');
            if ($id) {
                try {
                    $model = $this->modelRepository->getById($id);
                } catch (LocalizedException $e) {
                    $this->messageManager->addErrorMessage(__('This Access Point no longer exists.'));

                    return $resultRedirect->setPath('*/*/');
                }
            } else {
                $model = $this->modelFactory->create();
            }

            try {
                $model->setData($data);
                if (!$this->dataProcessor->validateRequireEntry($data)) {
                    return $resultRedirect->setPath('*/*/edit', ['entity_id' => $model->getId(), '_current' => true]);
                }
                $this->modelRepository->save($model);
                $this->_eventManager->dispatch(
                    'extmag_shiplab_accesspoint_prepare_save',
                    ['model' => $model, 'status' => 'success']
                );
                $this->messageManager->addSuccessMessage(__('You saved the Access Point.'));

                return $this->processResultRedirect($model, $resultRedirect);
            } catch (LocalizedException $e) {
                $this->messageManager->addExceptionMessage($e->getPrevious() ?: $e);
            } catch (Exception $e) {
                $this->messageManager->addExceptionMessage(
                    $e,
                    __('Something went wrong while saving the Access Point.')
                );
            }

            $this->dataPersistor->set('extmag_shiplab_accesspoint', $data);

            return $resultRedirect->setPath('*/*/edit', ['entity_id' => $this->getRequest()->getParam('entity_id')]);
        }

        return $resultRedirect->setPath('*/*/');
    }

    /**
     * @param AccessPoint $model
     * @param Redirect    $resultRedirect
     *
     * @return Redirect
     */
    private function processResultRedirect($model, $resultRedirect)
    {
        $this->dataPersistor->clear('extmag_shiplab_accesspoint');
        if ($this->getRequest()->getParam('back')) {
            return $resultRedirect->setPath('*/*/edit', ['entity_id' => $model->getId(), '_current' => true]);
        }

        return $resultRedirect->setPath('*/*/');
    }
}

Spamworldpro Mini