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 | * Revert one or more CiviCRM settings to their default value. | |
27 | * | |
28 | * @method array getSelect | |
29 | * @method $this addSelect(string $name) | |
30 | * @method $this setSelect(array $select) | |
31 | */ | |
32 | class Revert extends AbstractSettingAction { | |
33 | ||
34 | /** | |
35 | * Names of settings to revert | |
36 | * | |
37 | * @var array | |
38 | * @required | |
39 | */ | |
40 | protected $select = []; | |
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->select as $name) { | |
51 | $settingsBag->revert($name); | |
52 | $result[] = [ | |
53 | 'name' => $name, | |
54 | 'value' => $settingsBag->get($name), | |
55 | 'domain_id' => $domain, | |
56 | ]; | |
57 | } | |
58 | foreach ($result as $name => &$setting) { | |
59 | if (isset($setting['value']) && !empty($meta[$name]['serialize'])) { | |
60 | $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']); | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | } |