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) »
  • Apply this hook to all contacts in CiviCRM
Pages: [1]

Author Topic: Apply this hook to all contacts in CiviCRM  (Read 1082 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Apply this hook to all contacts in CiviCRM
July 28, 2009, 12:21:44 am
Hello,

I've written this hook to be run when saving custom data on an organisation (context here: http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=1880885).

I now want to apply it retrospectively to all organisations.  Is there a way I can loop through and edit all organisations and thus invoke this hook for them all? Or another way I can update all my contact records based on this?

Thanks,
Michael

Code: [Select]
function cavsa_custom_data_civicrm_custom( $op, $groupID, $entityID, &$params ) {

// If we are custom data from custom data group 1, i.e. a contact record

if ( $groupID==1 && ( $op=='edit' || $op=='add' )) {

// Define some variables

$tableName='civicrm_value_areas_of_work_and_service_provis_1';
$columnName='summary_30';

// The foreach below creates an array that is based on the column name minus the last number.
// This array is used to populate the summary checkbox data.
//
// NOTE: This code assumes that you have named the values of the summary data after the column
// names in the custom data group, trimed to 31 characters
//
// You could alternatively use an array to translate these values.

foreach($params as $param) { //
if($param['custom_group_id']== 1 and $param['value']!= NULL ) {
$summaryData[]=substr($param['column_name'], 0,31);
// $summaryData values have to be trimmed to max. length of option value
}
}

// Format the value in the CiviCRM way.  Is there a better CiviCRM function for this?
$summaryData=CRM_Core_DAO::VALUE_SEPARATOR.implode(CRM_Core_DAO::VALUE_SEPARATOR, $summaryData).CRM_Core_DAO::VALUE_SEPARATOR;

//Insert the data into the custom data table
$sql = "

UPDATE $tableName
SET $columnName = '$summaryData'
WHERE entity_id = $entityID

";

CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );

}
}
« Last Edit: July 28, 2009, 12:25:10 am by michaelmcandrew »
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

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: Apply this hook to all contacts in CiviCRM
July 28, 2009, 07:40:53 am

I think you'll need to write another script to apply this retroactively to all organizations. You should try to centralize the functions called between the two scripts

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) »
  • Apply this hook to all contacts in CiviCRM

This forum was archived on 2017-11-26.