Hello,
I am wondering if there's any collective will to
Add:
module_installed($module)
Alongside:
module_exists($module)
In:
core/includes/modules.inc
Here's the source for module_exists($module)
/**
* Determines whether a given module exists.
*
* @param string $module
* The name of the module (without the .module extension).
*
* @return bool
* TRUE if the module is both installed and enabled, FALSE otherwise.
*/
function module_exists($module) {
$list = module_list();
return isset($list[$module]);
}
Here's what I whipped up for module_installed($module)
/**
*
* @name
* module_installed()
*
* @description
* Determines if a module is installed or not.
*
* @param string $module
* The name of the module (without the .module extension).
*
* @return bool
* TRUE if the module is installed, FALSE otherwise.
*/
function module_installed($module) {
$result = db_query("SELECT * FROM {system} WHERE type = 'module' AND name = '" . $module . "'");
return $result->rowcount() ? TRUE : FALSE;
}
Comments
The system table shows rows of modules that are or were present in the codebase. So it would be unreliable.
Perhaps if I understood what you're trying to accomplish. Are you saying "installed" as in the module code is present, or that the module is enabled? If the latter then module_exists() already does that. As for the former, I don't think there's a performant way to do that.
In addition to what Herb said, it's important to clarify the terminology used by Backdrop.
The list of modules displayed in
/admin/modules
is the result of reading the.info
files placed within the usual module locations (modules
folder,core/modules
folder andsites/XXX/modules
folder), and lists any module that containstype = module
in those .info files. This list is stored in thesystem
table. When you remove a module folder from themodules
folder, thesystem
table will not be updated (and the module record will not be removed) until you either clear caches, or visit theadmin/module
page. Therefore, your code (IF what you are trying to do is to see if the module code is in themodules
folder) will be unreliable.In addition, your syntax for
db_query
is not great. You don't want to concatenate strings for the query. Instead you should use placeholders.