Merge pull request #19095 from nishant-bhorodia/Issue#537-owner-notification-email...
[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 namespace Civi\Api4\Action\Setting;
14
15 use Civi\Api4\Generic\Result;
16
17 /**
18 * Revert one or more CiviCRM settings to their default value.
19 *
20 * @method array getSelect
21 * @method $this setSelect(array $settingNames) Set settings to be reverted
22 */
23 class Revert extends AbstractSettingAction {
24
25 /**
26 * Names of settings to revert
27 *
28 * @var array
29 * @required
30 */
31 protected $select = [];
32
33 /**
34 * @param \Civi\Api4\Generic\Result $result
35 * @param \Civi\Core\SettingsBag $settingsBag
36 * @param array $meta
37 * @param int $domain
38 * @throws \Exception
39 */
40 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
41 foreach ($this->select as $name) {
42 $settingsBag->revert($name);
43 $result[] = [
44 'name' => $name,
45 'value' => $settingsBag->get($name),
46 'domain_id' => $domain,
47 ];
48 }
49 foreach ($result as $name => &$setting) {
50 if (isset($setting['value']) && !empty($meta[$name]['serialize'])) {
51 $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']);
52 }
53 }
54 }
55
56 /**
57 * Add one or more settings to be reverted
58 * @param string ...$settingNames
59 * @return $this
60 */
61 public function addSelect(string ...$settingNames) {
62 $this->select = array_merge($this->select, $settingNames);
63 return $this;
64 }
65
66 }