/** * Add or update a contact. If a dupe is found, check for * ignoreDupe flag to ignore or return error * * @deprecated deprecated since version 2.2.3; use civicrm_contact_create or civicrm_contact_update instead * * @param array $params (reference ) input parameters * * @return array (reference ) contact_id of created or updated contact * @static void * @access public */ function &civicrm_contact_add(&$params) { _civicrm_initialize(); $contactID = CRM_Utils_Array::value('contact_id', $params); if (!empty($contactID)) { $result = civicrm_contact_update($params); } else { $result = civicrm_contact_create($params); } return $result; }
function run($argc, $argv) { global $debug; session_start(); require_once '../civicrm.config.php'; require_once 'api/v2/Domain.php'; require_once 'api/v2/Group.php'; require_once 'api/v2/GroupNesting.php'; require_once 'api/v2/GroupOrganization.php'; require_once 'api/v2/Contact.php'; if ($argc < 3 || $argc > 4) { #var_dump($argv); print_usage($argv[0]); exit(-1); } $org_name = $argv[1]; $org_desc = $argv[2]; $config = CRM_Core_Config::singleton(); //load bootstrap to call hooks require_once 'CRM/Utils/System.php'; CRM_Utils_System::loadBootStrap(); # create the domain $existing_domain = civicrm_domain_get(); $domain_params = array('name' => $org_name, 'description' => $org_desc, 'version' => $existing_domain['version']); $domain = civicrm_domain_create($domain_params); if ($debug) { print "Create domain result: " . var_export($domain) . "\n"; } $domain_id = $domain['id']; # find the parent group, if necessary if (!is_null($argv[3])) { $parent_group_name = $argv[3]; $parent_group_params = array('title' => $parent_group_name); $parent_groups = civicrm_group_get($parent_group_params); if ($debug) { print "Find parent group result: " . var_export($parent_groups) . "\n"; } $parent_group_keys = array_keys($parent_groups); $parent_group_id = $parent_group_keys[0]; } # create the group $group_params = array('title' => $org_name, 'description' => $org_desc, 'is_active' => 1); $group = civicrm_group_add($group_params); if ($debug) { print "Create group result: " . var_export($group) . "\n"; } $group_id = $group['result']; # create the org nesting if necessary if (!is_null($parent_group_id)) { $group_nesting_params = array('parent_group_id' => $parent_group_id, 'child_group_id' => $group_id); $group_nesting = civicrm_group_nesting_create($group_nesting_params); if ($debug) { print "Create group nesting result: " . var_export($group_nesting) . "\n"; } } # create the org contact $org_params = array('organization_name' => $org_name, 'contact_type' => 'Organization'); $org = civicrm_contact_create($org_params); if ($debug) { print "Create org contact result: " . var_export($org) . "\n"; } $org_id = $org['contact_id']; # associate the two $group_org_params = array('group_id' => $group_id, 'organization_id' => $org_id); $group_org_id = civicrm_group_organization_create($group_org_params); if ($debug) { print "Create group-org association result: " . var_export($group_org_id) . "\n"; } print "\n"; print "Add or modify the following lines in the appropriate "; print "civicrm.settings.php file for {$org_name}:\n"; print "\tdefine( 'CIVICRM_DOMAIN_ID', {$domain_id} );\n"; print "\tdefine( 'CIVICRM_DOMAIN_GROUP_ID', {$group_id} );\n"; print "\tdefine( 'CIVICRM_DOMAIN_ORG_ID', {$org_id} );\n"; print "\n"; }
/** * Test civicrm_contact_search_count() */ public function testContactSearchEmail() { $params = array('email' => '*****@*****.**', 'contact_type' => 'Individual', 'location_type_id' => 1); $contact =& civicrm_contact_create($params); $this->assertEquals(0, $contact['is_error'], "In line " . __LINE__ . " error message: " . $contact['error_message']); $this->assertEquals(1, $contact['contact_id'], "In line " . __LINE__); $params = array('email' => 'man2'); $result = civicrm_contact_search($params); $this->assertEquals(1, $result[1]['contact_id']); $this->assertEquals('*****@*****.**', $result[1]['email']); // delete the contact civicrm_contact_delete($contact); }