Editing an extension always fails for duplicated DID

I’m using freepbx 2.2.2 with CustomContext and Dialplan Injection supplementary modules.
When I try to edit an Extension that has a non-blank Direct DID field, I always obtain “This DID is already associated with extension”.
I found that the new code that should avoid creating duplicated DIDs goes too far: it reports that the DID already exists, even if the Extension owning that DID is exactly the one that is being modified.
This is due to the fact that the code does not distinguish if the extension found having the same DID as the one being modified, is exactly the same extension.

I wrote the following simple patch to avoid this behaviour:

[code:1]— freepbx-2.2.2.orig/amp_conf/htdocs/admin/modules/core/functions.inc.php.orig 2007-06-10 15:14:27.000000000 +0200
+++ freepbx-2.2.2.orig/amp_conf/htdocs/admin/modules/core/functions.inc.php 2007-06-23 00:18:59.000000000 +0200
@@ -1355,7 +1355,7 @@
if (trim($directdid) != “”) {
$existing_directdid = empty($existing)?core_users_directdid_get($directdid):$existing;

  •           if (!empty($existing) || !empty($existing_directdid)) {
  •           if (!empty($existing) || ( !empty($existing_directdid) && $existing_directdid['extension'] != $extension ) ) {
                      if (!empty($existing)) {
                              echo "<script>javascript:alert('"._("A route with this DID already exists:")." ".$existing['extension']."')</script>";
                      } else {[/code:1]

It seems it’s working for me. Is there someone comfortable with freepbx coed who can review it and in case apply it to the main codebase?

more or less the same patch has already been applied to the code base:


it will come out in a 2.2.3 maintenace release but you can pull form svn if you want (or keep yours until then). I’ll be waiting just a bit to do another maintance release of 2.2.2 because the 2.3 beta program will probably fulush out other bugs that get back ported to 2.2 branch.