Example #1
0
/** Uninstall a module, but files remain
 * @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_uninstall($modulename, $force = false)
{
    global $db;
    $modules = module_getinfo($modulename);
    if (!isset($modules[$modulename])) {
        return array(_("Specified module not found"));
    }
    if (!$force) {
        if ($modules[$modulename]['status'] == MODULE_STATUS_NOTINSTALLED) {
            return array(_("Module not installed: cannot uninstall"));
        }
        if (($depmods = module_reversedepends($modulename)) !== false) {
            return array(_("Cannot disable: The following modules depend on this one: ") . implode(',', $depmods));
        }
    }
    $sql = "DELETE FROM modules WHERE modulename = '" . $db->escapeSimple($modulename) . "'";
    $results = $db->query($sql);
    if (DB::IsError($results)) {
        return array(_("Error updating database: ") . $results->getMessage());
    }
    if (!_module_runscripts($modulename, 'uninstall')) {
        return array(_("Failed to run un-installation scripts"));
    }
    needreload();
    return true;
}
Example #2
0
                 $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':
             if (!EXTERNAL_PACKAGE_MANAGEMENT) {
                 if (is_array($errors = module_reversedepends($modules[$module]))) {
                     $skipaction = true;
                     $errorstext[] = sprintf(_("%s cannot be uninstalled 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 uninstalled"), $modules[$module]['name'], $modules[$module]['dbversion']);
                 }
             }
             break;
     }
     // If error above we skip this action so we can proceed with the others
     //
     if (!$skipaction) {
         //TODO
         echo "\t<script type=\"text/javascript\"> moduleActions['" . $module . "'] = '" . $action . "'; </script>\n";
     }
 }
Example #3
0
/** Uninstall a module, but files remain
 * @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_uninstall($modulename, $force = false)
{
    global $db;
    global $amp_conf;
    $modules = module_getinfo($modulename);
    if (!isset($modules[$modulename])) {
        return array(_("Specified module not found"));
    }
    if (!$force) {
        if ($modules[$modulename]['status'] == MODULE_STATUS_NOTINSTALLED) {
            return array(_("Module not installed: cannot uninstall"));
        }
        if (($depmods = module_reversedepends($modulename)) !== false) {
            return array(_("Cannot disable: The following modules depend on this one: ") . implode(',', $depmods));
        }
    }
    // Check if another module wants this uninstall to be rejected
    // The module must have a callback: [modulename]_module_uninstall_check_callbak() that takes
    // a single modules array from module_getinfo() about the module to be uninstalled
    // and it must pass back boolean true if the uninstall can proceed, or a message
    // indicating why the uninstall must fail
    //
    $rejects = array();
    foreach (mod_func_iterator('module_uninstall_check_callback', $modules) as $mod => $res) {
        if ($res !== true) {
            $rejects[] = $res;
        }
    }
    if (!empty($rejects)) {
        return $rejects;
    }
    $sql = "DELETE FROM modules WHERE modulename = '" . $db->escapeSimple($modulename) . "'";
    $results = $db->query($sql);
    if (DB::IsError($results)) {
        return array(_("Error updating database: ") . $results->getMessage());
    }
    if (!_module_runscripts($modulename, 'uninstall', $modules)) {
        return array(_("Failed to run un-installation scripts"));
    }
    // Now make sure all feature codes are uninstalled in case the module has not already done it
    //
    require_once dirname(__FILE__) . '/featurecodes.class.php';
    //TODO: do we need this, now that we have bootstrap? -MB
    featurecodes_delModuleFeatures($modulename);
    $freepbx_conf =& freepbx_conf::create();
    $freepbx_conf->remove_module_settings($modulename);
    $mod_asset_dir = $amp_conf['AMPWEBROOT'] . "/admin/assets/" . $modulename;
    if (is_link($mod_asset_dir)) {
        @unlink($mod_asset_dir);
    }
    needreload();
    return true;
}