Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2046 Rationalise add vs create on website BAO #18607

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions CRM/Core/BAO/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -36,23 +38,13 @@ public static function add($params) {
* 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);
}

/**
Expand All @@ -65,6 +57,7 @@ public static function create($params, $contactID = NULL, $skipDelete = NULL) {
* @param bool $skipDelete
*
* @return bool
* @throws \CRM_Core_Exception
*/
public static function process($params, $contactID, $skipDelete) {
if (empty($params)) {
Expand All @@ -87,7 +80,7 @@ public static function process($params, $contactID, $skipDelete) {
}
if (!empty($values['url'])) {
$values['contact_id'] = $contactID;
self::add($values);
self::create($values);
}
elseif ($skipDelete && !empty($values['id'])) {
self::del($values['id']);
Expand Down
1 change: 0 additions & 1 deletion Civi/Api4/Generic/Traits/DAOActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ protected function writeObjects($items) {
$oddballs = [
'EntityTag' => 'add',
'GroupContact' => 'add',
'Website' => 'add',
];
$method = $oddballs[$this->getEntityName()] ?? 'create';
if (!method_exists($baoName, $method)) {
Expand Down