/** * Add ga_token setting if missing */ protected function upgradeToAddGaToken() { if (!dmConfig::has('ga_token')) { $setting = new DmSetting(); $setting->set('name', 'ga_token'); $setting->fromArray(array('description' => 'Auth token gor Google Analytics, computed from password', 'group_name' => 'internal', 'credentials' => 'google_analytics')); $setting->save(); } }
/** * Sets a config parameter. * * If a config parameter with the name already exists the value will be overridden. * If config parameter does not exist, one will be created, name & value will be * assigned and value will be returned * * @param string $name A config parameter name * @param mixed $value A config parameter value */ public static function set($name, $value) { /* * Convert booleans to 0, 1 not to fail doctrine validation */ if (is_bool($value)) { $value = (string) (int) $value; } $setting = dmDb::query('DmSetting s')->where('s.name = ?', $name)->withI18n(self::$culture)->fetchOne(); if (!$setting) { $setting = new DmSetting(); $setting->set('name', $name); } $setting->set('value', $value); $setting->save(); self::$config[$name] = $value; self::$dispatcher->notify(new sfEvent(null, 'dm.config.updated', array('setting' => $setting, 'culture' => self::$culture))); // reassign setting value as it may have changed return self::$config[$name] = $setting->get('value'); }
/** * Sets a config parameter. * * If a config parameter with the name already exists the value will be overridden. * If config parameter does not exist, one will be created, name & value will be * assigned and value will be returned * * @param string $name A config parameter name * @param mixed $value A config parameter value */ public static function set($name, $value) { if (!self::$loaded) { self::load(); } /* * Convert booleans to 0, 1 not to fail doctrine validation */ if (is_bool($value)) { $value = (string) (int) $value; } sfConfig::set(sprintf('dm_dmConfig_cache_%s_%s', self::getCulture(), $name), $value); $setting = dmDb::query('DmSetting s')->where('s.name = ?', $name)->withI18n(self::getCulture())->fetchOne(); if (!$setting) { $setting = new DmSetting(); $setting->set('name', $name); } $setting->set('value', $value); $setting->save(); self::dump(); self::$dispatcher->notify(new sfEvent(null, 'dm.config.updated', array('setting' => $setting, 'culture' => self::getCulture()))); return sfConfig::get(sprintf('dm_dmConfig_cache_%s_%s', self::getCulture(), $name)); }
protected function loadSettings() { $array = array('site_name' => array('default_value' => dmString::humanize(dmProject::getKey()), 'description' => 'The site name', 'group_name' => 'site'), 'site_active' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for visitors ?', 'group_name' => 'site'), 'site_indexable' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for search engine crawlers ?', 'group_name' => 'site'), 'site_working_copy' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is this site the current working copy ?', 'group_name' => 'site'), 'ga_key' => array('description' => 'The google analytics key without javascript stuff ( e.g. UA-9876614-1 )', 'group_name' => 'tracking', 'credentials' => 'google_analytics'), 'ga_token' => array('description' => 'Auth token gor Google Analytics, computed from password', 'group_name' => 'internal', 'credentials' => 'google_analytics'), 'gwt_key' => array('description' => 'The google webmaster tools filename without google and .html ( e.g. a913b555ba9b4f13 )', 'group_name' => 'tracking', 'credentials' => 'google_webmaster_tools'), 'xiti_code' => array('type' => 'textarea', 'description' => 'The xiti html code', 'group_name' => 'tracking', 'credentials' => 'xiti'), 'search_stop_words' => array('type' => 'textarea', 'description' => 'Words to exclude from searches (e.g. the, a, to )', 'group_name' => 'search engine', 'credentials' => 'search_engine'), 'base_urls' => array('type' => 'textarea', 'description' => 'Diem base urls for different applications/environments/cultures', 'group_name' => 'internal', 'credentials' => 'system'), 'image_resize_method' => array('type' => 'select', 'default_value' => 'center', 'description' => 'Default method when an image needs to be resized', 'params' => 'fit=Fit scale=Scale inflate=Inflate top=Top right=Right left=Left bottom=Bottom center=Center', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'image_resize_quality' => array('type' => 'number', 'default_value' => 95, 'description' => 'Jpeg default quality when generating thumbnails', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_external_blank' => array('type' => 'boolean', 'default_value' => 0, 'description' => 'Links to other domain get automatically a _blank target', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_current_span' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Links to current page are changed from <a> to <span>', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_use_page_title' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Add an automatic title on link based on the target page title', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'title_prefix' => array('default_value' => '', 'description' => 'Append something at the beginning of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'title_suffix' => array('default_value' => ' | ' . dmString::humanize(dmProject::getKey()), 'description' => 'Append something at the end of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'smart_404' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'When a page is not found, user is redirect to a similar page. The internal search index is used to find the best page for requested url.', 'group_name' => 'seo', 'credentials' => 'url_redirection')); $existingSettings = dmDb::query('DmSetting s INDEXBY s.name')->withI18n()->fetchRecords(); foreach ($array as $name => $config) { if (!isset($existingSettings[$name])) { $setting = new DmSetting(); $setting->set('name', $name); $setting->fromArray($config); $setting->save(); } elseif (!$existingSettings[$name]->hasCurrentTranslation()) { /* * Try to find an existing config from another culture */ $existing = dmDb::query('DmSettingTranslation s')->where('s.id = ?', $existingSettings[$name]->id)->limit(1)->fetchArray(); if ($existing = dmArray::first($existing)) { $config = $existing; unset($config['id'], $config['lang']); } $existingSettings[$name]->fromArray($config)->getCurrentTranslation()->save(); } } dmConfig::load(false); }