Ticket #4655 (closed Feature Requests: fixed)

Opened 3 years ago

Last modified 2 years ago

add module callback function to allow modules to change their assigned exten number

Reported by: p_lindheimer Assigned to: mbrevda
Priority: minor Milestone: 2.9
Component: FreePBX Framework Version: 2.8-branch
Keywords: Cc:
Confirmation: Unreviewed Distro:
Backend Engine: All Distro Ver:
Backend Ver: SVN Revision (if applicable):

Description

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;

Change History

11/25/10 10:46:43 changed by mbrevda

This would add yet another function to every module that want to implement it (in addition to those already use by the "destination registry"). We would probably be better server by creating a central destination registry where all module would store there destination, with api's to update the registry as necessary (without either the changing or the being changes module needing functions to achieve the change).

This registry can also provide other features such as a simpler and more inexpensive method of generating destinations. It may also be able to facilitate checking if a specific extension number is in use.

11/25/10 11:28:00 changed by p_lindheimer

for now we have a dynamic registry. When we decide to rewrite huge portions of FreePBX we can design how that would be. This change will take about 30 minutes to update every module in FreePBX that is already storing destinations. Re designing how registries are stored is a huge retrofit in addition to breaking every third party module that uses destinations. That is why we left the registry dynamic. For now, unless there are any flaws in this, or there is an even simple solution that has not been presented, this is simply an extension of the APIs that are already there with the other callbacks. This should have been there originally but was an oversight.

11/30/10 14:54:01 changed by mbrevda

Hmm, not thing straight atm, but we might need to pass in the CALLING module, as we probably dont want to update it?

11/30/10 15:14:23 changed by mbrevda

These are the modules that have been updated. If I missed any, please point them out:

  • announcement
  • callback
  • conferences
  • core
  • daynight
  • directory
  • disa
  • fax
  • featurecodeadmin
  • ivr
  • languages
  • miscapps
  • queues
  • ringgroups
  • timeconditions

11/30/10 15:16:11 changed by mbrevda

oops, no changes in disa

11/30/10 15:18:34 changed by mbrevda

  • status changed from new to closed.
  • resolution set to fixed.

(In [10637]) closes #4655. Thanks Philippe for the breadbord!

11/30/10 15:32:58 changed by mbrevda

(In [10638]) re #4655; oops forgot to make sure the extension isnt in use before changing it

11/30/10 16:58:27 changed by mbrevda

(In [10640]) re #4655, forgot the framework function

12/29/10 14:00:56 changed by p_lindheimer

(In [10747]) Merged revisions 10637 via svnmerge from http://www.freepbx.org/v2/svn/modules/branches/bootstrap-2.9

........

r10637 | mbrevda | 2010-11-30 12:18:34 -0800 (Tue, 30 Nov 2010) | 1 line

closes #4655. Thanks Philippe for the breadbord!

........ adds ability to change a conference room number when updating (vs. adding)

12/29/10 17:11:11 changed by p_lindheimer

(In [10756]) Merged revisions 10638 via svnmerge from http://www.freepbx.org/v2/svn/modules/branches/bootstrap-2.9

........

r10638 | mbrevda | 2010-11-30 12:32:58 -0800 (Tue, 30 Nov 2010) | 1 line

re #4655; oops forgot to make sure the extension isnt in use before changing it

........

12/29/10 18:33:28 changed by p_lindheimer

(In [10763]) Merged revisions 10561,10640,10648,10655,10728 via svnmerge from http://www.freepbx.org/v2/svn/freepbx/branches/bootstrap

........

r10561 | mickecarlsson | 2010-11-14 01:58:01 -0800 (Sun, 14 Nov 2010) | 1 line

Re #4566 dont ever remove copyrights, they are there for a reason. Update with 'Portions Copyright ...' instead

........

r10640 | mbrevda | 2010-11-30 13:58:27 -0800 (Tue, 30 Nov 2010) | 1 line

re #4655, forgot the framework function

........

r10648 | mbrevda | 2010-12-04 13:34:27 -0800 (Sat, 04 Dec 2010) | 1 line

closes #4616; closing fo rnow as this fis is reather harmless, im more concerened about the algorithm to detarmain the proper base, but nothing iwll break as a result of this. Reopen if there is a better way

........

r10728 | p_lindheimer | 2010-12-24 08:25:01 -0800 (Fri, 24 Dec 2010) | 1 line

expires changed to 24 hrs, we don't want it to be too far out or it can result in more 'bugs' being reported when upgrading. (as it stands we really do need to start versioning mainstyle.css for that same reason...)

........

01/10/11 17:10:56 changed by p_lindheimer

(In [10920]) adds _change_destination callback to missed modules re #4655