summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eba3f89)
raw | patch | inline | side by side (parent: eba3f89)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 22 Dec 2006 05:28:17 +0000 (05:28 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 22 Dec 2006 05:28:17 +0000 (05:28 +0000) |
Seems to work, testing it now
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5458 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5458 594d385d-05f5-0310-b6e9-bd551577e9d8
plugins/gofon/conference/class_phoneConferenceGeneric.inc | patch | blob | history | |
plugins/gofon/conference/class_phoneConferenceManagment.inc | patch | blob | history |
diff --git a/plugins/gofon/conference/class_phoneConferenceGeneric.inc b/plugins/gofon/conference/class_phoneConferenceGeneric.inc
index c81c29082eefc9e2aa6f5ea9449e992c047fcc01..43701df19b1a3f8dec9b3a9c4662c38d79245a56 100644 (file)
$this->base= dn2base($ui->dn);
}
} else {
- $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
+
+ /* The base is something like this
+ "cn=Confis,ou=conferences,ou=asterisk,ou=configs,ou=systems,"
+ */
+ $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,/", "", $this->dn);
}
$ui= get_userinfo();
function remove_from_parent()
{
- $this->SQL_remove_me(true);
+ $str = $this->SQL_remove_me(true);
+ if($str){
+ print_red($str);
+ }
$ldap= $this->config->get_ldap_link();
$ldap->cd ($this->dn);
}
+ function check_database_accessibility()
+ {
+
+ /* Check if mysql extension is available */
+ if(!is_callable("mysql_pconnect")){
+ return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
+ }
+
+ /********************
+ * Check currently selected home server
+ ********************/
+
+ $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
+ $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
+ if(!$r_current){
+ gosa_log(@mysql_error($r_current));
+ return(sprintf(_("The MySQL home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
+ $cfg_Current['SERVER'],$cfg_Current['LOGIN']));
+ }
+ $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
+ if(!$db_current){
+ gosa_log(@mysql_error($r_current));
+ mysql_close($r_current);
+ return( sprintf(_("Can't select database '%s' on home server '%s'."),$cfg_Current['DB'],$cfg_Current['SERVER']));
+ }
+
+ /********************
+ * Check init home server
+ ********************/
+
+ if($this->goFonHomeServers != $this->init_HomeServer){
+ $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
+ $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
+ if(!$r_init){
+ gosa_log(@mysql_error($r_init));
+ return(sprintf(_("The MySQL initial home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
+ $cfg_Init['SERVER'],$cfg_Init['LOGIN']));
+ }
+ $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
+ if(!$db_init){
+ gosa_log(@mysql_error($r_init));
+ mysql_close($r_init);
+ return( sprintf(_("Can't select database '%s' on initial home server '%s'."),$cfg_Init['DB'],$cfg_Init['SERVER']));
+ }
+ }
+ }
+
/* Check values */
function check()
{
$message[] =_("Only numbers are allowed in Lifetime.");
}
-
$str = $this->SQL_add_me(false);
if(!empty($str)){
$message[] = $str;
}
- if(!empty($this->generate_error)){
- $message[]=$this->generate_error;
- $this->generate_error="";
- }
-
return $message;
}
/********************
* Get configuration and try to connect
********************/
- $a_New = $this->goFonHomeServers[$this->goFonHomeServer] ;
- if(!is_callable("mysql_pconnect")){
- return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
- }
- $r_new = @mysql_pconnect($a_New['SERVER'],$a_New['LOGIN'],$a_New['PASSWORD']);
- if(!$r_new){
- gosa_log(@mysql_error($r_new));
- return(sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
- $a_New['SERVER'],$a_New['LOGIN']));
+
+ /* Check if databases are reachable, returns an error string if anything fails */
+ $error_str = $this->check_database_accessibility();
+ if($error_str){
+ return($error_str);
}
- $db_new = @mysql_select_db($a_New['DB'],$r_new);
- if(!$db_new){
- gosa_log(@mysql_error($r_new));
- return(sprintf(_("Can't select database %s on %s."),$a_New['DB'],$a_New['SERVER']));
+
+ /* Remove old entries, returns an error string if anything fails */
+ $error_str = $this->SQL_remove_me($save);
+ if($error_str){
+ return($error_str);
}
+
+ /* Connect to current database to be able to add new entries */
+ $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
+ $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
+ $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
+
/********************
- * Remove entries from old home server
+ * Remove entries that could cause trouble
********************/
- $a_Remove = $this->goFonHomeServers[$this->init_HomeServer] ;
- if(!is_callable("mysql_pconnect")){
- return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
- }
- $r_remove = @mysql_pconnect($a_Remove['SERVER'],$a_Remove['LOGIN'],$a_Remove['PASSWORD']);
- if(!$r_remove){
- gosa_log(@mysql_error());
- return(sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
- $a_Remove['SERVER'],$a_Remove['LOGIN']));
- }
- $db_remove = @mysql_select_db($a_Remove['DB'],$r_remove);
- if(!$db_remove){
- gosa_log(@mysql_error($r_remove));
- return( sprintf(_("Can't select database %s on %s."),$a_Remove['DB'],$a_Remove['SERVER']));
- }
- $query = "DELETE FROM ".$a_Remove['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
- if(!@mysql_query($query,$r_remove)){
- return(_("Could not remove old entries"));
+ /* If the current home server is different to the initial home server,
+ * there may be already some entries with the given telephoneNumber and/or cn.
+ * We must remove those entries to avoid duplicate use of the same extension name.
+ */
+ if($this->goFonHomeServer != $this->init_HomeServer){
+ $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR '".$this->cn."';";
+ $res = @mysql_query($query,$res_cur);
+ if(!$res){
+ gosa_log(@mysql_error($res_cur));
+ return(_("Can not check if there are already some entries with given telephone number and/or cn in the destination home server.").
+ " "._("Please have a look a the gosa logfiles."));
+ }
+ if($save && mysql_affected_rows($res_cur)) {
+ $SQL = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
+ WHERE (exten='".$this->telephoneNumber."')
+ OR (exten='".$this->cn."')";
+
+ /* Query and ensure that everything went fine */
+ $res = @mysql_query($SQL,$res_cur);
+ if(!$res){
+ gosa_log(@mysql_error($res_cur));
+ return(_("Can not remove entries with some telephone number and/or cn from destination home server.").
+ " "._("Please have a look a the gosa logfiles."));
+ }
+ }
}
-
/********************
* Add new conference entry
********************/
}
$s_keys =preg_replace("/\,$/","",$s_keys);
$s_values =preg_replace("/\,$/","",$s_values);
- $SQL[]="INSERT INTO ".$a_New['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
+ $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
}
foreach($SQL as $sqlsyn){
- mysql_query($sqlsyn);
+ mysql_query($sqlsyn,$res_cur);
}
}
- @mysql_close($r_con);
+ @mysql_close($res_cur);
}
- function SQL_remove_me($save){
- if(!is_callable("mysql_pconnect")){
- if(!$this->error_shown){
- print_red(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
- $this->error_shown = true;
- }
- return(true);
- }
-
- if($this->old_tele_number){
- // Get Configuration for Mysql database Server
- $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'][0];
-
- // Connect to DB server
- $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
-
- // Check if we are connected correctly
- if(!$r_con){
- $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
- $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
- gosa_log(mysql_error());
- return false;
- }
-
- // Select database for Extensions
- $db = @mysql_select_db($a_SETUP['DB'],$r_con);
-
- // Test if we have the database selected correctly
- if(!$db){
- $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
- gosa_log(mysql_error());
- return false;
- }
-
- $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']."
+ /* Remove initial entry from database
+ * This function checks if there is an entry in the
+ * initial home server that uses this->old_cn or $this->old_tele_number
+ * and removes this entries.
+ * This function is called from save and remove_from parent.
+ *
+ * The parameter '$save' is false if we just
+ * want to check if a remove is possible.
+ * And true if we realy want to remove the entries.
+ */
+ function SQL_remove_me($save)
+ {
+ /* check database access */
+ $str = $this->check_database_accessibility();
+ if($str){
+ return($str);
+ }
+
+ /* Connect to old database */
+ $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
+ $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
+ $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
+
+ /* Check if there is an old entry */
+ $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR '".$this->old_cn."';";
+ $res = @mysql_query($query,$r_init);
+ if(!$res){
+ gosa_log(@mysql_error($r_init));
+ return(_("Can not check if entry exists in old database. Please have a look a the gosa logfiles."));
+ }
+
+ /* There are entries using this cn and/or phone number */
+ if($save && mysql_affected_rows($r_init)) {
+ $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
WHERE (exten='".$this->old_tele_number."')
- OR (exten='".$this->telephoneNumber."')
- OR (exten='".$this->cn."')
OR (exten='".$this->old_cn."')";
-
- if($save){
- @mysql_query($SQL);
- }
+
+ /* Query and ensure that everything went fine */
+ $res = @mysql_query($SQL,$r_init);
+ if(!$res){
+ gosa_log(@mysql_error($r_init));
+ return(_("Can not remove old entries from initial home server. Please have a look a the gosa logfiles."));
+ }
}//ENDE old num availiable ...
- @mysql_close($r_con);
- return(true);
+ @mysql_close($r_init);
+ return(false);
}
}
-
-
-
/* Save to LDAP */
function save()
{
$this->old_tele_number= $this->telephoneNumber;
}
- $this->SQL_remove_me(true);
$this->SQL_add_me(true);
if(empty($this->goFonConferenceOption_P)){
diff --git a/plugins/gofon/conference/class_phoneConferenceManagment.inc b/plugins/gofon/conference/class_phoneConferenceManagment.inc
index 5bf53a119714f539f099a556426b76511e51a3ec..94e7b68b04598535e2f76b8a8134e73090c6a5a0 100644 (file)
del_lock ($this->dn);
}
- $this->conftab->save ();
del_lock ($this->conftab->dn);;
unset ($this->conftab);
$this->conftab= NULL;