CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom search and smart group and civimail: ain't friends ?
Pages: [1]

Author Topic: Custom search and smart group and civimail: ain't friends ?  (Read 1414 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Custom search and smart group and civimail: ain't friends ?
February 19, 2009, 02:56:31 am
Hi,

I developed a custom search, use the result for smart groups (works fine, even for mail activity").

When I use this group as a recipient for civimail, it crashed:
Code: [Select]
[debug_info] => INSERT IGNORE INTO  I_1 (email_id, contact_id)
                    SELECT DISTINCT     civicrm_email.id as email_id,
                                        contact_a.id as contact_id
                    civicrm_contact AS contact_a LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_a=contact_a.id and (end_date >= now() or end_date is null) and civicrm_relationship.is_active=1 ) LEFT JOIN civicrm_relationship_type ON (relationship_type_id=civicrm_relationship_type.id ) LEFT JOIN civicrm_email email ON (email.contact_id = contact_a.id AND email.is_primary= 1 ) LEFT JOIN civicrm_phone phone ON (phone.contact_id = contact_a.id AND phone.is_primary= 1 ) LEFT JOIN civicrm_address address ON (address.contact_id = contact_a.id AND address.is_primary= 1) LEFT JOIN civicrm_country ON (civicrm_country.id = address.country_id)
                    LEFT JOIN           X_1
                            ON          contact_a.id = X_1.contact_id
                    WHERE           
                                        contact_a.do_not_email = 0
                        AND             contact_a.is_opt_out = 0
                        AND             contact_a.is_deceased = 0
                        AND             (civicrm_email.is_bulkmail = 1 OR civicrm_email.is_primary = 1)
                        AND             civicrm_email.on_hold = 0
                                         AND contact_a.contact_type = 'Individual' AND civicrm_relationship.contact_id_b=3694
                        AND             contact_a.id NOT IN (
                                          SELECT contact_id FROM civicrm_group_contact
                                          WHERE civicrm_group_contact.group_id = 46 AND civicrm_group_contact.status = 'Removed')
                        AND             X_1.contact_id IS null
                    ORDER BY civicrm_email.is_bulkmail [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'civicrm_contact AS contact_a LEFT JOIN civicrm_relationship ON (civicrm_relation' at line 4]


Is there a different method to override for the mailing in the smart group for civimail than the one for the "normal" groups usage or ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Custom search and smart group and civimail: ain't friends ?
February 19, 2009, 03:07:31 am
Hi X - oddly I have had behaviour other way round. Smart Groups that we set up of other Smart Groups. Then they fail when we use in Adv Search due to too many Left Joins probably, but they held together in CiviMail (from memory). Not much help to you but .....
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: Custom search and smart group and civimail: ain't friends ?
February 19, 2009, 05:45:38 am
hi,

Currently for some custom searches, mailing is break for custom search -> smart group.
There are mainly two cases by which query is fail
1. Missing 'From' word  from 'from clause'.
2. Missing 'civicrm_email' table from joins.

This is due to some structural issue related to custom search code.

To fix you need to hack the code for get recipients.
go to CRM/Mailing/BAO/Mailing.php line around 305
ie
Code: [Select]
list( $from, $where ) = CRM_Contact_BAO_SavedSearch::fromWhereEmail( $ss->saved_search_id );after this line you need to crrect from clause.

code might be
Code: [Select]
           
            if ( !stristr( $from, 'from' ) ) {
                $from = 'FROM '. $from;
            }
           
            if ( !stristr( $from, 'civicrm_email' ) ) {
                $from .= ' LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id )';
            }

(IMO) for long term, solution would be fix custom search code.

kiran








You Are Designed To Choose... Defined By Choice.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom search and smart group and civimail: ain't friends ?
February 19, 2009, 06:33:10 am

The two functions from( ) and where( ) are only called via CiviMail and hence you have an issue. We can (and should) clean up that interface and document it a bit more :). Check Sample.php for some working code :)

from the interface.php code file

Code: [Select]
    /**                                                                                                                     
     * The below two functions (from and where) are ONLY used if you want to                                                 
     * expose a custom group as a smart group and be able to send a mailing                                                 
     * to them via CiviMail. civicrm_email should be part of the from clause                                                 
     * The from clause should be a valid sql from clause including the word FROM                                             
     * CiviMail will pick up the contacts where the email is primary and                                                     
     * is not on hold / opt out / do not email                                                                               
     *                                                                                                                       
     */

    /**                                                                                                                     
     * The from clause for the query                                                                                         
     */
    function from      ( );

    /**                                                                                                                     
     * The where clause for the query                                                                                       
     */
    function where     ( $includeContactIDs = false );


lobo
« Last Edit: February 19, 2009, 06:36:30 am by Donald Lobo »
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom search and smart group and civimail: ain't friends ?

This forum was archived on 2017-11-26.