Merge pull request #16009 from jmcclelland/import-match-phone
[civicrm-core.git] / Civi / Api4 / Action / Setting / Revert.php
CommitLineData
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
21namespace Civi\Api4\Action\Setting;
22
23use Civi\Api4\Generic\Result;
24
25/**
26 * Revert one or more CiviCRM settings to their default value.
27 *
28 * @method array getSelect
121ec912 29 * @method $this setSelect(array $settingNames) Set settings to be reverted
19b53e5b
C
30 */
31class Revert extends AbstractSettingAction {
32
33 /**
34 * Names of settings to revert
35 *
36 * @var array
37 * @required
38 */
39 protected $select = [];
40
41 /**
42 * @param \Civi\Api4\Generic\Result $result
43 * @param \Civi\Core\SettingsBag $settingsBag
44 * @param array $meta
45 * @param int $domain
46 * @throws \Exception
47 */
48 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
49 foreach ($this->select as $name) {
50 $settingsBag->revert($name);
51 $result[] = [
52 'name' => $name,
53 'value' => $settingsBag->get($name),
54 'domain_id' => $domain,
55 ];
56 }
57 foreach ($result as $name => &$setting) {
58 if (isset($setting['value']) && !empty($meta[$name]['serialize'])) {
59 $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']);
60 }
61 }
62 }
63
121ec912
CW
64 /**
65 * Add one or more settings to be reverted
66 * @param string ...$settingNames
67 * @return $this
68 */
69 public function addSelect(string ...$settingNames) {
70 $this->select = array_merge($this->select, $settingNames);
71 return $this;
72 }
73
19b53e5b 74}