4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2019 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2019
37 namespace Civi\Api4\Action\Setting
;
40 use Civi\Api4\Generic\Result
;
43 * Base class for setting actions.
45 * @method int getDomainId
46 * @method $this setDomainId(int $domainId)
48 abstract class AbstractSettingAction
extends \Civi\Api4\Generic\AbstractAction
{
51 * Domain id of setting. Leave NULL for default domain.
53 * @var int|string|array
58 * Contact - if this is a contact-related setting.
64 public function _run(Result
$result) {
67 foreach ($this->domainId
as $domain) {
68 $meta[$domain] = $this->validateSettings($domain);
70 foreach ($this->domainId
as $domain) {
71 $settingsBag = $this->contactId ? \Civi
::contactSettings($this->contactId
, $domain) : \Civi
::settings($domain);
72 $this->processSettings($result, $settingsBag, $meta[$domain], $domain);
77 * Checks that really ought to be taken care of by Civi::settings
81 * @throws \API_Exception
83 protected function validateSettings($domain) {
84 $meta = \Civi\Core\SettingsMetadata
::getMetadata([], $domain);
85 $names = isset($this->values
) ?
array_keys($this->values
) : $this->select
;
86 $invalid = array_diff($names, array_keys($meta));
88 throw new \
API_Exception("Unknown settings for domain $domain: " . implode(', ', $invalid));
90 if (isset($this->values
)) {
91 foreach ($this->values
as $name => &$value) {
92 \CRM_Core_BAO_Setting
::validateSetting($value, $meta[$name]);
98 protected function findDomains() {
99 if ($this->domainId
== 'all') {
100 $this->domainId
= Domain
::get()->setCheckPermissions(FALSE)->addSelect('id')->execute()->column('id');
102 elseif ($this->domainId
) {
103 $this->domainId
= (array) $this->domainId
;
104 $domains = Domain
::get()->setCheckPermissions(FALSE)->addSelect('id')->execute()->column('id');
105 $invalid = array_diff($this->domainId
, $domains);
107 throw new \
API_Exception('Invalid domain id: ' . implode(', ', $invalid));
111 $this->domainId
= [\CRM_Core_Config
::domainID()];