site_install.drush.inc

  1. 8.0.x commands/core/site_install.drush.inc
  2. 6.x commands/core/site_install.drush.inc
  3. 7.x commands/core/site_install.drush.inc
  4. 3.x commands/core/site_install.drush.inc
  5. 4.x commands/core/site_install.drush.inc
  6. 5.x commands/core/site_install.drush.inc
  7. master commands/core/site_install.drush.inc

Functions

Namesort descending Description
drush_core_pre_site_install Perform setup tasks for installation.
drush_core_site_install Command callback.
drush_core_site_install_validate Command validate.

File

commands/core/site_install.drush.inc
View source
  1. <?php
  2. /**
  3. * Command validate.
  4. */
  5. function drush_core_site_install_validate() {
  6. if ($sites_subdir = drush_get_option('sites-subdir')) {
  7. $lower = strtolower($sites_subdir);
  8. if ($sites_subdir != $lower) {
  9. drush_log(dt('Only lowercase sites-subdir are valid. Switching to !lower.', array('!lower' => $lower)), 'warning');
  10. drush_set_option('sites-subdir', $lower);
  11. }
  12. }
  13. }
  14. /**
  15. * Perform setup tasks for installation.
  16. */
  17. function drush_core_pre_site_install() {
  18. if (!$db_spec = _drush_sql_get_db_spec()) {
  19. drush_set_error(dt('Could not determine database connection parameters. Pass --db-url option.'));
  20. return;
  21. }
  22. if ($sites_subdir = drush_get_option('sites-subdir')) {
  23. // Needed so that we later bootstrap into the right site.
  24. drush_set_option('uri', 'http://'.$sites_subdir);
  25. }
  26. else {
  27. $sites_subdir = 'default';
  28. }
  29. $conf_path = "sites/$sites_subdir";
  30. $files = "$conf_path/files";
  31. $settingsfile = "$conf_path/settings.php";
  32. if (!file_exists($files)) {
  33. $msg[] = dt('create a @files directory', array('@files' => $files));
  34. }
  35. if (!file_exists($settingsfile)) {
  36. $msg[] = dt('create a @settingsfile file', array('@settingsfile' => $settingsfile));
  37. }
  38. $msg[] = dt("DROP your '@db' database and then CREATE a new one.", array('@db' => $db_spec['database']));
  39. if (!drush_confirm(dt('You are about to ') . implode(dt(' and '), $msg) . ' Do you want to continue?')) {
  40. return drush_user_abort();
  41. }
  42. // Can't install without sites directory and settings.php.
  43. if (!file_exists($conf_path)) {
  44. if (!drush_op('mkdir', $conf_path) && !drush_get_context('DRUSH_SIMULATE')) {
  45. drush_set_error(dt('Failed to create directory @conf_path', array('@conf_path' => $conf_path)));
  46. return;
  47. }
  48. }
  49. else {
  50. drush_log(dt('Sites directory @subdir already exists - proceeding.', array('@subdir' => $conf_path)));
  51. }
  52. if (!file_exists($settingsfile)) {
  53. if (!drush_op('copy', 'sites/default/default.settings.php', $settingsfile) && !drush_get_context('DRUSH_SIMULATE')) {
  54. drush_set_error(dt('Failed to copy sites/default/default.settings.php to @settingsfile', array('@settingsfile' => $settingsfile)));
  55. return;
  56. }
  57. elseif (drush_drupal_major_version() == 6) {
  58. // On D6, we have to write $db_url ourselves. In D7+, the installer does it.
  59. file_put_contents($settingsfile, "\n" . '$db_url = \'' . drush_get_option('db-url') . "';\n", FILE_APPEND);
  60. // Instead of parsing and performing string replacement on the configuration file,
  61. // the options are appended and override the defaults.
  62. // Database table prefix
  63. if (!empty($db_spec['db_prefix'])) {
  64. if (is_array($db_spec['db_prefix'])) {
  65. // Write db_prefix configuration as an array
  66. $db_prefix_config = '$db_prefix = ' . var_export($db_spec['db_prefix'], TRUE) . ';';
  67. }
  68. else {
  69. // Write db_prefix configuration as a string
  70. $db_prefix_config = '$db_prefix = \'' . $db_spec['db_prefix'] . '\';';
  71. }
  72. file_put_contents($settingsfile, "\n" . $db_prefix_config . "\n", FILE_APPEND);
  73. }
  74. }
  75. }
  76. // Add a files dir if needed
  77. if (!file_exists($files)) {
  78. if (!drush_op('mkdir', $files) && !drush_get_context('DRUSH_SIMULATE')) {
  79. drush_set_error(dt('Failed to create directory @name', array('@name' => $files)));
  80. return;
  81. }
  82. }
  83. // Now we can bootstrap up to the specified site.
  84. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
  85. // Drop and create DB if needed.
  86. $db_name = $db_spec['database'];
  87. $scheme = _drush_sql_get_scheme($db_spec);
  88. $simulate = drush_get_context('DRUSH_SIMULATE');
  89. if ($scheme === 'sqlite') {
  90. // With SQLite, we don't DROP DATABASEs. Each database is in a single file,
  91. // so we just remove the file. We also don't CREATE DATABASEs; it is created
  92. // when SQLite attempts to open a database file which doesn't exist.
  93. if (file_exists($db_spec['database']) && !$simulate) {
  94. if (!unlink($db_spec['database'])) {
  95. drush_set_error(dt('Could not drop database: @name', array('@name' => $db_name)));
  96. }
  97. }
  98. }
  99. else {
  100. drush_sql_empty_db($db_spec);
  101. }
  102. return TRUE;
  103. }
  104. /**
  105. * Command callback.
  106. */
  107. function drush_core_site_install($profile = NULL) {
  108. $args = func_get_args();
  109. $form_options = array();
  110. if ($args) {
  111. // The first argument is the profile.
  112. $profile = array_shift($args);
  113. // Subsequent arguments are additional form values.
  114. foreach ($args as $arg) {
  115. list($key, $value) = explode('=', $arg);
  116. $form_options[$key] = $value;
  117. }
  118. }
  119. drush_include_engine('drupal', 'site_install', drush_drupal_major_version());
  120. drush_core_site_install_version($profile, $form_options);
  121. }