Hello,
SCENARIO
Synchronizing a development site to a production site (and sometimes vice-versa) we copy the database from the one site to the other (say development to production). The language domains are set using the i18n module's domain option (ie. not language prefix).
Lets say the languages are setup as follows using i18n:
PRODUCTION site - multilingual configuration:
Default language: English - en
Default language domain: www.example.com
Additional language: Spanish - es
Additional language domain: es.example.com
DEVELOPMENT site - multilingual configuration:
Default language: English - en
Default language domain: dev.example.com
Additional language: Spanish - es
Additional language domain: es.dev.example.com
PROBLEM
When we move the development database to the live site it still has the multilinguage domains settings for the development site. This means that when we go to the live site www.example.com any link on the page will be pointing to dev.example.com/...
THEORETICAL SOLUTION
It may be possible to set the language domain in the settings file and thereby override the database settings.
I've see the post about $conf['i18n_variables'] = array(... in the settings.php file but I have not found a way to set the i18n domain settings using the settings.php file. I've read many posts and search the issue queues but have not found a solution using the settings.php file. Maybe some one knows.
All the best,
Guy Saban
Comments
Comment #1
EricLondon CreditAttribution: EricLondon commentedI've encountered the same problem. When I deployed my code from production to a development environment, I kept getting redirected to production. I added the following code to fix the issue, but I'm trying to find the best place to put it..
Comment #2
guysaban CreditAttribution: guysaban commentedI have not tried but I am guessing you can do the variable_get and variable_set in the settings file.
With Drush installed you probably could use the Drush instructions for vset and vget.
Comment #3
colanYou can't do variable overrides in settings.php or with Drush. This is because these domain settings are put in the "languages" table; they are not Drupal variables. You could stick the above code in settings.php, but it's a bit of a hack. What really needs to happen is have core support these settings as variables that can be overridden.
Until that happens, I'd recommend adding Drush commands such as these to your deployment processes.
...after you move your DB to whichever site (dev, staging, etc.).
Comment #4
colanThis is all in core now. Adjusting issue settings as appropriate.
Comment #5
colanComment #6
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #7
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe site alias feature (the
sites/sites.php
file) is precisely designed for this type of things. Could someone check if it can be used this way?Comment #8
kemo1 CreditAttribution: kemo1 commentedSubscribing.
Comment #9
mlncn CreditAttribution: mlncn commentedSubscribing (and tagging as potential edge case for a possible SettingsAPI).
Comment #10
hkovacs CreditAttribution: hkovacs commentedAnother solution for Guys scenario:
Tested on:
Drupal 6.2
Drush 4
When running drush sql-sync, I used the --skip-tables-key provided to exclude tables from being tranferred. This leaves the dev languages table variables as their original desired values.
Example Source: example.drushrc.php
Script:
Comment #11
plachsubscribe
Comment #12
colan@howiek03: I'd recommend being careful with that approach. If you upgrade Drupal on @dev, and the schema changes for the "languages" table, this change won't get propogated to @live because the table is skipped. Even if you run updatedb, the schema version pointer in the @live DB will say it's up-to-date, when that table isn't.
I'm actually using this approach to not overwrite Webform tables on @live, but this a contrib module, where each of them maintains its own schema version pointer. You can then update the code, run updatedb and then do the sql-sync. This won't work for core though, as it's already partially updated, so I'd avoid it.
Comment #13
hkovacs CreditAttribution: hkovacs commented@colan, I considered that when deciding which method to use (updates vs skip). I still opted for skip. At some point I might pay the price, but I am aware ahead of time.
Comment #14
bserem CreditAttribution: bserem commentedAfter reading the above I decided to go with Colan (#3) and turn his commands to a bash-function.
The code:
Drush aliases and subdomains should be the same in order for the above to work. For example @stage should be stage.example.com and @staging should be staging.example.com and @live should be the live site (example.com)!
As you can see the urls are hardcoded inside the function. I don't find this a problem because I have a different cpanel account for every site so I can change this function for each of my clients.
I suppose urls could be set as parameters, it might be good but it I believe could become tedius to write the url every time.
I hope somebody will enjoy the above code!
Comment #15
idflood CreditAttribution: idflood commentedsubscribing
Comment #16
colanI just looked into it. It cannot be used this way. It can only be used for mapping site aliases to site directories. See example.sites.php for details.
Comment #17
betz CreditAttribution: betz commentedCan someone tell what the status is for Drupal 8?
Can a language domainname be overridden from settings.php?
Comment #18
plachIt can be overridden through config overrides.
Comment #19
betz CreditAttribution: betz commentedParty!
Currently it's a pain each time manually editing my db with a local import.
Good te hear this is gone.
Comment #21
Pere OrgaIf this works for Drupal 8 but not for 7, could that feature be backported?
Comment #22
Iztok CreditAttribution: Iztok commentedThere is a module for this for D7: https://drupal.org/project/language_domains
Comment #23
Pere OrgaThat module looks very cool
Comment #25
leymannxTo add an example snippet of what you need to put in your
settings.php
orsettings.local.php
: