Unverified Commit 6f5ba759 authored by colemanw's avatar colemanw Committed by GitHub

Merge pull request #11721 from eileenmcnaughton/website

Fix relationshipType, paymentProcessorType, Note & jobLog apis to support custom data
parents 2c8fea4e da2dec3a
......@@ -85,7 +85,8 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType
*
* @return CRM_Contact_DAO_RelationshipType
*/
public static function add(&$params, &$ids) {
public static function add(&$params, $ids = []) {
$params['id'] = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('relationshipType', $ids));
//to change name, CRM-3336
if (empty($params['label_a_b']) && !empty($params['name_a_b'])) {
$params['label_a_b'] = $params['name_a_b'];
......@@ -97,7 +98,7 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType
// set label to name if it's not set - but *only* for
// ADD action. CRM-3336 as part from (CRM-3522)
if (empty($ids['relationshipType'])) {
if (!$params['id']) {
if (empty($params['name_a_b']) && !empty($params['label_a_b'])) {
$params['name_a_b'] = $params['label_a_b'];
}
......@@ -119,8 +120,6 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType
$relationshipType->label_b_a = CRM_Utils_Array::value('label_a_b', $params);
}
$relationshipType->id = CRM_Utils_Array::value('relationshipType', $ids);
$result = $relationshipType->save();
CRM_Core_PseudoConstant::relationshipType('label', TRUE);
......
......@@ -133,9 +133,9 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
* (reference) an assoc array of name/value pairs.
* @param array $ids
* (deprecated) associated array with note id - preferably set $params['id'].
*
* @return object|null
* @return null|object $note
* $note CRM_Core_BAO_Note object
* @throws \CRM_Exception
*/
public static function add(&$params, $ids = array()) {
$dataExists = self::dataExists($params);
......@@ -161,7 +161,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
$note->copyValues($params);
if (empty($params['contact_id'])) {
if ($params['entity_table'] == 'civicrm_contact') {
if (CRM_Utils_Array::value('entity_table', $params) == 'civicrm_contact') {
$note->contact_id = $params['entity_id'];
}
}
......@@ -183,9 +183,10 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
$displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id);
$noteActions = FALSE;
$session = CRM_Core_Session::singleton();
if ($session->get('userID')) {
if ($session->get('userID') == $note->entity_id) {
$loggedInContactID = CRM_Core_Session::singleton()->getLoggedInContactID();
if ($loggedInContactID) {
if ($loggedInContactID == $note->entity_id) {
$noteActions = TRUE;
}
elseif (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) {
......@@ -231,7 +232,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
*/
public static function dataExists(&$params) {
// return if no data present
if (!strlen($params['note'])) {
if (empty($params['id']) && !strlen($params['note'])) {
return FALSE;
}
return TRUE;
......
......@@ -36,3 +36,27 @@
function civicrm_api3_job_log_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
* Create one or more job log record.
*
* @param array $params
* input parameters
*
* @return array
*/
function civicrm_api3_job_log_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'JobLog');
}
/**
* Delete one or more job log record.
*
* @param array $params
* input parameters
*
* @return array
*/
function civicrm_api3_job_log_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'JobLog');
}
......@@ -40,17 +40,7 @@
* @return array
*/
function civicrm_api3_payment_processor_type_create($params) {
if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for payment_processor type ID');
}
$paymentProcessorType = CRM_Financial_BAO_PaymentProcessorType::create($params);
$relType = array();
_civicrm_api3_object_to_array($paymentProcessorType, $relType[$paymentProcessorType->id]);
return civicrm_api3_create_success($relType, $params, 'PaymentProcessorType', 'create', $paymentProcessorType);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'PaymentProcessorType');
}
/**
......
......@@ -41,31 +41,16 @@
*/
function civicrm_api3_relationship_type_create($params) {
if (!isset($params['label_a_b'])) {
// @todo should we when id is empty?
if (!isset($params['label_a_b']) && !empty($params['name_a_b'])) {
$params['label_a_b'] = $params['name_a_b'];
}
if (!isset($params['label_b_a'])) {
if (!isset($params['label_b_a']) && !empty($params['name_b_a'])) {
$params['label_b_a'] = $params['name_b_a'];
}
$ids = array();
if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for relationship type ID');
}
else {
$ids['relationshipType'] = CRM_Utils_Array::value('id', $params);
}
$relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
$relType = array();
_civicrm_api3_object_to_array($relationType, $relType[$relationType->id]);
return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'RelationshipType');
}
/**
......
......@@ -96,7 +96,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
$this->toBeImplemented['create'] = array(
'Cxn',
'CxnApp',
'JobLog',
'SurveyRespondant',
'OptionGroup',
'MailingRecipients',
......@@ -114,7 +113,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
$this->toBeImplemented['delete'] = array(
'Cxn',
'CxnApp',
'JobLog',
'MembershipPayment',
'OptionGroup',
'SurveyRespondant',
......@@ -388,18 +386,14 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'MailingEventUnsubscribe',
'MailingJob',
'MembershipPayment',
'Note',
'SavedSearch',
'UFJoin',
'UFField',
'PriceFieldValue',
'JobLog',
'GroupContact',
'EntityTag',
'PledgePayment',
'PaymentProcessorType',
'Relationship',
'RelationshipType',
// ones that are not real entities hence not extendable.
'ActivityType',
......@@ -731,6 +725,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'ignore_severity',
),
),
'JobLog' => array(
// For better or worse triggers override.
'break_return' => ['run_time'],
'cant_update' => ['run_time'],
),
);
if (empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])) {
return array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment