Hi everybody,

I have the following problem :

When I enable the domain module, its automatically create a new default domain ( sitename / localhost).

I have already a Drupal feature which contains my domains, and i don't want the localhost default domain.

How can I disable this default domain creation during installation ?

PS : It's ok with drush drush en domain --uri="myuri.com" but i have to do this with an installation profile.

Comments

agentrickard’s picture

This is considered a "convenience" feature for most users. We need a smart way to shut it off.

In an install profile, can you set a variable before module install? If so, we can read that variable in domain_enable().

If your installer can add data to the {domain} table before enabling domain, then the auto-create should not happen.

Marvine’s picture

Hi,

Thank you for your answer.

Finally, it's ok with this following code in my installation profile :

   module_enable( array(
        'domain',
        'domain_blocks',
        )
     );
   
  $domains['domain_1'] = array(
        'subdomain' => 'd1.mydomain.com',
        'sitename' => 'D1',
        'scheme' => 'http',
        'valid' => '1',
        'weight' => '1',
        'is_default' => '1',
        'machine_name' => 'd1_mydomain_com',
       );     

  $domains['domain_2'] = array(
        'subdomain' => 'd2.mydomain.com',
        'sitename' => 'D2',
        'scheme' => 'http',
        'valid' => '1',
        'weight' => '2',
        'is_default' => '0',
        'machine_name' => 'd2_mydomain_com',
       );
   
  domain_save($domains['domain_1']);
  domain_save($domains['domain_2']);
agentrickard’s picture

I just realized how dumb my last statement was. You can't add data to {domain} before it exists.

How are you able to preselect the domains as part of an install profile? Wouldn't those domains vary per install, or are you doing a project-specific profile?

mac_weber’s picture

I have the same question about exporting the install profile to a different server which uses a different base domain.

By now I think I will hack it using sed to replace strings in the install profile.

scottalan’s picture

I just ran into this issue after I set everything up and added it to my install profile. Any updates on this? If not I was wondering if we could just create a variable (in Domain Access) that could be set in the install profile. Then if have Domain Access check for the variable and if the variable exists, because it was set in the install profile, then the logic that creates the default Drupal - localhost entry could just be bypassed. This is just a thought as I haven't looked through the code yet to see how that is being created yet...but I am about to.

scottalan’s picture

ok, I think I found where this happens. Is it in domain_default()? I think the profile gets installed last so maybe this wouldn't work after all. Still thinking...

scottalan’s picture

I did find a way to add a variable during the profile install process before modules are enabled if it helps anyone else.

In MYPROFILE.profile you just need to add:

/**
 * Implements hook_install_tasks().
 *
 */
function MYPROFILE_install_tasks(&$install_state) {
  if ($install_state['completed_task'] == 'install_system_module') {
    // Set a variable for domain access.
    variable_set('domain_install_rule', FALSE);
    variable_set('domain_default', FALSE);
    variable_set('site_name', 'MY SITE');
  }
}

These of course are just example variables but it does work.

In an install profile, can you set a variable before module install? If so, we can read that variable in domain_enable().

So this is possible:

function domain_install() {
  if (variable_get('domain_install_primary', TRUE)) {
    domain_set_primary_domain();
  }
}
scottalan’s picture

I've tested this with my install profile and it works great. Only thing is...you have to install through the UI apparently for hook_install_tasks() to get called. I ran the install using drush site-install and they were never set. I'm trying to find out if there is a way to set these when using drush as it's my preferred method when installing the site. If anyone has a tip, please share.

EDIT:
Ok, I played around with the profile a bit and got this to work for drush. Here is what I did:

In the PROFILE.profile file.

function PROFILE_install_tasks(&$install_state) {

  if ($install_state['database_tables_exist']
    && $install_state['active_task'] == 'install_system_module') {
    PROFILE_define_variables();
  }
}

function PROFILE_define_variables() {
  // Set variables for domain access.
  variable_set('domain_install_primary', FALSE);
  variable_set('site_name', 'My Site');
  variable_set('domain_install_rule', FALSE);
  variable_set('domain_site_grant', FALSE);
  variable_set('domain_assign_users', FALSE);
}

I'll upload a patch I had to make to get this to work.

scottalan’s picture

Issue summary: View changes
StatusFileSize
new8.14 KB

This patch also includes these as well. Not trying to make it confusing but wanted all this functionality in a single patch.
https://drupal.org/node/2159423
https://drupal.org/node/2159443

bluegeek9’s picture

Status: Active » Closed (outdated)

Drupal 7 in End of Life and no longer supported. We encourage you to upgrade to a supported version of Drupal. For more information, see https://www.drupal.org/upgrade.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.