-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #772 from PrestaShopCorp/feature/MME-331/cloudsync…
…_ps8 feat: install eventbus on PS8
- Loading branch information
Showing
9 changed files
with
175 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
services: | ||
_defaults: | ||
public: true | ||
|
||
mbo.ps_eventbus.installer: | ||
class: 'PrestaShop\Module\Mbo\Service\ModuleInstaller' | ||
public: true | ||
arguments: | ||
- "ps_eventbus" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License version 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/AFL-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 [email protected] so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\Module\Mbo\Service; | ||
|
||
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; | ||
|
||
class ModuleInstaller { | ||
|
||
private $moduleName; | ||
private $moduleVersion; | ||
private $absoluteCompare; | ||
private $moduleManager; | ||
|
||
/** | ||
* @param string $moduleName | ||
* @param string|null $moduleVersion | ||
* @param bool $absoluteCompare | ||
*/ | ||
public function __construct(string $moduleName, string $moduleVersion = null, bool $absoluteCompare = false) { | ||
$this->moduleName = $moduleName; | ||
$this->moduleVersion = $moduleVersion; | ||
$this->absoluteCompare = $absoluteCompare; | ||
$moduleManagerBuilder = ModuleManagerBuilder::getInstance(); | ||
$this->moduleManager = $moduleManagerBuilder->build(); | ||
} | ||
|
||
/** | ||
* Install ps_accounts module if not installed | ||
* Method to call in every psx modules during the installation process | ||
* | ||
* @return bool | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function install() { | ||
if ($this->isModuleInstalled() && $this->isModuleVersionSatisfied()) { | ||
return true; | ||
} | ||
|
||
return $this->moduleManager->install($this->moduleName); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function enable() | ||
{ | ||
if (!$this->moduleManager->isEnabled($this->moduleName)) { | ||
return $this->moduleManager->enable($this->moduleName); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isShopVersion17() | ||
{ | ||
return version_compare(_PS_VERSION_, '1.7.0.0', '>='); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isModuleInstalled() { | ||
if (false === $this->isShopVersion17()) { | ||
return \Module::isInstalled($this->moduleName); | ||
} | ||
|
||
return $this->moduleManager->isInstalled($this->moduleName); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isModuleVersionSatisfied() { | ||
if (!$this->moduleVersion) return true; | ||
$module = \Module::getInstanceByName($this->moduleName); | ||
return version_compare( | ||
$module->version, | ||
$this->moduleVersion, | ||
$this->absoluteCompare ? '>' : '>=' | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters