/** * Update the DB record for this setting. * * @param string $name * The simple name of the setting. * @param mixed $value * The new value of the setting. */ protected function setDb($name, $value) { if (\CRM_Core_BAO_Setting::isUpgradeFromPreFourOneAlpha1()) { // civicrm_setting table is not going to be present. return; } $fields = array(); $fieldsToSet = \CRM_Core_BAO_Setting::validateSettingsInput(array($name => $value), $fields); //We haven't traditionally validated inputs to setItem, so this breaks things. //foreach ($fieldsToSet as $settingField => &$settingValue) { // self::validateSetting($settingValue, $fields['values'][$settingField]); //} $metadata = $fields['values'][$name]; $dao = new \CRM_Core_DAO_Setting(); $dao->name = $name; $dao->domain_id = $this->domainId; if ($this->contactId) { $dao->contact_id = $this->contactId; $dao->is_domain = 0; } else { $dao->is_domain = 1; } $dao->find(TRUE); if (isset($metadata['on_change'])) { foreach ($metadata['on_change'] as $callback) { call_user_func(\Civi\Core\Resolver::singleton()->get($callback), unserialize($dao->value), $value, $metadata, $this->domainId); } } if (\CRM_Utils_System::isNull($value)) { $dao->value = 'null'; } else { $dao->value = serialize($value); } $dao->created_date = \CRM_Utils_Time::getTime('Ymdhis'); $session = \CRM_Core_Session::singleton(); if (\CRM_Contact_BAO_Contact_Utils::isContactId($session->get('userID'))) { $dao->created_id = $session->get('userID'); } $dao->save(); $dao->free(); }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['setting'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Update the DB record for this setting. * * @param string $name * The simple name of the setting. * @param mixed $value * The new value of the setting. */ protected function setDb($name, $value) { if (\CRM_Core_BAO_Setting::isUpgradeFromPreFourOneAlpha1()) { // civicrm_setting table is not going to be present. return; } $fields = array(); $fieldsToSet = \CRM_Core_BAO_Setting::validateSettingsInput(array($name => $value), $fields); //We haven't traditionally validated inputs to setItem, so this breaks things. //foreach ($fieldsToSet as $settingField => &$settingValue) { // self::validateSetting($settingValue, $fields['values'][$settingField]); //} $metadata = $fields['values'][$name]; $dao = new \CRM_Core_DAO_Setting(); $dao->name = $name; $dao->domain_id = $this->domainId; if ($this->contactId) { $dao->contact_id = $this->contactId; $dao->is_domain = 0; } else { $dao->is_domain = 1; } $dao->find(TRUE); if (isset($metadata['on_change'])) { foreach ($metadata['on_change'] as $callback) { call_user_func(\Civi\Core\Resolver::singleton()->get($callback), unserialize($dao->value), $value, $metadata, $this->domainId); } } if (!is_array($value) && \CRM_Utils_System::isNull($value)) { $dao->value = 'null'; } else { $dao->value = serialize($value); } if (!isset(\Civi::$statics[__CLASS__]['upgradeMode'])) { \Civi::$statics[__CLASS__]['upgradeMode'] = \CRM_Core_Config::isUpgradeMode(); } if (\Civi::$statics[__CLASS__]['upgradeMode'] && \CRM_Core_DAO::checkFieldExists('civicrm_setting', 'group_name')) { $dao->group_name = 'placeholder'; } $dao->created_date = \CRM_Utils_Time::getTime('YmdHis'); $session = \CRM_Core_Session::singleton(); if (\CRM_Contact_BAO_Contact_Utils::isContactId($session->get('userID'))) { $dao->created_id = $session->get('userID'); } if ($dao->id) { $dao->save(); } else { // Cannot use $dao->save(); in upgrade mode (eg WP + Civi 4.4=>4.7), the DAO will refuse // to save the field `group_name`, which is required in older schema. \CRM_Core_DAO::executeQuery(\CRM_Utils_SQL_Insert::dao($dao)->toSQL()); } $dao->free(); }
/** * @param $rev */ public function upgrade_4_1_alpha2($rev) { $dao = new CRM_Core_DAO_Setting(); $dao->group_name = 'Directory Preferences'; $dao->name = 'customTemplateDir'; if (!$dao->find(TRUE)) { $dao->domain_id = CRM_Core_Config::domainID(); $dao->created_date = date('YmdHis'); $dao->is_domain = 0; $dao->save(); } $dao->free(); // Do the regular upgrade $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); }