コード例 #1
0
ファイル: manage.lib.php プロジェクト: rhertzog/lcs
/**
 * Uninstall a specific module to the platform
 *
 * @param integer $moduleId the id of the module to uninstall
 * @return array( backlog, boolean )
 *      backlog object
 *      boolean true if the uninstall process suceeded, false otherwise
 * @todo remove the need of the Backlog and use Exceptions instead
 */
function uninstall_module($moduleId, $deleteModuleData = true)
{
    $success = true;
    $backlog = new Backlog();
    //first thing to do : deactivate the module
    // deactivate_module($moduleId);
    $moduleInfo = get_module_info($moduleId);
    if ($moduleInfo['type'] == 'tool' && $moduleId) {
        // 2- delete the module in the cours_tool table, used for every course creation
        list($backlog2, $success2) = unregister_module_from_courses($moduleId);
        if ($success2) {
            $backlog->success(get_lang('Module uninstalled in all courses'));
        } else {
            $backlog->append($backlog2);
        }
    }
    //Needed tables and vars
    $tbl = claro_sql_get_main_tbl();
    $backlog = new Backlog();
    // 0- find info about the module to uninstall
    $sql = "SELECT `label`\n              FROM `" . $tbl['module'] . "`\n             WHERE `id` = " . (int) $moduleId;
    $module = claro_sql_query_get_single_row($sql);
    if ($module == false) {
        $backlog->failure(get_lang("No module to uninstall"));
        $success = false;
    } else {
        // 1- Include the local 'uninstall.sql' and 'uninstall.php' file of the module if they exist
        // call uninstall.php first in case it requires module database schema to run
        if (isset($uninstallPhpScript)) {
            unset($uninstallPhpScript);
        }
        $uninstallPhpScript = get_module_path($module['label']) . '/setup/uninstall.php';
        if (file_exists($uninstallPhpScript)) {
            language::load_translation();
            language::load_locale_settings();
            language::load_module_translation($module['label']);
            load_module_config($module['label']);
            require $uninstallPhpScript;
            $backlog->info(get_lang('Module uninstallation script called'));
        }
        if (isset($uninstallSqlScript)) {
            unset($uninstallSqlScript);
        }
        $uninstallSqlScript = get_module_path($module['label']) . '/setup/uninstall.sql';
        if ($deleteModuleData && file_exists($uninstallSqlScript)) {
            $sql = file_get_contents($uninstallSqlScript);
            if (!empty($sql)) {
                $sql = str_replace('__CL_MAIN__', get_conf('mainTblPrefix'), $sql);
                if (false !== claro_sql_multi_query($sql)) {
                    $backlog->success(get_lang('Database uninstallation succeeded'));
                } else {
                    $backlog->failure(get_lang('Database uninstallation failed'));
                    $success = false;
                }
            }
        } elseif (!$deleteModuleData && file_exists($uninstallSqlScript)) {
            $backlog->info(get_lang('Database uninstallation skipped'));
        }
        // 2- delete related files and folders
        $modulePath = get_module_path($module['label']);
        if (file_exists($modulePath)) {
            if (claro_delete_file($modulePath)) {
                $backlog->success(get_lang('Delete scripts of the module'));
            } else {
                $backlog->failure(get_lang('Error while deleting the scripts of the module'));
                $success = false;
            }
        }
        //  delete the module in the cours_tool table, used for every course creation
        //retrieve this module_id first
        $sql = "SELECT id as tool_id FROM `" . $tbl['tool'] . "`\n                WHERE claro_label = '" . $module['label'] . "'";
        $tool_to_delete = claro_sql_query_get_single_row($sql);
        $tool_id = $tool_to_delete['tool_id'];
        $sql = "DELETE FROM `" . $tbl['tool'] . "`\n                WHERE claro_label = '" . $module['label'] . "'\n            ";
        claro_sql_query($sql);
        // 3- delete related entries in main DB
        $sql = "DELETE FROM `" . $tbl['module'] . "`\n                WHERE `id` = " . (int) $moduleId;
        claro_sql_query($sql);
        $sql = "DELETE FROM `" . $tbl['module_info'] . "`\n                WHERE `module_id` = " . (int) $moduleId;
        claro_sql_query($sql);
        $sql = "DELETE FROM `" . $tbl['module_contexts'] . "`\n                WHERE `module_id` = " . (int) $moduleId;
        claro_sql_query($sql);
        // 4-Manage right - Delete read action
        $action = new RightToolAction();
        $action->setName('read');
        $action->setToolId($tool_id);
        $action->delete();
        // Manage right - Delete edit action
        $action = new RightToolAction();
        $action->setName('edit');
        $action->setToolId($tool_id);
        $action->delete();
        // 5- remove all docks entries in which the module displays
        // TODO FIXME handle failure
        remove_module_dock($moduleId, 'ALL');
        // 6- cache file with the module's include must be renewed after uninstallation of the module
        if (!generate_module_cache()) {
            $backlog->failure(get_lang('Module cache update failed'));
            $success = false;
        } else {
            $backlog->success(get_lang('Module cache update succeeded'));
        }
    }
    return array($backlog, $success);
}
コード例 #2
0
ファイル: backlog.class.php プロジェクト: rhertzog/lcs
 function main()
 {
     $bl = new Backlog();
     echo '<pre>';
     $bl->success('message success 1');
     $bl->debug('message debug 1');
     $bl->failure('message failure 1');
     $bl->success('message success 2');
     $bl->info('message info 1');
     var_dump($bl->size());
     var_dump($bl->_size);
     echo '</pre>';
     echo '<pre>';
     echo $bl->output();
     echo '</pre>';
     echo 'Append';
     echo '<pre>';
     $bl->append($bl);
     echo $bl->output();
     echo '</pre>';
 }
コード例 #3
0
ファイル: module.lib.php プロジェクト: rhertzog/lcs
/**
 * Remove database for all modules in the given course
 * @param   string courseId
 * @return  array(
 *  boolean success
 *  Backlog log )
 * @author  Frederic Minne <*****@*****.**>
 */
function delete_all_modules_from_course($courseId)
{
    $backlog = new Backlog();
    $success = true;
    if (!($moduleLabelList = get_module_label_list(false))) {
        $success = false;
        $backlog->failure(claro_failure::get_last_failure());
    } else {
        foreach ($moduleLabelList as $moduleLabel) {
            if (!delete_module_in_course($moduleLabel, $courseId)) {
                $backlog->failure(get_lang('delete failed for module %module', array('%module' => $moduleLabel)));
                $success = false;
            } else {
                $backlog->success(get_lang('delete succeeded for module %module', array('%module' => $moduleLabel)));
            }
        }
    }
    return array($success, $backlog);
}