/** * Return the dependance Tree * @param : string $moduleName : moduleName to use * @param : string $todo : action (add // remove) * @param : array $arModules : modules to remove/add */ function _getDependenciesArray($moduleName, $toDo, $arModules) { if ($toDo == "add") { $toCheck = CopixModule::getInformations($moduleName); foreach ($toCheck->dependencies as $dependency) { if (!in_array($dependency, CopixModule::getList(true)) && !in_array($dependency, $arModules)) { $arModules[] = $dependency; $arModules = CopixModule::_getDependenciesArray($dependency, $toDo, $arModules); } } } elseif ($toDo == "remove") { $strResult = ''; foreach (CopixModule::getList(true) as $installedModule) { $toCheck = CopixModule::getInformations($installedModule); foreach ((array) $toCheck->dependencies as $dependency) { if ($dependency == $moduleName && !in_array($toCheck->name, $arModules)) { $arModules[] = $toCheck->name; $arModules = CopixModule::_getDependenciesArray($toCheck->name, $toDo, $arModules); } } } } return $arModules; }
/** * Install module given in parameter */ function doInstallModule() { $service =& CopixClassesFactory::Create('InstallService'); $action = $this->vars['todo']; $tpl =& new CopixTpl(); $toAdd = array(); $toDelete = array(); if ($action == 'add') { $toAdd = CopixModule::_getDependenciesArray($this->vars['moduleName'], $action, array()); $toAdd[] = $this->vars['moduleName']; $this->_setSessionInstallModules($toAdd); } elseif ($action == 'remove') { $toDelete = CopixModule::_getDependenciesArray($this->vars['moduleName'], $action, array()); $toDelete[] = $this->vars['moduleName']; $this->_setSessionInstallModules($toDelete); } $tpl->assign('TITLE_PAGE', CopixI18N::get('install.title.manageModules')); $tpl->assign('MAIN', CopixZone::process('install|installconfirm', array('toAdd' => $toAdd, 'toDelete' => $toDelete))); return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl); }