Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 3.1.4
-
Fix Version/s: 3.1.6
-
Component/s: Drupal Integration Modules
-
Labels:None
Description
In multisite.module, function _multisite_get_parent_orgs() has the following SQL query:
SELECT g.parents as parents, g.id as groupID
FROM civicrm_group g,
civicrm_mailing_job mj,
civicrm_mailing_group mg
WHERE mj.job_id = %1
AND mg.mailing_id = mj.mailing_id
Problems with this:
(1) civicrm_mailing_job has no field job_id (should be id)
(2) unconstrained join to civicrm_group, resulting in far too many rows returned.
In the code following this, I think there may be further issues:
(3) $dao->groupID is ignored if $dao->parents is present, so the ids of groups with parents are missed.
(4) $parentIDString = implode( ',', $parents ); - this joins the array values, which are all 1, instead of the keys.
In the next SQL query:
SELECT GROUP_CONCAT(DISTINCT(go.organization_id))
FROM civicrm_group_organization go
WHERE go.organization_id IN ( $parentIDString )
(5) The WHERE clause tries to equate organization_ids with the group ids obtained from the code above.
I've attached a patch based on what I think the code's intended to achieve but this needs review. I'm puzzled as to why we've only just been hit by this. Here's a backtrace:
--------------------------------------------------------------------------------------------
SELECT g.parents as parents, g.id as groupID
FROM civicrm_group g,
civicrm_mailing_job mj,
civicrm_mailing_group mg
WHERE mj.job_id = 143
AND mg.mailing_id = mj.mailing_id
[nativecode=1054 ** Unknown column 'mj.job_id' in 'where clause']
$backTrace = .../sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 191
, handle,
.../sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 931
.../sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 966
.../sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 564
.../sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1903
.../sites/all/modules/civicrm/packages/DB/mysql.php, raiseError, 898
.../sites/all/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 327
.../sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1216
.../sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2411
.../sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1597
.../sites/all/modules/civicrm/CRM/Core/DAO.php, query, 145
.../sites/all/modules/civicrm/CRM/Core/DAO.php, query, 867
.../sites/all/modules/civicrm_multi/multisite/multisite.module, executeQuery, 202
.../sites/all/modules/civicrm_multi/multisite/multisite.module, _multisite_get_parent_orgs, 58
.../sites/all/modules/civicrm/CRM/Utils/Hook/Drupal.php, multisite_civicrm_tokenValues, 55
.../sites/all/modules/civicrm/CRM/Utils/Hook.php(373) : eval()'d code, invoke, 1
.../sites/all/modules/civicrm/CRM/Utils/Hook.php, eval, 373
.../sites/all/modules/civicrm/CRM/Mailing/BAO/Mailing.php, tokenValues, 979
.../sites/all/modules/civicrm/CRM/Mailing/BAO/Job.php, compose, 340
.../sites/all/modules/civicrm/CRM/Mailing/BAO/Job.php, deliverGroup, 319
.../sites/all/modules/civicrm/CRM/Mailing/BAO/Job.php, deliver, 144
.../sites/all/modules/civicrm/bin/civimail.cronjob.php, runJobs, 40
.../sites/all/modules/civicrm/bin/civimail.cronjob.php, processQueue, 59
.../sites/all/modules/civicrm/bin/civimail.cronjob.php, run, 62
--------------------------------------------------------------------------------------------
Dave J