Merge pull request #15821 from seamuslee001/dev_core_183_custom_group
[civicrm-core.git] / Civi / Api4 / Action / Setting / Revert.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 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 }