- To change queries of getRecipients and getTestRecipients functions in CRM/Mailing/BAO/Mailing.php.
solution->removing location table used for email search like
- INNER JOIN $location
- ON $email.location_id = $location.id
INNER JOIN $contact
- ON $location.entity_id = $contact.id
- AND $location.entity_table = '$contact'
+ ON $email.contact_id = $contact.id
- To set a email is_bulkmail true we set all email of the same contact is_bulkmail false in CRM/Core/BAO/Email.php file
solution->(location table is used for searching other email address of that contact remove that location table).
if ( $email->is_bulkmail ) {
$sql = "
UPDATE civicrm_email
LEFT JOIN civicrm_location ON civicrm_email.location_id = civicrm_location.id
LEFT JOIN civicrm_contact ON civicrm_location.entity_id = civicrm_contact.id
AND civicrm_location.entity_table = 'civicrm_contact'
SET is_bulkmail = 0
WHERE
civicrm_contact.id = {$params'contact_id'}";
CRM_Core_DAO::executeQuery( $sql );
}
remove location table used in the query. - Mailing/Event/BAO/Subscribe.php subscribe function finds the contact of email through the mail is received search is based on location.
solution-> same as the above - Mailing/Event/BAO/Forward.php forward function finds the contact based on location.
solution-> same as the above - In Job.php file we create activity history after delivering a mail. The api used for that (crm_create_activity_history) works acording to old activity history table
solution->change that api use the existing table
Labels:

1 Comment
Hide/Show CommentsSep 27, 2007
Pankaj Sharma
1)To change queries of getRecipients and getTestRecipients functions in CRM/Mailing/BAO/Mailing.php.
solution->removing location table used for email search
--- CRM/Mailing/BAO/Mailing.php (revision 11620)
+++ CRM/Mailing/BAO/Mailing.php (working copy)
@@ -133,7 +133,6 @@
$contact = CRM_Contact_DAO_Contact::getTableName();
- $location = CRM_Core_DAO_Location::getTableName();
@@ -239,11 +238,8 @@
SELECT DISTINCT $email.id as email_id,
$contact.id as contact_id
FROM $email
- INNER JOIN $location
- ON $email.location_id = $location.id
INNER JOIN $contact
- ON $location.entity_id = $contact.id
- AND $location.entity_table = '$contact'
+ ON $email.contact_id = $contact.id
INNER JOIN $g2contact
ON $contact.id = $g2contact.contact_id
INNER JOIN $mg
@@ -254,7 +250,6 @@
WHERE
$mg.group_type = 'Include'
AND $g2contact.status = 'Added'
- AND $g2contact.location_id IS null
AND $g2contact.email_id IS null
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
@@ -269,11 +264,8 @@
SELECT DISTINCT $email.id as email_id,
$contact.id as contact_id
FROM $email
- INNER JOIN $location
- ON $email.location_id = $location.id
INNER JOIN $contact
- ON $location.entity_id = $contact.id
- AND $location.entity_table = '$contact'
+ ON $email.contact_id = $contact.id
INNER JOIN $eq
ON $eq.contact_id = $contact.id
INNER JOIN $job
@@ -286,7 +278,6 @@
$mg.group_type = 'Include'
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
- AND $location.is_primary = 1
AND $email.is_primary = 1
AND $email.on_hold = 0
AND $mg.mailing_id = {$mailing_id}
@@ -325,7 +316,6 @@
WHERE
contact_a.do_not_email = 0
AND contact_a.is_opt_out = 0
- AND $location.is_primary = 1
AND $email.is_primary = 1
AND $email.on_hold = 0
$where
@@ -339,14 +329,10 @@
SELECT DISTINCT $email.id as local_email_id,
$contact.id as contact_id
FROM $email
- INNER JOIN $location
- ON $email.location_id = $location.id
INNER JOIN $contact
- ON $location.entity_id = $contact.id
- AND $location.entity_table = '$contact'
+ ON $email.contact_id = $contact.id
INNER JOIN $g2contact
ON $contact.id = $g2contact.contact_id
- AND $location.id = $g2contact.location_id
INNER JOIN $mg
ON $g2contact.group_id = $mg.entity_id
LEFT JOIN X_$job_id
@@ -355,7 +341,6 @@
$mg.entity_table = '$group'
AND $mg.group_type = 'Include'
AND $g2contact.status = 'Added'
- AND $g2contact.location_id IS NOT null
AND $g2contact.email_id is null
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
@@ -382,7 +367,6 @@
$mg.entity_table = '$group'
AND $mg.group_type = 'Include'
AND $g2contact.status = 'Added'
- AND $g2contact.location_id IS NOT null
AND $g2contact.email_id IS NOT null
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
@@ -754,12 +738,8 @@
$query = "
SELECT DISTINCT contact_a.id as contact_id
FROM civicrm_contact contact_a
- LEFT JOIN civicrm_individual ON contact_a.id = civicrm_individual.contact_id
- LEFT JOIN civicrm_location ON civicrm_location.entity_id = contact_a.id
- LEFT JOIN civicrm_address ON civicrm_location.id = civicrm_address.location_id
- LEFT JOIN civicrm_email ON civicrm_location.id = civicrm_email.location_id
- WHERE LOWER(civicrm_email.email) = %1
- AND civicrm_location.entity_table = 'civicrm_contact'";
+ LEFT JOIN civicrm_email ON contact_a.id = civicrm_email.contact_id
+ WHERE LOWER(civicrm_email.email) = %1";
$params = array( 1 => array( $testParams['test_email'], 'String' ) );
$dao =& CRM_Core_DAO::executeQuery( $query, $params );
@@ -774,16 +754,7 @@
$params = array( 1 => array($testParams['test_email'], 'String' ) );
if ( ! $contact_id ) {
- $query = "SELECT civicrm_location.id
- FROM civicrm_location
- WHERE civicrm_location.entity_id = $userID
- AND civicrm_location.is_primary = 1";
- $dao =& CRM_Core_DAO::executeQuery( $query);
- if ($dao->fetch( ) )
- $dao->free( );
- $query = "INSERT INTO civicrm_email (location_id,email) values ($location_id,%1)";
+ $query = "INSERT INTO civicrm_email (contact_id,email) values ($userID,%1)";
CRM_Core_DAO::executeQuery( $query, $params );
$contact_id = $userID;
}
@@ -813,9 +784,7 @@
"SELECT DISTINCT civicrm_email.id AS email_id, civicrm_email.is_primary as is_primary,
civicrm_email.is_bulkmail as is_bulkmail
FROM civicrm_email
-INNER JOIN civicrm_location ON civicrm_email.location_id = civicrm_location.id
-INNER JOIN civicrm_contact ON civicrm_location.entity_id = civicrm_contact.id
-AND civicrm_location.entity_table = 'civicrm_contact'
+INNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id
WHERE civicrm_email.is_bulkmail = 1
AND civicrm_contact.id = {$contact->contact_id}
AND civicrm_contact.do_not_email =0
@@ -834,9 +803,7 @@
"SELECT DISTINCT civicrm_email.id AS email_id, civicrm_email.is_primary as is_primary,
civicrm_email.is_bulkmail as is_bulkmail
FROM civicrm_email
-INNER JOIN civicrm_location ON civicrm_email.location_id = civicrm_location.id
-INNER JOIN civicrm_contact ON civicrm_location.entity_id = civicrm_contact.id
-AND civicrm_location.entity_table = 'civicrm_contact'
+INNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id
WHERE civicrm_email.is_primary = 1
AND civicrm_contact.id = {$contact->contact_id}
AND civicrm_contact.do_not_email =0