Merge pull request #23352 from eileenmcnaughton/leg
[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 namespace Civi\Api4\Generic;
14
15 /**
16 * @inheritDoc
17 */
18 class DAOSaveAction extends AbstractSaveAction {
19 use Traits\DAOActionTrait;
20
21 /**
22 * @inheritDoc
23 */
24 public function _run(Result $result) {
25 foreach ($this->records as &$record) {
26 $record += $this->defaults;
27 $this->formatWriteValues($record);
28 $this->matchExisting($record);
29 if (empty($record['id'])) {
30 $this->fillDefaults($record);
31 }
32 }
33 $this->validateValues();
34
35 $resultArray = $this->writeObjects($this->records);
36
37 $result->exchangeArray($resultArray);
38 }
39
40 }