[Vtigercrm-developers] How to delete/uninstall a module

Hamono, Chris (DPC) Chris.Hamono at sa.gov.au
Tue Jul 7 02:55:32 GMT 2015


There is often a need to uninstall a module, community vtiger (6.2) does not have a built in way to do this.

There is some code here...
https://discussions.vtiger.com/index.php?p=/discussion/28895/how-to-uninstall-one-module/p1

I thought I'd improve on the code a little bit and include it here for others with the need

Please remember to delete the file after uninstalling the module it is definitely a security risk!!!
An additional test would be to ensure only a logged in admin could run this file but as the need is so low I didn't think it was worth the extra effort

Call it like thus...

Mydomain.moc/vtigerfolder/deletemodule.php?modulename=MyRss


Chris

deletemodule.php

<?php
/*
* Delete a vtiger module
*
* based on code at
* https://discussions.vtiger.com/index.php?p=/discussion/28895/how-to-uninstall-one-module/p1
*
* assumes it is being called from a webbrowser
* modifications are required if called from the CLI
*
*/

error_reporting(E_ALL); // & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
ini_set('display_errors', 1);

require_once('vtlib/Vtiger/Module.php');

// we need these functions to continue
if (!function_exists('vtlib_isModuleActive') || !class_exists('Vtiger_Module')) {
    die("Unable to process request; unmet needs");
}

// get the name from the commandline
$modulename = (!empty($_GET['modulename'])) ? $_GET['modulename'] : null;

// have we been provided a name?
if (!$modulename) {
    die("modulename is required");
}

// is the name valid(ish)
if (preg_match('/[^a-zA-Z_-]/', $modulename)) {
    die("modulename {$modulename} not valid");
}


// load the module
$module = Vtiger_Module::getInstance($modulename);

if ($module) {

// check if the module is active if so it cant be deleted
    if (vtlib_isModuleActive($modulename)) {
        die("You cannot delete an active module");
    }
    echo "Module {$modulename} is about to be deleted<br/>\n";

// Delete from system
    $module->delete();
    echo "Module {$modulename} deleted!<br/>\n";
    echo "Please manually delete the source files for {$modulename}, Do not forget layout files, language files and other possible files";
} else {
    echo "Module {$modulename} was not found and could not be deleted!";
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20150707/278036f1/attachment.html>


More information about the vtigercrm-developers mailing list