Under typical (non DA) multisite circumstances, I understand setting up a multisite and migrating content out from a dev environment into staging and eventually production (if the project requires it). However, a project I am working on will likely use the domain access module and I was a little in the dark about the migration workflow.

1) Have a development/staging site with the domain access module installed (and all the necessary subdomains set up)
2) Client works on setting up the staging site will all content that will go live.

Now we introduce the production servers (staging would consist of stage.domain.com, subsite1.stage.domain.com...subsiteN.stage.domain.com while production would be domain.com, subsite1.domain.com...subsiteN.domain.com)

So the content was created on the stage site (and pointed towards its appropriate subsites) and the time has come to make the site go live (thus out of the staging domain and into the production domain).

What are general practices to then move that structure (and possible content) over from the stage domain over to production? Would you set up domain aliases or is there something else that must be done during the db migration process?

Comments

agentrickard’s picture

We usually set up domain aliases. If possible, we use the production site as the domain records even on dev, and then alias the dev hosts.

Then we use a little trick in hook_domainload() to alter the domain 'path' element IFF you are on a dev box.

BTMash’s picture

Thank you very much for your response on this, agentrickard. I have something mostly up and running at this point though I ran into an issue - when I implemented hook_domainload and altered $domain['path'], it did not seem to do anything to the links. However, if I change $domain['subdomain'], the links on the subdomains with different sources do change appropriately (though I'm guessing that may be a somewhat harsher option to implement?).

agentrickard’s picture

That would work, since path is derived from subdomain. But if your module fires before Domain Access does, DA would overwrite the path after you set it.

BTMash’s picture

Status: Active » Fixed

Ah, that makes perfect sense :) Thank you very much!

I wrote out what you described and it looks to work perfectly. I'm posting the code here if it might be useful to others (the name of the module could use work but I tried to make it flexible enough for others to get potential use out of it):

domain_access_alias_redirect.info:

; $Id $
name = "Domain Alias Redirect"
description = "Provide domain redirection to an alias - useful for development/stage switches"
core = 6.x
package = Domain Access
dependencies[] = domain
dependencies[] = domain_alias

domain_access_alias_redirect.install:

<?php

/**
 * Implementation of hook_install().
 */
function domain_access_alias_redirect_install() {
  $domain_weight = max(0, db_result(db_query("SELECT weight FROM {system} WHERE name='domain'")));
  db_query("UPDATE {system} SET weight = %d WHERE name='domain_access_alias_redirect'", $domain_weight + 1);
}

/**
 * Implementation of hook_uninstall().
 */
function domain_access_alias_redirect_uninstall() {
  db_query("DELETE FROM {variable} WHERE name LIKE 'domain-access-alias-redirect-path%%'");
}

domain_access_alias_redirect.module:

<?php

/**
 * @file
 * Domain Access Alias Redirect primary module file
 * This module will let the user decide if a particular url is what will be used
 * instead of the main site domain.
 * This makes it useful for site migrations when you may want content to have a
 * staging domain url until move to a production site whereby you can then
 * change it to use the primary domain record, change to another alias, or uninstall
 * the module for core domain access functionality.
 */


/**
 * Implementation of hook_menu()
 */
function domain_access_alias_redirect_menu() {
  $items = array();
  
  $items['admin/build/domain/alias/redirect/path'] = array(
    'title' => 'Edit domain path',
    'description' => 'Alter the path of the domain - useful for content migration towards another domain.',
    'type' => MENU_LOCAL_TASK,
    'access arguments' => array('administer domains'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('domain_access_alias_redirect_path_form'),
    'file' => 'domain_access_alias_redirect.admin.inc',
  );
  
  return $items;
}

/**
 * Implementation of hook_domainload().
 */
function domain_access_alias_redirect_domainload(&$domain) {
  $new_domain_path = variable_get('domain-access-alias-redirect-path-'. $domain['domain_id'], $subdomain);
  // Save the original subdomain in case there are any issues
  $domain['original_subdomain'] = $subdomain;
  $domain['original_path'] = $domain['path'];
  if ($new_domain_path !== $domain['subdomain']) {
    if ($domain['path']) {
      $domain['path'] = str_replace($domain['subdomain'], $new_domain_path, $domain['path']);
    }
  }
}

domain_access_alias_redirect.admin.inc:

<?php

/**
 * Form to select the path generated for a particular site.
 */
function domain_access_alias_redirect_path_form($form_state) {
  $form = array();
  // Get list of domains.
  $domains = domain_domains();
  
  foreach ($domains as $domain_key => $domain) {
    $subdomain = ($domain['original_subdomain']) ? $domain['original_subdomain'] : $domain['subdomain'];
    $domain_paths = array($subdomain => $subdomain);
    foreach($domain['aliases'] as $domain_alias) {
      $domain_paths[$domain_alias['pattern']] = $domain_alias['pattern'];
    }
    $form['domain-access-alias-redirect-path-'. $domain['domain_id']] = array(
      '#type' => 'select',
      '#title' => t('Alias redirect for @subdomain', array('@subdomain' => $subdomain)),
      '#options' => $domain_paths,
      '#default_value' => variable_get('domain-access-alias-redirect-path-'. $domain['domain_id'], $subdomain),
    );
  }
  
  return system_settings_form($form);
}
agentrickard’s picture

How is this different from the provided Domain Alias module?

BTMash’s picture

Unless I missed something in the domain alias module, this one allows you to switch to using one of the aliases (changes the path for a domain) you create for the site (so if I have a site domain.com with the alias dev.domain.com and stage.domain.com, you can configure the module to use the dev.domain.com aliss the links on the other subdomains will come up as dev.domain.com). Its just building on top of what domain alias provides.

agentrickard’s picture

Cool. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.