From ebdf0a2cc3881d3e15119221100f3e89b0a6eea5 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 20 Feb 2018 16:28:21 +1300 Subject: [PATCH] Move towards standardising website.create function. --- CRM/Contact/BAO/Contact.php | 5 +++-- CRM/Contact/Form/Inline/Website.php | 2 +- CRM/Core/BAO/Website.php | 34 ++++++++++++++++++++++++----- api/v3/Website.php | 8 +------ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 8cafef35bc..b9eda6db81 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -349,8 +349,9 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $skipDelete = TRUE; } - //add website - CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete); + if (isset($params['website'])) { + CRM_Core_BAO_Website::process($params['website'], $contact->id, $skipDelete); + } $userID = CRM_Core_Session::singleton()->get('userID'); // add notes diff --git a/CRM/Contact/Form/Inline/Website.php b/CRM/Contact/Form/Inline/Website.php index 7671a5fd3b..d7d02c03c1 100644 --- a/CRM/Contact/Form/Inline/Website.php +++ b/CRM/Contact/Form/Inline/Website.php @@ -122,7 +122,7 @@ class CRM_Contact_Form_Inline_Website extends CRM_Contact_Form_Inline { } } // Process / save websites - CRM_Core_BAO_Website::create($params['website'], $this->_contactId, TRUE); + CRM_Core_BAO_Website::process($params['website'], $this->_contactId, TRUE); $this->log(); $this->response(); diff --git a/CRM/Core/BAO/Website.php b/CRM/Core/BAO/Website.php index 585e843d5f..99dded93ab 100644 --- a/CRM/Core/BAO/Website.php +++ b/CRM/Core/BAO/Website.php @@ -40,12 +40,11 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * Takes an associative array and adds im. * * @param array $params - * (reference ) an assoc array of name/value pairs. + * an assoc array of name/value pairs. * - * @return object - * CRM_Core_BAO_Website object on success, null otherwise + * @return CRM_Core_BAO_Website */ - public static function add(&$params) { + public static function add($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'Website', CRM_Utils_Array::value('id', $params), $params); @@ -57,6 +56,31 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { return $website; } + /** + * Create website. + * + * If called in a legacy manner this, temporarily, fails back to calling the legacy function. + * + * @param array $params + * @param int $contactID + * @param bool $skipDelete + * + * @return bool|CRM_Core_BAO_Website + */ + public static function create($params, $contactID = NULL, $skipDelete = NULL) { + if ($skipDelete !== NULL || ($contactID && !is_array($contactID))) { + \Civi::log()->warning(ts('Calling website:create with vars other than $params is deprecated. Use process'), ['civi.tag' => 'deprecated']); + return self::process($params, $contactID, $skipDelete); + } + foreach ($params as $key => $value) { + if (is_numeric($key)) { + \Civi::log()->warning(ts('Calling website:create for multiple websites $params is deprecated. Use process'), ['civi.tag' => 'deprecated']); + return self::process($params, $contactID, $skipDelete); + } + } + return self::add($params); + } + /** * Process website. * @@ -68,7 +92,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * * @return bool */ - public static function create(&$params, $contactID, $skipDelete) { + public static function process($params, $contactID, $skipDelete) { if (empty($params)) { return FALSE; } diff --git a/api/v3/Website.php b/api/v3/Website.php index 34735609db..310d601fee 100644 --- a/api/v3/Website.php +++ b/api/v3/Website.php @@ -38,15 +38,9 @@ * * @return array * API result array - * @todo convert to using basic create - BAO function non-std */ function civicrm_api3_website_create($params) { - //DO NOT USE THIS FUNCTION AS THE BASIS FOR A NEW API http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards - _civicrm_api3_check_edit_permissions('CRM_Core_BAO_Website', $params); - $websiteBAO = CRM_Core_BAO_Website::add($params); - $values = array(); - _civicrm_api3_object_to_array($websiteBAO, $values[$websiteBAO->id]); - return civicrm_api3_create_success($values, $params, 'Website', 'get'); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Website'); } /** -- 2.25.1