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
/** 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;
}