From 22911720df7c970d390534a45a0aa72edb5ce2e2 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 26 Sep 2020 15:24:51 +1200 Subject: [PATCH] dev/core#2046 Rationalise add vs create on website BAO 2 years ago we deprecated 'calling website create in weird ways' - it seems like now we can remove that handling & standardise on recommended create function & deprecate add https://lab.civicrm.org/dev/core/-/issues/2046 --- CRM/Core/BAO/Website.php | 25 ++++++++------------- Civi/Api4/Generic/Traits/DAOActionTrait.php | 1 - 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/CRM/Core/BAO/Website.php b/CRM/Core/BAO/Website.php index 358ddd2f3c..d5f386e8fd 100644 --- a/CRM/Core/BAO/Website.php +++ b/CRM/Core/BAO/Website.php @@ -24,9 +24,11 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * Create or update Website record. * * @param array $params + * * @return CRM_Core_DAO_Website + * @throws \CRM_Core_Exception */ - public static function add($params) { + public static function create($params) { return self::writeRecord($params); } @@ -36,23 +38,13 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_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 + * @throws \CRM_Core_Exception */ - 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); + public static function add($params) { + CRM_Core_Error::deprecatedFunctionWarning('use apiv4'); + return self::create($params); } /** @@ -65,6 +57,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * @param bool $skipDelete * * @return bool + * @throws \CRM_Core_Exception */ public static function process($params, $contactID, $skipDelete) { if (empty($params)) { @@ -87,7 +80,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { } if (!empty($values['url'])) { $values['contact_id'] = $contactID; - self::add($values); + self::create($values); } elseif ($skipDelete && !empty($values['id'])) { self::del($values['id']); diff --git a/Civi/Api4/Generic/Traits/DAOActionTrait.php b/Civi/Api4/Generic/Traits/DAOActionTrait.php index 9404b11ecf..3982e4dba8 100644 --- a/Civi/Api4/Generic/Traits/DAOActionTrait.php +++ b/Civi/Api4/Generic/Traits/DAOActionTrait.php @@ -110,7 +110,6 @@ trait DAOActionTrait { $oddballs = [ 'EntityTag' => 'add', 'GroupContact' => 'add', - 'Website' => 'add', ]; $method = $oddballs[$this->getEntityName()] ?? 'create'; if (!method_exists($baoName, $method)) { -- 2.25.1