Merge pull request #17150 from civicrm/5.25
[civicrm-core.git] / Civi / Api4 / Generic / DAOSaveAction.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace Civi\Api4\Generic;
23
24 /**
25 * Create or update one or more $ENTITIES.
26 *
27 * If creating more than one $ENTITY with similar values, use the `defaults` param.
28 *
29 * Set `reload` if you need the api to return complete records for each saved $ENTITY.
30 */
31 class DAOSaveAction extends AbstractSaveAction {
32 use Traits\DAOActionTrait;
33
34 /**
35 * @inheritDoc
36 */
37 public function _run(Result $result) {
38 foreach ($this->records as &$record) {
39 $record += $this->defaults;
40 if (empty($record['id'])) {
41 $this->fillDefaults($record);
42 }
43 }
44 $this->validateValues();
45
46 $resultArray = $this->writeObjects($this->records);
47
48 $result->exchangeArray($resultArray);
49 }
50
51 }