install.provision.inc 4.36 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
/**
 * @file
 *   Provision hooks for the provision install command.
 */

/**
 * Provision install command
 *
10
 * These are the hooks that will be executed by the drush_invoke function
11 12 13 14 15 16
 * when doing a provision_install.
 */

/**
 * Check that we are trying to install a new site , and a new site only
 */
17
function drush_provision_drupal_provision_install_validate() {
18
  if (!d()->uri) {
19 20
    return drush_set_error("PROVISION_URL_REQUIRED", dt("You need to specify a valid url to install a site"));
  }
21
  if (_provision_drupal_site_exists()) {
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

    // If "force-reinstall" option is set, delete the database and files.
    if (drush_get_option('force-reinstall', FALSE)) {

      drush_log(dt('Forcing reinstall...'), 'ok');

      // Load the current database name from drushrc.php.
      // I cannot find another way to find the current db_name!
      require_once(d()->site_path . '/drushrc.php');
      $old_db_name = $options['db_name'];

      if (d()->service('db')->database_exists($old_db_name)) {
        d()->service('db')->drop_database($old_db_name);
        drush_log(dt('Dropped database @database.', array(
          '@database' => $old_db_name,
        )), 'ok');
      }

helmo's avatar
helmo committed
40
      // Destroy site_path.
41 42 43 44 45 46 47 48 49 50
      if (file_exists(d()->site_path)) {
        _provision_recursive_delete( d()->site_path );
        drush_log(dt('Deleted @site_path.', array('@site_path' => d()->site_path)), 'ok');
      }
    }

    // Check again if site does not exist after the forced reinstall.
    if (_provision_drupal_site_exists()) {
      return drush_set_error('PROVISION_SITE_INSTALLED');
    }
51
  }
52 53 54 55 56
}

/**
 * Set up the directories and settings.php file that we need.
 */
57
function drush_provision_drupal_pre_provision_install() {
omega8cc's avatar
omega8cc committed
58
  // This is the actual drupal provisioning requirements.
59
  _provision_drupal_create_directories();
60 61
}

62 63 64 65 66
/**
 * If the install went south, and the site is not PROVISION_SITE_INSTALLED, clean up behind ourselves
 */
function drush_provision_drupal_pre_provision_install_rollback() {
  _provision_recursive_delete( d()->site_path );
67
  drush_invoke_process('@none', 'provision-save', array(d()->name), array('delete' => TRUE));
68 69 70
  foreach (d()->drush_aliases as $alias) {
    drush_invoke_process('@none', 'provision-save', array($alias), array('delete' => TRUE));
  }
71 72 73
}


74 75 76 77 78 79
/**
 * Install Drupal with the pre-configured settings, by calling an external script
 *
 * This is an external script so that php is running in it's own namespace, and
 * weird problems such as the multiple database connections don't confuse drupal.
 */
80
function drush_provision_drupal_provision_install() {
81
 // Requires at least the database settings to complete.
82
  provision_prepare_environment();
83
  _provision_drupal_create_settings_file();
84
  provision_drupal_push_site($override_slave_authority = TRUE);
85

Adrian Rossouw's avatar
Adrian Rossouw committed
86
  provision_save_site_data();
Adrian Rossouw's avatar
Adrian Rossouw committed
87

88 89
  drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);

90 91
  // Install site according to site_install_method.
  drush_log(dt('Installing site with the "!method" method.', array(
92
    '!method' => d()->install_method,
93 94
  )), 'ok');

95
  // Run Drupal installation if option was specified
96
  if (d()->install_method == 'profile') {
97 98 99 100 101 102 103 104 105

    // call a backend task to do the actual installation.
    $result = provision_backend_invoke(d()->name, "provision-install-backend", array(), array('client_email' => drush_get_option('client_email')));
    // pass the login link back to the front end.
    drush_set_option('login_link', $result['context']['login_link']);

    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
    drush_set_option('installed', TRUE, 'site');
  }
106
  else {
107
    drush_set_option('login_link', 'http://' . d()->uri . '/install.php');
108
  }
109

110
  _provision_drupal_maintain_aliases();
111

112 113 114 115 116 117
}

/**
 * Finish the installation, regenerate the caches on the site so that
 * any changes to things such as available modules/ themes can take affect.
 */
118
function drush_provision_drupal_post_provision_install() {
119 120

  // If Drupal profile was installed, rebuild drupal caches and save enabled packages for aegir.
121
  if (d()->install_method == 'profile' && drush_get_option('installed', FALSE, 'site')) {
122 123 124 125 126
    _provision_drupal_rebuild_caches();
    drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
    _provision_client_create_symlink();
    drush_include_engine('drupal', 'cron_key');
  }
127 128 129 130
  // For all other install methods, just create the symlink.
  else {
    _provision_client_create_symlink();
  }
131 132
}