Example #1
0
 case 'install':
     if (!EXTERNAL_PACKAGE_MANAGEMENT) {
         if (is_array($errors = module_checkdepends($modules[$module]))) {
             $skipaction = true;
             $errorstext[] = sprintf($modules[$module]['status'] == MODULE_STATUS_NEEDUPGRADE ? _("%s cannot be upgraded: %s Please try again after the dependencies have been installed.") : _("%s cannot be installed: %s Please try again after the dependencies have been installed."), $modules[$module]['name'], '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>');
         } else {
             if ($modules[$module]['status'] == MODULE_STATUS_NEEDUPGRADE) {
                 $actionstext[] = sprintf(_("%s %s will be upgraded to %s"), $modules[$module]['name'], $modules[$module]['dbversion'], $modules[$module]['version']);
             } else {
                 $actionstext[] = sprintf(_("%s %s will be installed and enabled"), $modules[$module]['name'], $modules[$module]['version']);
             }
         }
     }
     break;
 case 'enable':
     if (is_array($errors = module_checkdepends($modules[$module]))) {
         $skipaction = true;
         $errorstext[] = sprintf(_("%s cannot be enabled: %s Please try again after the dependencies have been installed."), $modules[$module]['name'], '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>');
     } else {
         $actionstext[] = sprintf(_("%s %s will be enabled"), $modules[$module]['name'], $modules[$module]['dbversion']);
     }
     break;
 case 'disable':
     if (is_array($errors = module_reversedepends($modules[$module]))) {
         $skipaction = true;
         $errorstext[] = sprintf(_("%s cannot be disabled because the following modules depend on it: %s Please disable those modules first then try again."), $modules[$module]['name'], '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>');
     } else {
         $actionstext[] = sprintf(_("%s %s will be disabled"), $modules[$module]['name'], $modules[$module]['dbversion']);
     }
     break;
 case 'uninstall':
Example #2
0
/** Installs or upgrades a module from it's directory
 * Checks dependencies, and enables
 * @param string   The name of the module to install
 * @param bool     If true, skips status and dependency checks
 * @return mixed   True if succesful, array of error messages if not succesful
 */
function module_install($modulename, $force = false)
{
    global $db, $amp_conf;
    if ($time_limit = ini_get('max_execution_time')) {
        set_time_limit($time_limit);
    }
    $modules = module_getinfo($modulename);
    // make sure we have a directory, to begin with
    $dir = $amp_conf['AMPWEBROOT'] . '/admin/modules/' . $modulename;
    if (!is_dir($dir)) {
        return array(_("Cannot find module"));
    }
    // read the module.xml file
    $modules = module_getinfo($modulename);
    if (!isset($modules[$modulename])) {
        return array(_("Could not read module.xml"));
    }
    // don't force this bit - we can't install a broken module (missing files)
    if ($modules[$modulename]['status'] == MODULE_STATUS_BROKEN) {
        return array(_("Module " . $modules[$modulename]['rawname'] . " is broken and cannot be installed. You should try to download it again."));
    }
    if (!$force) {
        if (!in_array($modules[$modulename]['status'], array(MODULE_STATUS_NOTINSTALLED, MODULE_STATUS_NEEDUPGRADE))) {
            //return array(_("This module is already installed."));
            // This isn't really an error, we just exit
            return true;
        }
        // check dependencies
        if (is_array($errors = module_checkdepends($modules[$modulename]))) {
            return $errors;
        }
    }
    // run the scripts
    if (!_module_runscripts($modulename, 'install')) {
        return array(_("Failed to run installation scripts"));
    }
    if ($modules[$modulename]['status'] == MODULE_STATUS_NOTINSTALLED) {
        // customize INSERT query
        $sql = "INSERT INTO modules (modulename, version, enabled) values ('" . $db->escapeSimple($modules[$modulename]['rawname']) . "','" . $db->escapeSimple($modules[$modulename]['version']) . "', 1);";
    } else {
        // just need to update the version
        $sql = "UPDATE modules SET version='" . $db->escapeSimple($modules[$modulename]['version']) . "' WHERE modulename = '" . $db->escapeSimple($modules[$modulename]['rawname']) . "'";
    }
    // run query
    $results = $db->query($sql);
    if (DB::IsError($results)) {
        return array(sprintf(_("Error updating database. Command was: %s; error was: %s "), $sql, $results->getMessage()));
    }
    // module is now installed & enabled, invalidate the modulelist class since it is now stale
    $modulelist =& modulelist::create($db);
    $modulelist->invalidate();
    // edit the notification table to list any remaining upgrades available or clear
    // it if none are left. It requres a copy of the most recent module_xml to compare
    // against the installed modules.
    //
    $sql = 'SELECT data FROM module_xml WHERE id = "xml"';
    $data = sql($sql, "getOne");
    $parser = new xml2ModuleArray($data);
    $xmlarray = $parser->parseAdvanced($data);
    $new_modules = array();
    if (count($xmlarray)) {
        foreach ($xmlarray['xml']['module'] as $mod) {
            $new_modules[$mod['rawname']] = $mod;
        }
    }
    module_upgrade_notifications($new_modules, 'PASSIVE');
    needreload();
    return true;
}