From: hickert Date: Wed, 26 May 2010 06:01:23 +0000 (+0000) Subject: Updated goFonAccount X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d7c9f2b9581392074b36d4a4e3259f7ed69d9903;p=gosa.git Updated goFonAccount -Removing a goFon extension without any asterisk servers lead to 'no MySql extension installed' message, but it was installed. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18697 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/gofon/gofon/phoneaccount/class_phoneAccount.inc b/gosa-plugins/gofon/gofon/phoneaccount/class_phoneAccount.inc index 971f04990..d55d023e4 100644 --- a/gosa-plugins/gofon/gofon/phoneaccount/class_phoneAccount.inc +++ b/gosa-plugins/gofon/gofon/phoneaccount/class_phoneAccount.inc @@ -1613,115 +1613,123 @@ class phoneAccount extends plugin { if(!$this->initially_was_account) return; - if(count($this->goFonHomeServers) && !empty($this->init_HomeServer) && is_callable("mysql_pconnect")){ + // Check for MySQL extension + if(!is_callable("mysql_pconnect")){ + msg_dialog::display(_("Configuration error"), msgPool::missingext("php-mysql"), WARNING_DIALOG); + return(FALSE); + } - // Get Configuration for initial Mysql database Server - $a_SETUP = $this->goFonHomeServers[$this->init_HomeServer]; - $s_parameter =""; + // Check if we've at least one Home-Server + if(!count($this->goFonHomeServers)){ + msg_dialog::display(_("Configuration error"), msgPool::noserver(_("GOfon")), WARNING_DIALOG); + return false; + } - /* Check table definitions - */ - if(!phoneAccount::checkRealtimeTables($a_SETUP)){ - msg_dialog::display(_("Warning"), - sprintf(_("GOsa identified problems with your MySQL table definition!")), - WARNING_DIALOG); - } + if(empty($this->init_HomeServer)) return; - // 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){ - msg_dialog::display(_("Error"), msgPool::dbconnect("GOfon",@mysql_error()), ERROR_DIALOG); - new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); - return false; - } + // -------- REMOVE from MySQL - // Select database for Extensions - $db = @mysql_select_db($a_SETUP['DB'],$r_con); + // Get Configuration for initial Mysql database Server + $a_SETUP = $this->goFonHomeServers[$this->init_HomeServer]; + $s_parameter =""; - // Test if we have the database selected correctly - if(!$db){ - msg_dialog::display(_("Error"), msgPool::dbselect("GOfon", @mysql_error()), ERROR_DIALOG); - new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); - return false; - } + /* Check table definitions + */ + if(!phoneAccount::checkRealtimeTables($a_SETUP)){ + msg_dialog::display(_("Warning"), + sprintf(_("GOsa identified problems with your MySQL table definition!")), + WARNING_DIALOG); + } - $SQL=""; - $SQL[]= "SET @@sql_mode = STRICT_ALL_TABLES;"; + // Connect to DB server + $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']); - $first_num = false; - // Delete old entries - foreach($this->a_old_telenums as $s_telenums){ - if(!$first_num){ - $first_num = $s_telenums; - } - $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$s_telenums."';\n"; - } + // Check if we are connected correctly + if(!$r_con){ + msg_dialog::display(_("Error"), msgPool::dbconnect("GOfon",@mysql_error()), ERROR_DIALOG); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + return false; + } + // Select database for Extensions + $db = @mysql_select_db($a_SETUP['DB'],$r_con); - $query = "SELECT id,name,callerid FROM ".$a_SETUP['SIP_TABLE']." WHERE name='".$this->uid."';"; - $rid = mysql_query($query,$r_con); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); - $result = mysql_fetch_assoc($rid); - $callerid = $first_num; - if($result){ - $callerid = $result['callerid']; + // Test if we have the database selected correctly + if(!$db){ + msg_dialog::display(_("Error"), msgPool::dbselect("GOfon", @mysql_error()), ERROR_DIALOG); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + return false; + } + + $SQL=""; + $SQL[]= "SET @@sql_mode = STRICT_ALL_TABLES;"; + + $first_num = false; + // Delete old entries + foreach($this->a_old_telenums as $s_telenums){ + if(!$first_num){ + $first_num = $s_telenums; } + $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$s_telenums."';\n"; + } - /* Set mode to strict - Strict disallows the addition of entries that do not match the targets field length. - */ - $SQL[] = "DELETE FROM ".$a_SETUP['VOICE_TABLE']." WHERE customer_id='".$callerid."';"; - $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->uid."';\n"; - $SQL[] = "DELETE FROM ".$a_SETUP['SIP_TABLE']." WHERE name='".$this->uid."';\n"; - /* Start transaction, to be able to rollback - */ - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Removing entry from server---",""); + $query = "SELECT id,name,callerid FROM ".$a_SETUP['SIP_TABLE']." WHERE name='".$this->uid."';"; + $rid = mysql_query($query,$r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + $result = mysql_fetch_assoc($rid); + $callerid = $first_num; + if($result){ + $callerid = $result['callerid']; + } - mysql_query("begin;",$r_con); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"begin;","Starting transaction!"); + /* Set mode to strict + Strict disallows the addition of entries that do not match the targets field length. + */ + $SQL[] = "DELETE FROM ".$a_SETUP['VOICE_TABLE']." WHERE customer_id='".$callerid."';"; + $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->uid."';\n"; + $SQL[] = "DELETE FROM ".$a_SETUP['SIP_TABLE']." WHERE name='".$this->uid."';\n"; - foreach($SQL as $query){ - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", ""); + /* Start transaction, to be able to rollback + */ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Removing entry from server---",""); - if(!mysql_query($query,$r_con)){ - $err = mysql_error($r_con); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "FAILED"); - msg_dialog::display(_("Error"), - msgPool::mysqlerror($err,__CLASS__)." ". - "\n

"._("Please activate debugging for details!")."

", - ERROR_DIALOG); + mysql_query("begin;",$r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"begin;","Starting transaction!"); - mysql_query("rollback;",$r_con); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"rollback;", "ERROR Rollback transaction!"); - @mysql_close($r_con); - return(false); - } - } + foreach($SQL as $query){ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", ""); - /* Let changes get active, everything was fine; - */ - mysql_query("commit;",$r_con); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"commit;", ""); - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Transaction sucessful!---", ""); + if(!mysql_query($query,$r_con)){ + $err = mysql_error($r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "FAILED"); + msg_dialog::display(_("Error"), + msgPool::mysqlerror($err,__CLASS__)." ". + "\n

"._("Please activate debugging for details!")."

", + ERROR_DIALOG); - }else{ - msg_dialog::display(_("Configuration error"), msgPool::missingext("php-mysql"), WARNING_DIALOG); - return false; + mysql_query("rollback;",$r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"rollback;", "ERROR Rollback transaction!"); + @mysql_close($r_con); + return(false); + } } + /* Let changes get active, everything was fine; + */ + mysql_query("commit;",$r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"commit;", ""); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Transaction sucessful!---", ""); + + + // -------- REMOVE from LDAP + /* unset macro attr, it will cause an error */ $tmp = array_flip($this->attributes); unset($tmp['macro']); $this->attributes=array_flip($tmp); - /* Cancel if there's nothing to do here */ - if (!$this->initially_was_account){ - return; - } - plugin::remove_from_parent(); /* Just keep one phone number */