Example #1
0
/**
 * Add module in claroline, giving  its path
 *
 * @param string $modulePath
 * @return int module id or false
 * @todo remove the need of the Backlog and use Exceptions instead
 */
function register_module($modulePath)
{
    $backlog = new Backlog();
    if (file_exists($modulePath)) {
        /*$parser = new ModuleManifestParser;
          $module_info = $parser->parse($modulePath.'/manifest.xml');*/
        $module_info = readModuleManifest($modulePath);
        if (false === $module_info) {
            $backlog->failure(get_lang('Cannot parse module manifest'));
            $moduleId = false;
        } elseif (is_array($module_info) && false !== ($moduleId = register_module_core($module_info))) {
            $backlog->failure(get_lang('Module %claroLabel registered', array('%claroLabel' => $module_info['LABEL'])));
            if ('TOOL' == strtoupper($module_info['TYPE'])) {
                if (false !== ($toolId = register_module_tool($moduleId, $module_info))) {
                    $backlog->failure(get_lang('Module %label registered as tool', array('%claroLabel' => $module_info['LABEL'])));
                } else {
                    $backlog->failure(get_lang('Cannot register tool %label', array('%label' => $module_info['LABEL'])));
                }
            } elseif ('APPLET' == strtoupper($module_info['TYPE'])) {
                if (array_key_exists('DEFAULT_DOCK', $module_info) && is_array($module_info['DEFAULT_DOCK'])) {
                    foreach ($module_info['DEFAULT_DOCK'] as $dock) {
                        add_module_in_dock($moduleId, $dock);
                        $backlog->failure(get_lang('Module %label added in dock : %dock', array('%label' => $module_info['LABEL'], '%dock' => $dock)));
                    }
                }
            }
        } else {
            $backlog->failure(get_lang('Cannot register module %label', array('%label' => $module_info['LABEL'])));
        }
    } else {
        $backlog->failure(get_lang('Cannot find module'));
    }
    return $moduleId;
}
Example #2
0
// Security Check
if (!claro_is_platform_admin()) {
    upgrade_disp_auth_form();
}
if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'run') {
    // DB tables definition
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_module = $tbl_mdb_names['module'];
    $tbl_module_info = $tbl_mdb_names['module_info'];
    $tbl_module_contexts = $tbl_mdb_names['module_contexts'];
    $modules = claro_sql_query_fetch_all("SELECT label, id, name FROM `{$tbl_module}`");
    $deactivatedModules = array();
    $readOnlyModules = array('CLDOC', 'CLGRP', 'CLUSR');
    $version = '';
    foreach ($modules as $module) {
        $manifest = readModuleManifest(get_module_path($module['label']));
        if ($manifest) {
            $version = array_key_exists('CLAROLINE_MAX_VERSION', $manifest) ? $manifest['CLAROLINE_MAX_VERSION'] : $manifest['CLAROLINE_MIN_VERSION'];
            if (!in_array($module['label'], $readOnlyModules) && !preg_match($patternVarVersion, $version)) {
                deactivate_module($module['id']);
                $deactivatedModules[] = $module;
            }
        }
    }
    $display = DISPLAY_RESULT_SUCCESS_PANEL;
}
// Display Header
echo upgrade_disp_header();
// Display Content
switch ($display) {
    case DISPLAY_WELCOME_PANEL:
Example #3
0
/**
 * Upgrade module (from main database) to 1.8
 * @return step value, 0 if succeed
 */
function upgrade_main_database_module_to_18()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tool = 'MODULE_18';
    switch ($step = get_upgrade_status($tool)) {
        case 1:
            // module
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['module'] . "` (\n              `id`         smallint    unsigned             NOT NULL auto_increment,\n              `label`      char(8)                          NOT NULL default '',\n              `name`       char(100)                        NOT NULL default '',\n              `activation` enum('activated','desactivated') NOT NULL default 'desactivated',\n              `type`       enum('tool','applet')            NOT NULL default 'applet',\n              `script_url` char(255)                        NOT NULL default 'entry.php',\n              PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM";
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['module_info'] . "` (\n              id             smallint     NOT NULL auto_increment,\n              module_id      smallint     NOT NULL default '0',\n              version        varchar(10)  NOT NULL default '',\n              author         varchar(50)  default NULL,\n              author_email   varchar(100) default NULL,\n              author_website varchar(255) default NULL,\n              description    varchar(255) default NULL,\n              website        varchar(255) default NULL,\n              license        varchar(50)  default NULL,\n              PRIMARY KEY (id)\n            ) ENGINE=MyISAM AUTO_INCREMENT=0";
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['dock'] . "` (\n              id        smallint unsigned NOT NULL auto_increment,\n              module_id smallint unsigned NOT NULL default '0',\n              name      varchar(50)          NOT NULL default '',\n              rank      tinyint  unsigned NOT NULL default '0',\n              PRIMARY KEY  (id)\n            ) ENGINE=MyISAM AUTO_INCREMENT=0";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
            unset($sqlForUpdate);
        case 3:
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n                             SET claro_label = TRIM(TRAILING '_' FROM claro_label )";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n                             SET `script_url` = SUBSTRING_INDEX( `script_url` , '/', -1 ) ";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "`\n                             SET `script_url` = 'exercise.php' WHERE `script_url` = 'exercice.php' ";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
            unset($sqlForUpdate);
        case 4:
            // include libray to manage module
            require_once $GLOBALS['includePath'] . '/lib/module/manage.lib.php';
            $error = false;
            $sql = " SELECT id, claro_label, script_url, icon, def_access, def_rank, add_in_course, access_manager\n                     FROM `" . $tbl_mdb_names['tool'] . "`";
            $toolList = claro_sql_query_fetch_all($sql);
            foreach ($toolList as $tool) {
                $toolLabel = $tool['claro_label'];
                // get module path, for read module manifest
                $toolPath = get_module_path($toolLabel);
                if (($toolInfo = readModuleManifest($toolPath)) !== false) {
                    // get script url
                    if (isset($toolInfo['ENTRY'])) {
                        $script_url = $toolInfo['ENTRY'];
                    } else {
                        $script_url = 'entry.php';
                    }
                } else {
                    // init toolInfo
                    $toolInfo['LABEL'] = $tool['claro_label'];
                    $toolInfo['NAME'] = $tool['claro_label'];
                    $toolInfo['TYPE'] = 'tool';
                    $toolInfo['VERSION'] = '1.8';
                    $toolInfo['AUTHOR']['NAME'] = '';
                    $toolInfo['AUTHOR']['EMAIL'] = '';
                    $toolInfo['AUTHOR']['WEB'] = '';
                    $toolInfo['DESCRIPTION'] = '';
                    $toolInfo['LICENSE'] = 'unknown';
                    $script_url = $tool['script_url'];
                }
                // fill table module and module_info
                // code from register_module_core from inc/lib/module.manage.lib.php
                $sql = "INSERT INTO `" . $tbl_mdb_names['module'] . "`\n                        SET label      = '" . claro_sql_escape($toolInfo['LABEL']) . "',\n                            name       = '" . claro_sql_escape($toolInfo['NAME']) . "',\n                            type       = '" . claro_sql_escape($toolInfo['TYPE']) . "',\n                            activation = 'activated' ,\n                            script_url = '" . claro_sql_escape($script_url) . "'";
                $moduleId = claro_sql_query_insert_id($sql);
                $sql = "INSERT INTO `" . $tbl_mdb_names['module_info'] . "`\n                        SET module_id    = " . (int) $moduleId . ",\n                            version      = '" . claro_sql_escape($toolInfo['VERSION']) . "',\n                            author       = '" . claro_sql_escape($toolInfo['AUTHOR']['NAME']) . "',\n                            author_email = '" . claro_sql_escape($toolInfo['AUTHOR']['EMAIL']) . "',\n                            website      = '" . claro_sql_escape($toolInfo['AUTHOR']['WEB']) . "',\n                            description  = '" . claro_sql_escape($toolInfo['DESCRIPTION']) . "',\n                            license      = '" . claro_sql_escape($toolInfo['LICENSE']) . "'";
                if (upgrade_sql_query($sql) === false) {
                    $error = true;
                    break;
                }
            }
            if (!$error) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
        default:
            $step = set_upgrade_status($tool, 0);
            return $step;
    }
    return false;
}