function _unused_modules_add_project_path in Unused Modules 7
Same name and namespace in other branches
- 6 unused_modules.module \_unused_modules_add_project_path()
Add project path.
Group modules by 'project' and extract their lowest common basepath.
1 call to _unused_modules_add_project_path()
- _unused_modules_get_available_modules in ./
unused_modules.inc - Returns an array of available modules.
File
- ./
unused_modules.inc, line 121 - Common Unused Modules functionality.
Code
function _unused_modules_add_project_path(&$modules) {
// Group modules by project.
$modules_grouped_by_project = array();
foreach ($modules as $module) {
$modules_grouped_by_project[$module->project][$module->name] = $module;
}
// Add project_path to module.
foreach ($modules_grouped_by_project as $project) {
// Determine common basepath by looking for needle "/<project>/" in uri.
// As a fallback use the shortest path method.
foreach ($project as $module) {
if (isset($module->error) && $module->error !== TRUE) {
$needle = "/" . $module->project . "/";
$before_needle = TRUE;
$project_path = strstr($module->uri, $needle, $before_needle) . "/" . $module->project;
$module->project_path = $project_path;
}
}
// Fallback: determine common basepath by picking the shortest path of all
// project modules.
if (!isset($module->project_path)) {
$project_paths = array();
foreach ($project as $module) {
$project_paths[] = $module->module_path;
}
// Get length of each module path in a project.
$lengths = array_map('strlen', $project_paths);
// Sort by value (lowest number first).
asort($lengths);
// Get lowest key.
reset($lengths);
$key = key($lengths);
// Shortest path.
$shortest_path = $project_paths[$key];
// Add the project_path to each module.
foreach ($project as $module) {
$module->project_path = $shortest_path;
}
}
unset($project_paths);
}
}