Commit | Line | Data |
---|---|---|
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 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace Civi\Api4\Generic; |
23 | ||
24 | /** | |
e3c6d5ff | 25 | * Create or update one or more $ENTITIES. |
19b53e5b | 26 | * |
fc95d9a5 | 27 | * If creating more than one $ENTITY with similar values, use the `defaults` param. |
19b53e5b | 28 | * |
fc95d9a5 | 29 | * Set `reload` if you need the api to return complete records for each saved $ENTITY. |
19b53e5b C |
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; | |
961e974c | 40 | $this->formatWriteValues($record); |
19b53e5b C |
41 | if (empty($record['id'])) { |
42 | $this->fillDefaults($record); | |
43 | } | |
44 | } | |
45 | $this->validateValues(); | |
46 | ||
47 | $resultArray = $this->writeObjects($this->records); | |
48 | ||
49 | $result->exchangeArray($resultArray); | |
50 | } | |
51 | ||
52 | } |