I’ve been working to integrate SugarCRM (actually SuiteCRM) into Asterisk this morning and started with superfecta. I came across the following error during debug:
Executing SugarCRM
Connecting to database....
Connection failed: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '10.0.1.24' (110)
{"error":{"type":"Whoops\\Exception\\ErrorException","message":"Undefined
variable:
wquery_result","file":"\/var\/www\/html\/admin\/modules\/superfecta\/sources\/source-SugarCRM.module","line":110}}
From reviewing the code it appears that this module is attempting to do a mysql_num_rows prior to actually running a query. Furthermore, it appears to be calling mysql_num_rows on $wquery_result which is completely undefined in the SugarCRM modules. Here’s the code where I believe the problem resides (line 110:
"if(mysql_num_rows($wquery_result) > 0) {" ):
if ($run_param['Search_Accounts'] == "on") {
$sql = "SELECT name FROM accounts WHERE deleted = '0' AND accounts.phone_office REGEXP '" . $thenumberregex . "' OR accounts.phone_alternate REGEXP '" . $thenumberregex . "' OR accounts.phone_fax REGEXP '" . $thenumberregex . "' LIMIT 1";
if(mysql_num_rows($wquery_result) > 0) {
$wquery_row = mysql_fetch_array($wquery_result);
$wresult_caller_name = $wquery_row["name"];
}
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(!$sth) {
$this->DebugPrint("Failed to Prepare the SQL Statement. Are we connected?...Skipping");
return null;
}
$this->DebugPrint("Connected!");
$this->DebugPrint("Searching Accounts Database...");
$sth->execute(array(':thenumber' => $thenumber));
$find = $sth->fetch(PDO::FETCH_BOTH);
if($find && is_array($find)) {
$this->DebugPrint("Found..");
return $find[0];
}
}
Is anybody using the SugarCRM superfecta module successfully?
Roger that - I’ll work on the SugarCRM code myself. Is Sangoma supporting superfecta in any way? I would rather stay as close to the supported configs as possible so I can focus on other things.
I added this to the bug report but I’ll past it here for anybody else who finds this. The problem is a series of if blocks which should not be there. Removing them made the module functional again. Here’s the patch:
--- source-SugarCRM.module.orig 2016-10-04 22:41:38.416545258 -0400
+++ source-SugarCRM.module 2016-10-04 23:28:53.622597616 -0400
@@ -107,10 +107,6 @@
if ($run_param['Search_Accounts'] == "on") {
$sql = "SELECT name FROM accounts WHERE deleted = '0' AND accounts.phone_office REGEXP '" . $thenumberregex . "' OR accounts.phone_alternate REGEXP '" . $thenumberregex . "' OR accounts.phone_fax REGEXP '" . $thenumberregex . "' LIMIT 1";
- if(mysql_num_rows($wquery_result) > 0) {
- $wquery_row = mysql_fetch_array($wquery_result);
- $wresult_caller_name = $wquery_row["name"];
- }
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(!$sth) {
$this->DebugPrint("Failed to Prepare the SQL Statement. Are we connected?...Skipping");
@@ -130,10 +126,6 @@
// search users
if ($run_param['Search_Users'] == "on") {
$sql = "SELECT first_name,last_name FROM users WHERE deleted = '0' AND users.phone_work REGEXP '" . $thenumberregex . "' OR users.phone_mobile REGEXP '" . $thenumberregex . "' OR users.phone_home REGEXP '" . $thenumberregex . "' OR users.phone_other REGEXP '" . $thenumberregex . "' OR users.phone_fax REGEXP '" . $thenumberregex . "' LIMIT 1";
- if(mysql_num_rows($wquery_result) > 0) {
- $wquery_row = mysql_fetch_array($wquery_result);
- $wresult_caller_name = $wquery_row["name"];
- }
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(!$sth) {
$this->DebugPrint("Failed to Prepare the SQL Statement. Are we connected?...Skipping");
@@ -153,10 +145,6 @@
// search contacts
if ($run_param['Search_Contacts'] == "on") {
$sql = "SELECT first_name,last_name FROM contacts WHERE deleted = '0' AND contacts.phone_work REGEXP '" . $thenumberregex . "' OR contacts.phone_mobile REGEXP '" . $thenumberregex . "' OR contacts.phone_home REGEXP '" . $thenumberregex . "' OR contacts.phone_other REGEXP '" . $thenumberregex . "' OR contacts.phone_fax REGEXP '" . $thenumberregex . "' LIMIT 1";
- if(mysql_num_rows($wquery_result) > 0) {
- $wquery_row = mysql_fetch_array($wquery_result);
- $wresult_caller_name = $wquery_row["name"];
- }
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(!$sth) {
$this->DebugPrint("Failed to Prepare the SQL Statement. Are we connected?...Skipping");
@@ -176,10 +164,6 @@
// search leads
if ($run_param['Search_Leads'] == "on") {
$sql = "SELECT first_name,last_name FROM leads WHERE deleted = '0' AND leads.phone_work REGEXP '" . $thenumberregex . "' OR leads.phone_mobile REGEXP '" . $thenumberregex . "' OR leads.phone_home REGEXP '" . $thenumberregex . "' OR leads.phone_other REGEXP '" . $thenumberregex . "' OR leads.phone_fax REGEXP '" . $thenumberregex . "' LIMIT 1";
- if(mysql_num_rows($wquery_result) > 0) {
- $wquery_row = mysql_fetch_array($wquery_result);
- $wresult_caller_name = $wquery_row["name"];
- }
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(!$sth) {
$this->DebugPrint("Failed to Prepare the SQL Statement. Are we connected?...Skipping");