/** * Install a specific module to the platform * @param string $modulePath path to the module * @param bool $skipCheckDir skip checking if module directory already exists (default false) * @return array( backlog, int ) * backlog object containing the messages * int moduleId if the install process suceeded, false otherwise * @todo remove the need of the Backlog and use Exceptions instead */ function install_module($modulePath, $skipCheckDir = false, $registerModuleInCourses = false) { $backlog = new Backlog(); $moduleId = false; if (false === ($module_info = readModuleManifest($modulePath))) { claro_delete_file($modulePath); $backlog->failure(claro_failure::get_last_failure()); } else { //check if a module with the same LABEL is already installed, if yes, we cancel everything // TODO extract from install function should be tested BEFORE calling install_module if (!$skipCheckDir && check_name_exist(get_module_path($module_info['LABEL']) . '/')) { $backlog->failure(get_lang('Module %module is already installed on your platform', array('%module' => $module_info['LABEL']))); // claro_delete_file($modulePath); // TODO : add code to point on existing instance of tool. // TODO : how to overwrite . prupose uninstall ? } else { //3- Save the module information into DB if (false === ($moduleId = register_module_core($module_info))) { claro_delete_file($modulePath); $backlog->failure(claro_failure::get_last_failure()); $backlog->failure(get_lang('Module registration failed')); } else { //in case of tool type module, the dock can not be selected and must added also now if ('tool' == $module_info['TYPE']) { // TODO FIXME handle failure register_module_tool($moduleId, $module_info); } if (array_key_exists('DEFAULT_DOCK', $module_info)) { foreach ($module_info['DEFAULT_DOCK'] as $dock) { // TODO FIXME handle failure add_module_in_dock($moduleId, $dock); } } //4- Rename the module repository with label $currentPlace = realpath($modulePath) . '/'; $destPath = get_module_path($module_info['LABEL']); claro_mkdir(get_path('rootSys') . 'module/', CLARO_FILE_PERMISSIONS, true); if (!@rename($currentPlace, $destPath)) { $backlog->failure(get_lang("Error while renaming module folder") . ' from:' . $currentPlace . ' to:' . $destPath); } else { // force access rights on module root dir after rename() because some modules written on M$ Win$#!t are causing issues chmod($destPath, CLARO_FILE_PERMISSIONS); //5-Include the local 'install.sql' and 'install.php' file of the module if they exist if (isset($installSqlScript)) { unset($installSqlScript); } $installSqlScript = get_module_path($module_info['LABEL']) . '/setup/install.sql'; if (file_exists($installSqlScript)) { $sql = file_get_contents($installSqlScript); if (!empty($sql)) { $sql = str_replace('__CL_MAIN__', get_conf('mainTblPrefix'), $sql); if (claro_sql_multi_query($sql) === false) { $backlog->failure(get_lang('Sql installation query failed')); } else { $backlog->failure(get_lang('Sql installation query succeeded')); } } } // generate the conf if a def file exists if (file_exists(get_module_path($module_info['LABEL']) . '/conf/def/' . $module_info['LABEL'] . '.def.conf.inc.php')) { require_once dirname(__FILE__) . '/../config.lib.inc.php'; $config = new Config($module_info['LABEL']); list($confMessage, $status) = generate_conf($config); $backlog->info($confMessage); } // call install.php after initialising database in case it requires database to run if (isset($installPhpScript)) { unset($installPhpScript); } $installPhpScript = get_module_path($module_info['LABEL']) . '/setup/install.php'; if (file_exists($installPhpScript)) { language::load_translation(); language::load_locale_settings(); language::load_module_translation($module_info['LABEL']); load_module_config($module_info['LABEL']); // FIXME this is very dangerous !!!! require $installPhpScript; $backlog->info(get_lang('Module installation script called')); } $moduleInfo = get_module_info($moduleId); if ($registerModuleInCourses && $moduleInfo['type'] == 'tool' && $moduleId) { list($backlog2, $success2) = register_module_in_courses($moduleId); if ($success2) { $backlog->success(get_lang('Module installed in all courses')); } else { $backlog->append($backlog2); } } //6- cache file with the module's include must be renewed after installation of the module if (!generate_module_cache()) { $backlog->failure(get_lang('Module cache update failed')); } else { $backlog->success(get_lang('Module cache update succeeded')); } } } } } return array($backlog, $moduleId); }
} else { trigger_error('module path not found', E_USER_WARNING); } } // init default right profile init_default_right_profile(); /*** * Generate module conf from definition files. */ $config_code_list = get_config_code_list('module'); if (is_array($config_code_list)) { foreach ($config_code_list as $config_code) { // new config object $config = new Config($config_code); //generate conf list($message, $configToolError) = generate_conf($config, $form_value_list); if ($configToolError) { $configError = true; $messageConfigErrorList[] = $message; } } unset($configToolError); } if ($configError) { $display = DISP_RUN_INSTALL_NOT_COMPLETE; } /** * Add administrator in user and admin table */ include_once $newIncludePath . 'lib/user.lib.php'; $user_data['lastname'] = $adminNameForm;
$out .= '<tr>' . "\n" . '<td>' . get_lang('Save') . ' :' . "\n" . '<input type="hidden" name="cmd" value="movedock" />' . "\n" . '<input type="submit" value="' . get_lang('Ok') . '" /> ' . "\n" . claro_html_button(claro_htmlspecialchars($_SERVER['HTTP_REFERER']), get_lang('Cancel')) . '</td>' . "\n" . '</tr>' . "\n" . '</tbody>' . "\n" . '</table>' . "\n" . '</dd>' . '</form>'; } } else { // nothing to do at the moment } break; case 'LOCAL': $form = ''; $url_params = '&module_id=' . $moduleId . '&item=' . claro_htmlspecialchars($item); $form = $config->display_section_menu($section_selected, $url_params); // init config name $config_name = $config->config_code; if (isset($_REQUEST['cmd']) && isset($_REQUEST['property'])) { if ('save' == $_REQUEST['cmd']) { if (!empty($_REQUEST['property'])) { list($message, $error) = generate_conf($config, $_REQUEST['property']); } } // display form $form .= $config->display_form($_REQUEST['property'], $section_selected, $url_params); } else { // display form $form .= $config->display_form(null, $section_selected, $url_params); } $out .= '<div style="padding-left:1em;padding-right:1em;">'; if (!empty($message)) { $dialogBox = new DialogBox(); $dialogBox->success($message); $out .= $dialogBox->render(); } $out .= $form . '</div>';