/** * Export a data structure from an entity. * * @param array $params * Parameters (entity_type, uuid). * * @return array */ function exportData(array $params) { $api_params = array('id' => $params['entity_id']); $uuid_params = $params; if (!($uuid = civicrm_api3('uuid', 'get', $uuid_params))) { throw new API_Exception(ts('Unable to obtain UUID for %1', array('1' => print_r($params, 1))), 2900); } if (!($api = civicrm_api3($params['entity_type'], 'getsingle', $api_params))) { throw new API_Exception(ts('Unable to obtain %1 with ID %2', array(1 => $params['entity_type'], 2 => $params['entity_id']))); } $uuid = $uuid['values']['uuid']; // Prepend UUID, remove numeric ID. $export = array_merge(array('uuid' => $uuid), $api); unset($export['id']); // If there are entities this entity depends on, add them to the UUID. if ($dependencies = ConfigManager::getDependencyTypes($params['entity_type'])) { foreach ($dependencies as $dep_column) { // payment_processor will be unaffected by this, which is OK it turns out ... for now. $dep_type = preg_replace('/_id$/', '', $dep_column); if (!empty($api[$dep_column])) { // Explode it then iterate. if ($entity_ids = explode(\CRM_Core_DAO::VALUE_SEPARATOR, $api[$dep_column])) { foreach ($entity_ids as $entity_id) { $dep_params = array('entity_type' => $dep_type, 'entity_id' => $api[$dep_column]); if ($dep = ConfigManager::exportData($dep_params)) { $export['configmgr_dependencies'][$dep_type][] = $dep; } } } } } } return $export; }