Merge pull request #17975 from eileenmcnaughton/matt_yet_another
[civicrm-core.git] / Civi / Api4 / Generic / DAOSaveAction.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 */
18
19
19b53e5b
C
20namespace Civi\Api4\Generic;
21
22/**
e3c6d5ff 23 * Create or update one or more $ENTITIES.
19b53e5b 24 *
fc95d9a5 25 * If creating more than one $ENTITY with similar values, use the `defaults` param.
19b53e5b 26 *
fc95d9a5 27 * Set `reload` if you need the api to return complete records for each saved $ENTITY.
19b53e5b
C
28 */
29class DAOSaveAction extends AbstractSaveAction {
30 use Traits\DAOActionTrait;
31
32 /**
33 * @inheritDoc
34 */
35 public function _run(Result $result) {
36 foreach ($this->records as &$record) {
37 $record += $this->defaults;
961e974c 38 $this->formatWriteValues($record);
19b53e5b
C
39 if (empty($record['id'])) {
40 $this->fillDefaults($record);
41 }
42 }
43 $this->validateValues();
44
45 $resultArray = $this->writeObjects($this->records);
46
47 $result->exchangeArray($resultArray);
48 }
49
50}