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 SQL query updating custom fields: is this bad form?
Pages: [1]

Author Topic: Custom SQL query updating custom fields: is this bad form?  (Read 320 times)

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Custom SQL query updating custom fields: is this bad form?
May 09, 2014, 02:46:58 am
I am working on an extension to add "Do Not Contact Until" functionality. After retrieving details of the custom field group (using CRM_Core_BAO_CustomGroup) and its fields (using CRM_Core_BAO_CustomField), I am performing a custom query for each field in question. This query affects both the custom field and a corresponding column in civicrm_contact.
Code: [Select]
    UPDATE `$dncuTable` INNER JOIN `civicrm_contact`
        ON `$dncuTable`.`entity_id`           = `civicrm_contact`.`id`
       SET `civicrm_contact`.`$contactColumn` = 0,
           `$dncuTable`.`$dncuColumn`         = NULL
     WHERE `civicrm_contact`.`$contactColumn` = 1
       AND `$dncuTable`.`$dncuColumn`         IS NOT NULL
       AND DATE(`$dncuTable`.`$dncuColumn`)   <= CURDATE();
This appears to work (after putting dropTriggers and triggerRebuild around it, as it appears to fall foul of something similar to CRM-13587). Is it, however, considered harmful to use custom SQL here in an extension that I'd like to eventually release?
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom SQL query updating custom fields: is this bad form?

This forum was archived on 2017-11-26.