CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Setting locale in "civicrm.settings php"
Pages: [1]

Author Topic: Setting locale in "civicrm.settings php"  (Read 2001 times)

freshwebservices

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.3
Setting locale in "civicrm.settings php"
December 12, 2012, 04:49:28 am
Hi,
I'm trying to set Civi installation up so that default country, currency, etc are automagically populated rather than needing to be done via the admin UI.
I'd assumed that it would be possible to add these to the "civicrm.settings php" like so:
define('CIVICRM_COUNTRY_LIMIT','GB');
etc, etc.
However, this can't be done prior to installation, so I was hoping that subsequently editing the "civicrm.settings php" would suffice - however, my edits are not being picked up (probably because the database has already been populated).

Is there a way to do this via this or similar approach?

Thanks,
Eddie


D7, Civi 4.2.6

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Setting locale in "civicrm.settings php"
December 12, 2012, 09:29:14 am
I suppose you could find where in the install code the SQL is for the current defaults, and then change those.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Setting locale in "civicrm.settings php"
December 12, 2012, 09:35:38 am
Hi Eddie,

The constants for CIVICRM_COUNTRY_LIMIT and CIVICRM_PROVINCE_LIMIT were deprecated some time ago, although I see one or two comment in the CiviCRM code still referring to them.

Initially, a long long time ago, CiviCRM had constants for most settings, which were defined in the civicrm.settings.php (CiviCRM 1.x). In CiviCRM 2.x and 3.x, those settings were progressively migrated to options that could be configured from the administrative interface, and stored in the database. However, they were often stored in the "civicrm_domain" table (in a serialized field). Around 3.4/4.0, settings were migrated to the civicrm_option_name / civicrm_option_value table, because some of those fields had huge lists of possible values.

More recently, the need for API calls to manage those settings has become more and more important, especially for those of us who manage turn-key hosting farms (reduce installation costs). A new "settings" mechanism is available in CiviCRM since 4.2 (I think), but not all configurations have been migrated to it. Country/province settings are one of those not migrated yet (I think they are still in the "civicrm_domain" table). This migration is a lot of work, since it standardizes many different old mechanisms, and civi developers are trying to pick up best practices from Drupal 8's configuration management initiative.

Long story short, here is an example of what I use to set the country/province and other localization settings. I'm using it on a CiviCRM 4.1 farm, however, and it has not been upgraded to 4.2 yet.

Code: [Select]
$params = array(
    'enableComponents' => array(),
    'enableComponentIDs' => array(),
    'moneyformat' => '%a %c',
    'monetaryThousandSeparator' => ' ',
    'monetaryDecimalPoint' => '.',
    'dateformatDatetime' => '%Y/%m/%d %k:%M', // 2012-01-31 5:30
    'dateformatFull' => '%Y/%m/%d', // 2012-01-31
    'dateformatPartial' => '%B %Y', // janvier 2012
    'lcMessages' => 'fr_CA',
    'defaultContactCountry' => 1039,
    'defaultCurrency' => 'CAD',
    'enableSSL' => TRUE,
  );

  civicrm_initialize(TRUE);
  require_once "CRM/Core/BAO/Setting.php";
  CRM_Core_BAO_Setting::add($params);

In 4.2, CRM_Core_BAO_Setting::add($params) was changed to CRM_Core_BAO_ConfigSetting::add($params);

For example, you can see in CRM/Admin/Form/Setting/Localization.php, it sets an array of values, and then calls the parent commonProcess() function, in CRM/Admin/Form/Setting.php.

Code: [Select]
  // $params = array(... );

  civicrm_initialize(TRUE);
  require_once "CRM/Core/BAO/ConfigSetting.php";
  CRM_Core_BAO_ConfigSetting::add($params);

Mathieu / bgm on IRC
« Last Edit: December 12, 2012, 09:37:26 am by mlutfy »
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

freshwebservices

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.3
Re: Setting locale in "civicrm.settings php"
December 13, 2012, 12:57:59 am
Hi Mathieu/Hershel,

Thanks for your responses - much appreciated.

It seems that the defaults (US) are loaded during the installation - irrespective of what country you enter during the installation screen (when you enter database details & then can select your country/language). There is a msql file called something like civicrm_data.mysql which has US, etc set as default. So I was going to run a post-installation update statement to reset these values.

However, the use of the API looks the better way to go. I'm already using the Domain API to set domain details but didn't see that locale could be set there. I also noted that System API is still in development. So, I think I'll investigate Mathieu's approach as its closer to the eventual API route.

Thanks again,
Eddie

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Setting locale in "civicrm.settings php"
December 13, 2012, 12:55:28 pm
Under 4.3 the settings that are in the domain table and those stored in civicrm_settings are available through a new settings api - so you would be able to do

$param = array('version' => 3,
    'enableComponents' => array(),
    'enableComponentIDs' => array(),
    'moneyformat' => '%a %c',
    'monetaryThousandSeparator' => ' ',
    'monetaryDecimalPoint' => '.',
    'dateformatDatetime' => '%Y/%m/%d %k:%M', // 2012-01-31 5:30
    'dateformatFull' => '%Y/%m/%d', // 2012-01-31
    'dateformatPartial' => '%B %Y', // janvier 2012
    'lcMessages' => 'fr_CA',
    'defaultContactCountry' => 1039,
    'defaultCurrency' => 'CAD',
    'enableSSL' => TRUE,
   'default_renewal_contribution_page' => 3,

   );

civicrm_api('setting', 'create', $params);

(We have backported this to 4.2 - https://github.com/fuzionnz/civicrm)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Setting locale in "civicrm.settings php"

This forum was archived on 2017-11-26.