Restricting Module Installation

 

As of FreePBX 2.11, developers are now able to restrict module installation for reasons such as conflicting modules, compatibility issues, etc. To do this we need to add one function to our module and let module.xml know where to find this function.

In module.xml we introduced the fileinclude tag. This tag allows us to include files into FreePBX framework immediately after a module is un/installed. Nested under the fileinclude tag, we can have as may install or uninstall tags as necessary.

 

<fileinclude>     <install>install.inc.php</install>     <uninstall>uninstall.inc.php</uninstall> </fileinclude>

 

After telling FreePBX about the file, we still need a way to check the installation of other modules. We do this by adding a module_install_check_callback function into the install.inc.php file we told module.xml about above. The purpose of this function is to check for conflicting modules and provide an error message with more information if a conflicting module is attempting to be installed. In the example below, we are working in the OSS endpoint manager and adding the commercial endpoint module as a conflicting module.

 

The following code snippet assumes that endpointman is already installed, and we are checking against other modules being installed:

function endpointman_module_install_check_callback($mods = array()) {     global $active_modules;     $ret = array();     $current_mod = 'endpointman';     $conflicting_mods = array('endpoint');     foreach($mods as $k => $v) {         if (in_array($k, $conflicting_mods) && !in_array($active_modules[$current_mod]['status'],array(MODULE_STATUS_NOTINSTALLED,MODULE_STATUS_BROKEN))) {             $ret[] = $v['name'];         }     }     if (!empty($ret)) {         $modules = implode(',',$ret);         return _('Failed to install ' . $modules . ' due to the following conflicting module(s): ' . $active_modules[$current_mod]['displayname']);     }     return TRUE; }

To do the same check on install of your module, you would do the following:

function endpointman_module_install_check_callback($mods = array()) {     global $active_modules;         $ret = array();         $conflicting_mods = array('endpoint');     $mod_keys = array_keys($active_modules);         foreach($conflicting_mods as $cm) {         if (in_array($cm, $mod_keys)) {             $ret[] = $active_modules[$cm]['name'];         }     }     if (!empty($ret)) {         $modules = implode(',',$ret);         return _('Failed to install due to the following conflicting module(s): ' . $modules);     }     return TRUE; }

Or combining the two which will do the check both during install and on the install of any other modules:

Return to Documentation Home I Return to Sangoma Support