If a module wants to update and extension number to a new number, any module currently using that as a destination will have their destination broken. We need a callback with an associated framework function that can tell all modules to use the new destination.
The framework function would be called like this:
framework_change_destination(modulename_getdest($old_exten),modulename_getdest($new_exten))
where modulename is the calling module.
Each module would implement:
modulename_change_destination($old_dest, $new_dest)
Examples of the framework module and an example from ringgroups implementation would look like the following below, and where the modulename_change_destination() callback will be implemented by all modules that use and thus store one or more destinations.
Here are examples what I think the framework and example ringgroup callback would look like:
function ringgroups_change_destination($old_dest, $new_dest) {
$sql = "UPDATE ringgroups SET postdest = '$new_dest' WHERE postdest = '$old_dest'";
$results = sql($sql,"query");
return $results->numRows();
}
/** check if a specific destination is being used, or get a list of all destinations that are being used
* @param string the old destination that is being changed
* @param string the new destination that is replacing the old
* @param array a hash of module names to search for callbacks, otherwise global $active_modules is used
* @return integer returns the number of records that were updated
* @description has each module replace their destination information with another one, used if you are
* assigning a new number to something such as a conference room that may be used as a destination
*
*/
function framework_change_destination($old_dest, $new_dest, $module_hash=false) {
global $db;
global $active_modules;
$old_dest = $db->escapeSimple($old_dest);
$new_dest = $db->escapeSimple($new_dest);
if (!is_array($module_hash)) {
$module_hash = $active_modules;
}
$total_updated = 0;
foreach(array_keys($module_hash) as $mod) {
$function = $mod."_change_destination";
if (function_exists($function)) {
$total_updated += $function($dest);
}
}
return $total_update;