Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 public function __destruct()
 {
     \Civi\Core\Resolver::singleton()->call($this->callback, $this->args);
 }
Ejemplo n.º 3
0
 public function __unset($k)
 {
     if (!isset($this->map[$k])) {
         throw new \CRM_Core_Exception("Cannot unset unrecognized property CRM_Core_Config::\${$k}");
     }
     unset($this->cache[$k]);
     $type = $this->map[$k][0];
     $name = isset($this->map[$k][1]) ? $this->map[$k][1] : $k;
     switch ($type) {
         case 'setting':
         case 'setting-path':
         case 'setting-url-abs':
         case 'setting-url-rel':
             $this->getSettings()->revert($k);
             return;
         case 'local':
             $this->initLocals();
             $this->locals[$name] = NULL;
             return;
         case 'callback':
             // Array(0 => $type, 1 => $obj, 2 => $getter, 3 => $setter, 4 => $unsetter).
             if (!isset($this->map[$k][1], $this->map[$k][4])) {
                 throw new \CRM_Core_Exception("Cannot find unsetter for property CRM_Core_Config::\${$k}");
             }
             \Civi\Core\Resolver::singleton()->call(array($this->map[$k][1], $this->map[$k][4]), array($k));
             return;
         default:
             throw new \CRM_Core_Exception("Cannot unset property CRM_Core_Config::\${$k} ({$type})");
     }
 }
Ejemplo n.º 4
0
 /**
  * @param string $name
  *   Symbolic name for the lock.
  * @return callable|NULL
  */
 public function getFactory($name)
 {
     foreach ($this->rules as $rule) {
         if (preg_match($rule['pattern'], $name)) {
             return Resolver::singleton()->get($rule['factory']);
         }
     }
     return NULL;
 }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /**
  * (Quasi-Private) Do not call externally. For use by DAOs.
  *
  * Apply any third-party alterations to the `fields()`.
  *
  * @param string $className
  * @param string $event
  * @param mixed $values
  */
 public static function invoke($className, $event, &$values)
 {
     self::init();
     if (isset(self::$entityTypes[$className][$event])) {
         foreach (self::$entityTypes[$className][$event] as $filter) {
             $args = array($className, &$values);
             \Civi\Core\Resolver::singleton()->call($filter, $args);
         }
     }
 }