Skip to content
Snippets Groups Projects
Commit ffbcf0f4 authored by colemanw's avatar colemanw
Browse files

Api3 - Delete ActivityType API (deprecated since 2014)

parent 7f437228
Branches
Tags
No related merge requests found
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* The ActivityType api is deprecated. Please use the OptionValue api instead.
*
* @deprecated
*
* @package CiviCRM_APIv3
*/
/**
* Notification of deprecated function.
*
* @deprecated api notice
* @return string
* to indicate this entire api entity is deprecated
*/
function _civicrm_api3_activity_type_deprecation() {
return 'The ActivityType api is deprecated. Please use the OptionValue api instead.';
}
/**
* Retrieve activity types.
*
* @param array $params
*
* @return array
* activity types keyed by id
* @deprecated - use the getoptions action instead
*/
function civicrm_api3_activity_type_get($params) {
$activityTypes = CRM_Core_OptionGroup::values('activity_type');
return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
}
/**
* Create activity type.
*
* @param array $params
*
* @return array
* created / updated activity type
*
* @deprecated use the OptionValue api instead
*/
function civicrm_api3_activity_type_create($params) {
$action = 1;
$optionValueID = $params['option_value_id'] ?? NULL;
if ($optionValueID) {
$action = 2;
}
$activityObject = CRM_Core_OptionValue::addOptionValue($params, 'activity_type', $action, $optionValueID);
$activityType = [];
_civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]);
return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create');
}
/**
* Adjust Metadata for Create action.
*
* The metadata is used for setting defaults, documentation & validation.
*
* @param array $params
* Array of parameters determined by getfields.
*/
function _civicrm_api3_activity_type_create_spec(&$params) {
$params['label'] = [
'api.required' => 1,
'title' => 'Label',
'type' => CRM_Utils_Type::T_STRING,
];
$params['weight'] = [
'api.required' => 1,
'title' => 'Weight',
'type' => CRM_Utils_Type::T_STRING,
];
}
/**
* Delete ActivityType.
*
* @param array $params
* Array including id of activity_type to delete.
* @return array API result array
* @throws CRM_Core_Exception
* @deprecated use OptionValue api
*/
function civicrm_api3_activity_type_delete($params) {
$result = CRM_Core_BAO_OptionValue::deleteRecord($params);
if ($result) {
return civicrm_api3_create_success(TRUE, $params);
}
throw new CRM_Core_Exception("Failure to delete activity type id {$params['id']}");
}
......@@ -1269,45 +1269,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
$this->assertEquals('Test activity type', $result['values'][$activity2['id']]['activity_name']);
}
/**
* Test chained Activity format.
*
* @throws \CRM_Core_Exception
*/
public function testChainedActivityGet(): void {
$activity = $this->callAPISuccess('Contact', 'Create', [
'display_name' => 'bob brown',
'contact_type' => 'Individual',
'api.activity_type.create' => [
'weight' => '2',
'label' => 'send out letters',
'filter' => 0,
'is_active' => 1,
'is_optgroup' => 1,
'is_default' => 0,
],
'api.activity.create' => [
'subject' => 'send letter',
'activity_type_id' => '$value.api.activity_type.create.values.0.value',
],
]);
$this->callAPISuccess('Activity', 'Get', [
'id' => $activity['id'],
'return.assignee_contact_id' => 1,
'api.contact.get' => ['api.pledge.get' => 1],
]);
}
/**
* Test civicrm_activity_contact_get() with invalid Contact ID.
*/
public function testActivitiesContactGetWithInvalidContactId(): void {
$params = ['contact_id' => 'contact'];
$this->callAPIFailure('activity', 'get', $params);
}
/**
* Test civicrm_activity_contact_get() with contact having no Activity.
*/
......
<?php
/**
* File for the TestActivityType class
*
* (PHP 5)
*
* @package CiviCRM
*
* This file is part of CiviCRM
*
* CiviCRM is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* CiviCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* Test APIv3 civicrm_activity_* functions
*
* @package CiviCRM_APIv3
* @subpackage API_Activity
* @group headless
*/
class api_v3_ActivityTypeTest extends CiviUnitTestCase {
protected $_apiversion;
public function setUp(): void {
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
}
/**
* Test civicrm_activity_type_get().
*/
public function testActivityTypeGet(): void {
$params = [];
$result = $this->callAPISuccess('activity_type', 'get', $params);
$this->assertEquals($result['values']['1'], 'Meeting');
}
/**
* Test civicrm_activity_type_create().
*/
public function testActivityTypeCreate(): void {
$params = [
'weight' => '2',
'label' => 'send out letters',
'filter' => 0,
'is_active' => 1,
'is_optgroup' => 1,
'is_default' => 0,
];
$result = $this->callAPISuccess('activity_type', 'create', $params);
}
/**
* Test civicrm_activity_type_create - check id
*/
public function testActivityTypecreatecheckId(): void {
$params = [
'label' => 'type_create',
'weight' => '2',
];
$activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
$this->assertArrayHasKey('id', $activitycreate);
$this->assertArrayHasKey('option_group_id', $activitycreate['values'][$activitycreate['id']]);
}
/**
* Test civicrm_activity_type_delete()
*/
public function testActivityTypeDelete(): void {
$params = [
'label' => 'type_create_delete',
'weight' => '2',
];
$activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
$params = [
'activity_type_id' => $activitycreate['id'],
];
$result = $this->callAPISuccess('activity_type', 'delete', $params, __FUNCTION__, __FILE__);
}
}
......@@ -132,7 +132,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
}
public function getDeprecatedAPIs() : array {
return ['Location', 'ActivityType', 'SurveyRespondant'];
return ['Location', 'SurveyRespondant'];
}
public function tearDown(): void {
......@@ -399,7 +399,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'Relationship',
// ones that are not real entities hence not extendable.
'ActivityType',
'Entity',
'Constant',
'Attachment',
......@@ -509,7 +508,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'CustomField',
'CustomGroup',
'Contribution',
'ActivityType',
'MailingEventConfirm',
'Case',
'CaseContact',
......@@ -959,7 +957,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
) {
return;
}
if (in_array($Entity, ['ActivityType', 'SurveyRespondant'])) {
if (in_array($Entity, ['SurveyRespondant'])) {
$this->markTestSkipped();
}
$this->callAPISuccess($Entity, 'getlist', ['label_field' => 'id']);
......@@ -978,7 +976,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
) {
return;
}
if (in_array($entity, ['ActivityType', 'SurveyRespondant'])) {
if (in_array($entity, ['SurveyRespondant'])) {
$this->markTestSkipped();
}
if ($entity === 'UFGroup') {
......@@ -1262,7 +1260,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testInvalidSort_get($Entity) {
$invalidEntitys = ['ActivityType', 'Setting', 'System'];
$invalidEntitys = ['Setting', 'System'];
if (in_array($Entity, $invalidEntitys)) {
$this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently sips invalid params');
}
......@@ -1277,7 +1275,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testValidSortSingleArrayById_get($Entity) {
$invalidEntitys = ['ActivityType', 'Setting', 'System'];
$invalidEntitys = ['Setting', 'System'];
$tests = [
'id' => '_id',
'id desc' => '_id desc',
......@@ -1800,7 +1798,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
*/
protected function getOnlyIDNonZeroCount(): array {
return [
'ActivityType',
'Entity',
'Domain',
'Setting',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment