When a CiviCRM group is set to synchronize with Constant Contact, the group is "successfully created" in Constant Contact. This can be verified by looking at contact lists in Constant Contact. However, the initial import of email addresses does not take place.

Comments

bigjim’s picture

Status: Active » Closed (duplicate)

Duplicate of #1104938

Bweber-1’s picture

Status: Closed (duplicate) » Active

After implementing the fix described in #1104938. CiviCRM group members are not imported. This is not a duplicate of that issue.

Bweber-1’s picture

I am not a CiviCRM developer nor a PHP developer, but I am working through debugging this. Listed below is the backtrace for enabling sync for a group. A fatal error occurs. It looks like this occurs because the syntax for the getFieldValue function called in the civicrm_constant_contact.module, getFieldValue, line 1296 contains a null or 0 value for the $searchValue argument so the getFieldValue function defined in civicrm/CRM/Core/DAO.php line 709 errors out.

While this seems to relate to the data, I am not sure why this occurs. It does seem to imply that the module should be checking for 0 values in the 'id' field of the contact record.

Error when turning on sync for a group:

The group Staff was successfully created in Constant Contact.
Group Settings: Staff
Sorry. A non-recoverable error has occurred.
We experienced an unexpected error. Please post a detailed description and the backtrace on the CiviCRM forums: http://forum.civicrm.org/

Backtrace after enabling sync for group Staff:

backTrace

/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 270
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/DAO.php, fatal, 709
/home/tnsconejo/www/www/sites/all/modules/civicrm_constant_contact/civicrm_constant_contact.module, getFieldValue, 1296
/home/tnsconejo/www/www/sites/all/modules/civicrm_constant_contact/civicrm_constant_contact.module, getContactDetails, 459
/home/tnsconejo/www/www/sites/all/modules/civicrm_constant_contact/civicrm_constant_contact.module, civicrm_constant_contact_civicrm_post_manage_group, 89
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Utils/Hook/Drupal.php, civicrm_constant_contact_civicrm_post, 57
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Utils/Hook.php(87) : eval()'d code, invoke, 1
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Utils/Hook.php, eval, 87
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Contact/BAO/Group.php, post, 425
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Group/Form/Edit.php, create, 411
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Form.php, postProcess, 250
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php, mainProcess, 153
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php, realPerform, 130
/home/tnsconejo/www/www/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 203
/home/tnsconejo/www/www/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 103
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 284
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Page/Basic.php, run, 351
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Page/Basic.php, edit, 171
/home/tnsconejo/www/www/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 219
/home/tnsconejo/www/www/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 355
, civicrm_invoke,
/home/tnsconejo/www/www/includes/menu.inc, call_user_func_array, 348
/home/tnsconejo/www/www/index.php, menu_execute_active_handler, 18

Reference lines from respective code files:

civicrm_constant_contact.module line 1296
$fname = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',$objectId,'first_name');

civicrm/CRM/Core/DAO.php line 709
static function getFieldValue( $daoName, $searchValue, $returnColumn = 'name', $searchColumn = 'id' )
{
if ( empty( $searchValue ) ) {
// adding this year since developers forget to check for an id
// and hence we get the first value in the db
CRM_Core_Error::fatal( );
return null;

akakadak’s picture

Version: 6.x-1.1 » 6.x-1.2

The for loop that referenced the contact id from getMember was pointing to the array value, but needs to point to the array key. I changed the for loop to a while loop to keep the sequence correct. This code worked for me. Before this change we could only sync contacts after previously syncing an empty group to a list. Now we can sync a populate group.

$group_members = CRM_Contact_BAO_Group::getMember( $objectId );
$cc_group_id = get_cc_group_id($objectId);
//var_dump($group_members);
//add or edit each group member in civi
reset($group_members);
while ($contact = current($group_members) ){
$contact_id = key($group_members);
$contactDetails = getContactDetails($contact_id);
$contactEmail = civicrm_constant_contact_get_primary_email($contact_id);
if (!empty($contactEmail)) {
$result = add_or_edit_subscriber($contactEmail, $contactDetails);
if ( $result ) {
civicrm_constant_contact_display($contactEmail .' synced successfully in Constant Contact');
cc_log('Group Contact with e-mail '. $contactEmail . ' synced successfully in Constant Contact for CiviCRM group with ID: '. $objectId . '.');
}
else {//if result
civicrm_constant_contact_display($contactEmail . ' failed to sync with Constant Contact');
cc_log('The group Contact with e-mail '. $contactEmail .' could not be synced in Constant Contact for CiviCRM group with ID: '. $objectId .'.', WATCHDOG_ERROR);
//** TODO:
//add code here to remove the created GroupContact from this group in Civi to keep data synched
//** End TODO
//----------------------------------------------------------------------------------
}//else add failed
}
else {//if empty
cc_log('Could not sync contact: No e-mail address');
}
next($group_members);
$count++;
}//while loop