Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check module is active before instanciating it #13

Open
wants to merge 2 commits into
base: 8.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions classes/module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,23 @@ public static function getModulesInstalled($position = 0)
return Db::getInstance()->executeS($sql);
}

/**
* Return modules that are installed AND enabled
*
* @return array Modules
*/
public static function getModulesInstalledAndEnabled()
{
$id_shops = Shop::getContextListShopID();

$select = 'SELECT m.`id_module`, m.`name`, m.`version`';
$from = ' FROM `' . _DB_PREFIX_ . 'module` m';
$from .= ' INNER JOIN `' . _DB_PREFIX_ . 'module_shop` ms ON ms.`id_module` = m.`id_module`';
$from .= ' AND ms.`id_shop` IN (' . (implode(',', array_map('intval', $id_shops))) . ')';

return Db::getInstance()->executeS($select . $from);
}

/**
* Returns the list of the payment module associated to the current customer.
*
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ protected function formatCategoryDiscountList($id_group)

public function formatModuleListAuth($id_group)
{
$modules = Module::getModulesInstalled();
$modules = Module::getModulesInstalledAndEnabled();
$authorized_modules = '';

$auth_modules = [];
Expand Down
10 changes: 10 additions & 0 deletions src/Adapter/Module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,16 @@ public function getModulesInstalled($position = 0)
return LegacyModule::getModulesInstalled((int) $position);
}

/**
* Return modules that are installed AND enabled
*
* @return array Modules
*/
public function getModulesInstalledAndEnabled()
{
return LegacyModule::getModulesInstalledAndEnabled();
}

/**
* Return an instance of the specified module.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function indexAction(Request $request)

$moduleAdapter = $this->get('prestashop.adapter.legacy.module');
$hookProvider = $this->get('prestashop.adapter.legacy.hook');
$installedModules = $moduleAdapter->getModulesInstalled();
$installedModules = $moduleAdapter->getModulesInstalledAndEnabled();

$selectedModule = $request->get('show_modules');
if ($selectedModule && (string) $selectedModule != 'all') {
Expand Down