File: /home4/cca63905/public_html/nueva/modules/wnetsecurity/src/Installer/PsMboInstaller.php
<?php
/**
* Copyright since 2014 Waynet Sp. z o.o.
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@waynet.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop-project.org/ for more information.
*
* @author Waynet Sp. z o.o. <kontakt@waynet.pl>
* @copyright since 2014 Waynet Sp. z o.o.
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
declare(strict_types=1);
namespace Waynet\Security\Installer;
use Prestashop\ModuleLibMboInstaller\Installer;
use Prestashop\ModuleLibMboInstaller\Presenter;
use PrestaShopBundle\Service\Hook\HookEvent;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Waynet\Security\Installer\Module\ModuleInstallerFactory;
class PsMboInstaller implements InstallerInterface
{
private const TRANSLATION_SOURCE = 'psmboinstaller';
private $presenter;
private $installer;
private $moduleInstallerFactory;
private $moduleInstaller;
public function __construct(
Presenter $presenter,
Installer $installer,
ModuleInstallerFactory $moduleInstallerFactory
) {
$this->presenter = $presenter;
$this->installer = $installer;
$this->moduleInstallerFactory = $moduleInstallerFactory;
}
public function install(\Module $module): bool
{
if (\Tools::version_compare(_PS_VERSION_, '8.0')) {
return true;
}
$status = $this->presenter->present();
if ($status['isInstalled']) {
return true;
}
try {
if (!$this->installer->installModule()) {
return false;
}
} catch (\Exception $exception) {
throw new InstallerException(sprintf($module->l('Could not install the "ps_mbo" module. Error: "%s"', self::TRANSLATION_SOURCE), $exception->getMessage()), 0, $exception);
}
$this->registerHookListener($module);
return true;
}
public function uninstall(\Module $module): bool
{
return true;
}
private function registerHookListener(\Module $module): void
{
try {
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = $module->get('prestashop.core.hook.dispatcher');
} catch (ServiceNotFoundException $exception) {
return;
}
$dispatcher->addListener('actionbeforeinstallmodule', [$this, 'onBeforeInstallModule']);
}
public function onBeforeInstallModule(HookEvent $event): void
{
if (null === $this->moduleInstaller = $this->moduleInstaller ?? $this->moduleInstallerFactory->create()) {
return;
}
($this->moduleInstaller)($event->getHookParameters());
}
}