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/app/code/Soon/Core/Setup/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Soon/Core/Setup/Installer.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2016 Agence Soon (http://www.agence-soon.fr)
 */
declare(strict_types=1);

namespace Soon\Core\Setup;

use Magento\Config\Model\ResourceModel\Config;
use Magento\Config\Model\ResourceModel\ConfigFactory;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Module\SetupFactory;
use Magento\Framework\Setup\SampleData\InstallerInterface;
use Magento\Framework\Setup\SetupInterface;

class Installer implements InstallerInterface
{
    /**
     * @var ScopeConfigInterface
     */
    private $scopeConfig;
    /**
     * @var ConfigFactory
     */
    private $configResourceFactory;
    /**
     * @var SetupInterface
     */
    private $setup;
    /**
     * @var bool
     */
    private $fkCheckFlag = true;
    /**
     * @var Taxes
     */
    private $taxesFactory;
    /**
     * @var GroupRepositoryInterface
     */
    private $customerGroupRepository;
    /**
     * @var SearchCriteriaInterface
     */
    private $searchCriteria;
    /**
     * @var CmsFactory
     */
    private $cmsFactory;
    /**
     * @var EmailTemplateFactory
     */
    private $emailTemplateFactory;
    /**
     * @var Config
     */
    private $config;
    /**
     * @var Cms
     */
    private $cms;
    /**
     * @var EmailTemplate
     */
    private $emailTemplate;

    /**
     * Installer constructor.
     * @param SetupFactory $setupFactory
     * @param ScopeConfigInterface $scopeConfig
     * @param ConfigFactory $configResourceFactory
     * @param TaxesFactory $taxesFactory
     * @param GroupRepositoryInterface $customerGroupRepository
     * @param SearchCriteriaInterface $searchCriteria
     * @param CmsFactory $cmsFactory
     * @param EmailTemplateFactory $emailTemplateFactory
     */
    public function __construct(
        SetupFactory $setupFactory,
        ScopeConfigInterface $scopeConfig,
        ConfigFactory $configResourceFactory,
        TaxesFactory $taxesFactory,
        GroupRepositoryInterface $customerGroupRepository,
        SearchCriteriaInterface $searchCriteria,
        CmsFactory $cmsFactory,
        EmailTemplateFactory $emailTemplateFactory
    ) {
        $this->scopeConfig = $scopeConfig;
        $this->configResourceFactory = $configResourceFactory;
        $this->setup = $setupFactory->create();
        $this->taxesFactory = $taxesFactory;
        $this->customerGroupRepository = $customerGroupRepository;
        $this->searchCriteria = $searchCriteria;
        $this->cmsFactory = $cmsFactory;
        $this->emailTemplateFactory = $emailTemplateFactory;
    }

    public function install(): void
    {
        $this->config = $this->configResourceFactory->create();
        $this->cms = $this->cmsFactory->create();
        $this->emailTemplate = $this->emailTemplateFactory->create();
        $this->forceBaseSecureUrl();
        $this->setLocale();
        $this->installTaxes();
        $this->updateCustomerGroups();
        $this->updateCms();
        $this->installEmailTemplates();
    }

    /**
     * Force base secure URL to 'http'
     *
     * When installing Jade with Magerun, base secure URL is https
     * but our vhost may not be configured as such. So we force to http.
     */
    private function forceBaseSecureUrl(): void
    {

        $configPath = 'web/secure/base_url';
        $currentUrl = $this->scopeConfig->getValue($configPath);
        $newUrl = str_replace('https', 'http', $currentUrl);

        $this->config->saveConfig($configPath, $newUrl, 'default', 0);
    }

    /**
     * Use France_French (FR_fr) locale
     */
    private function setLocale(): void
    {
        $this->config->saveConfig('general/locale/code', 'fr_FR', 'default', 0);
    }

    private function installTaxes(): void
    {
        $this->toggleFkChecks();
        $taxes = $this->taxesFactory->create();
        $taxes->install();
        $this->toggleFkChecks();
    }

    private function toggleFkChecks(): void
    {
        $this->fkCheckFlag = !$this->fkCheckFlag;

        $this->setup
            ->getConnection()
            ->query(sprintf('SET FOREIGN_KEY_CHECKS=%s', (int)$this->fkCheckFlag));
    }

    /**
     * Clean and update customer groups
     */
    private function updateCustomerGroups(): void
    {
        $customerGroups = $this->customerGroupRepository
            ->getList($this->searchCriteria)
            ->getItems();

        foreach ($customerGroups as $customerGroup) {
            switch ($customerGroup->getId()) {
                case 0:
                    // NOT LOGGED IN
                    break;
                case 1:
                    // Rename "General"
                    $customerGroup->setCode('Particuliers');
                    $this->customerGroupRepository->save($customerGroup);
                    break;
                default:
                    // Remove unused customer groups
                    $this->customerGroupRepository->delete($customerGroup);

            }
        }
    }

    private function updateCms(): void
    {
        $this->cms->install();
    }

    private function installEmailTemplates(): void
    {
        $this->emailTemplate->install();
    }
}

Spamworldpro Mini