Commit | Line | Data |
---|---|---|
19b53e5b | 1 | <?php |
380f3545 TO |
2 | |
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 | ||
19b53e5b C |
21 | namespace Civi\Api4\Action\Setting; |
22 | ||
23 | use Civi\Api4\Generic\Result; | |
24 | ||
25 | /** | |
26 | * Set the value of one or more CiviCRM settings. | |
27 | * | |
28 | * @method array getValues | |
29 | * @method $this setValues(array $value) | |
30 | * @method $this addValue(string $name, mixed $value) | |
31 | */ | |
32 | class Set extends AbstractSettingAction { | |
33 | ||
34 | /** | |
35 | * Setting names/values to set. | |
36 | * | |
37 | * @var mixed | |
38 | * @required | |
39 | */ | |
40 | protected $values = []; | |
41 | ||
42 | /** | |
43 | * @param \Civi\Api4\Generic\Result $result | |
44 | * @param \Civi\Core\SettingsBag $settingsBag | |
45 | * @param array $meta | |
46 | * @param int $domain | |
47 | * @throws \Exception | |
48 | */ | |
49 | protected function processSettings(Result $result, $settingsBag, $meta, $domain) { | |
50 | foreach ($this->values as $name => $value) { | |
51 | if (isset($value) && !empty($meta[$name]['serialize'])) { | |
52 | $value = \CRM_Core_DAO::serializeField($value, $meta[$name]['serialize']); | |
53 | } | |
54 | $settingsBag->set($name, $value); | |
55 | $result[] = [ | |
56 | 'name' => $name, | |
57 | 'value' => $this->values[$name], | |
58 | 'domain_id' => $domain, | |
59 | ]; | |
60 | } | |
61 | } | |
62 | ||
63 | } |