The DAOActionTrait::writeObjects function was formatting values but not by reference,
so the CiviCase writeObjects function was using unformatted values to open the case,
which would contain the raw string `user_contact_id` instead of the processed value.
/**
* @inheritDoc
*/
- protected function writeObjects($items) {
+ protected function writeObjects(&$items) {
foreach ($items as &$item) {
if ($this->streetParsing && !empty($item['street_address'])) {
$item = array_merge($item, \CRM_Core_BAO_Address::parseStreetAddress($item['street_address']));
* @param array $cases
* @return array
*/
- protected function writeObjects($cases) {
+ protected function writeObjects(&$cases) {
$cases = array_values($cases);
$result = parent::writeObjects($cases);
/**
* @inheritDoc
*/
- protected function writeObjects($items) {
+ protected function writeObjects(&$items) {
foreach ($items as &$item) {
$item['method'] = $this->method;
$item['tracking'] = $this->tracking;
$this->validateValues();
$params = $this->values;
$this->fillDefaults($params);
+ $items = [$params];
- $resultArray = $this->writeObjects([$params]);
-
- $result->exchangeArray($resultArray);
+ $result->exchangeArray($this->writeObjects($items));
}
/**
// Update a single record by ID unless select requires more than id
if ($this->getSelect() === ['id'] && count($this->where) === 1 && $this->where[0][0] === 'id' && $this->where[0][1] === '=' && !empty($this->where[0][2])) {
$this->values['id'] = $this->where[0][2];
- $result->exchangeArray($this->writeObjects([$this->values]));
+ $items = [$this->values];
+ $result->exchangeArray($this->writeObjects($items));
return;
}
/**
* @inheritDoc
*/
- protected function writeObjects($items) {
+ protected function writeObjects(&$items) {
$fields = $this->entityFields();
foreach ($items as $idx => $item) {
FormattingUtil::formatWriteParams($item, $fields);
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
- protected function writeObjects($items) {
+ protected function writeObjects(&$items) {
$baoName = $this->getBaoName();
// Some BAOs are weird and don't support a straightforward "create" method.
$result = [];
- foreach ($items as $item) {
+ foreach ($items as &$item) {
$entityId = $item['id'] ?? NULL;
FormattingUtil::formatWriteParams($item, $this->entityFields());
$this->formatCustomParams($item, $entityId);
$duration->setInputType('Number');
$duration->setDescription('Open Case activity duration (minutes).');
$spec->addFieldSpec($duration);
+
+ $defaultStatus = \CRM_Core_DAO::singleValueQuery('SELECT value FROM civicrm_option_value
+ WHERE is_default
+ AND domain_id = ' . \CRM_Core_BAO_Domain::getDomain()->id . '
+ AND option_group_id = (SELECT id FROM civicrm_option_group WHERE name = "case_status")
+ LIMIT 1');
+ if ($defaultStatus) {
+ $status = $spec->getFieldByName('status_id');
+ $status->setDefaultValue((int) $defaultStatus);
+ }
}
/**
--- /dev/null
+{
+ "CaseType": [
+ {
+ "name": "test_case_type",
+ "title": "Test Case Type",
+ "definition": {
+ "activityTypes": [
+ {
+ "name": "Open Case",
+ "max_instances": "1"
+ },
+ {
+ "name": "Follow up"
+ }
+ ],
+ "activitySets": [
+ {
+ "name": "standard_timeline",
+ "label": "Standard Timeline",
+ "timeline": 1,
+ "activityTypes": [
+ {
+ "name": "Open Case",
+ "status": "Completed"
+ },
+ {
+ "name": "Follow up",
+ "reference_activity": "Open Case",
+ "reference_offset": "3",
+ "reference_select": "newest"
+ }
+ ]
+ }
+ ],
+ "timelineActivityTypes": [
+ {
+ "name": "Open Case",
+ "status": "Completed"
+ },
+ {
+ "name": "Follow up",
+ "reference_activity": "Open Case",
+ "reference_offset": "3",
+ "reference_select": "newest"
+ }
+ ],
+ "caseRoles": [
+ {
+ "name": "Parent of",
+ "creator": "1",
+ "manager": "1"
+ }
+ ]
+ },
+ "@ref": "test_case_type_1"
+ }
+ ]
+}
"@ref": "test_contact_2"
}
],
- "CaseType": [
- {
- "name": "test_case_type",
- "title": "Test Case Type",
- "definition": {
- "activityTypes": [
- {
- "name": "Open Case",
- "max_instances": "1"
- },
- {
- "name": "Follow up"
- }
- ],
- "activitySets": [
- {
- "name": "standard_timeline",
- "label": "Standard Timeline",
- "timeline": 1,
- "activityTypes": [
- {
- "name": "Open Case",
- "status": "Completed"
- },
- {
- "name": "Follow up",
- "reference_activity": "Open Case",
- "reference_offset": "3",
- "reference_select": "newest"
- }
- ]
- }
- ],
- "timelineActivityTypes": [
- {
- "name": "Open Case",
- "status": "Completed"
- },
- {
- "name": "Follow up",
- "reference_activity": "Open Case",
- "reference_offset": "3",
- "reference_select": "newest"
- }
- ],
- "caseRoles": [
- {
- "name": "Parent of",
- "creator": "1",
- "manager": "1"
- }
- ]
- },
- "@ref": "test_case_type_1"
- }
- ],
"Case": [
{
"case_type_id": "@ref test_case_type_1.id",
--- /dev/null
+<?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 |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+
+namespace api\v4\Entity;
+
+use Civi\Api4\CiviCase;
+use api\v4\UnitTestCase;
+
+/**
+ * @group headless
+ */
+class CaseTest extends UnitTestCase {
+
+ public function setUp() {
+ parent::setUp();
+ \CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
+ $this->loadDataSet('CaseType');
+ }
+
+ public function testCreateUsingLoggedInUser() {
+ $this->createLoggedInUser();
+
+ $contactID = $this->createEntity(['type' => 'Individual'])['id'];
+
+ $result = CiviCase::create(FALSE)
+ ->addValue('case_type_id', $this->getReference('test_case_type_1')['id'])
+ ->addValue('creator_id', 'user_contact_id')
+ ->addValue('status_id', 1)
+ ->addValue('contact_id', $contactID)
+ ->execute()
+ ->first();
+
+ }
+
+}
$this->dropByPrefix('civicrm_value_myfavorite');
$this->cleanup(['tablesToTruncate' => $tablesToTruncate]);
$this->setUpOptionCleanup();
+ $this->loadDataSet('CaseType');
$this->loadDataSet('ConformanceTest');
$this->creationParamProvider = \Civi::container()->get('test.param_provider');
parent::setUp();