deploy.provision.inc

  1. 7.x-3.x platform/deploy.provision.inc
  2. 7.x-3.x db/deploy.provision.inc
  3. 7.x-3.x http/deploy.provision.inc

Functions

Namesort descending Description
drush_provision_drupal_post_provision_deploy Implementation of drush_hook_post_COMMAND().
drush_provision_drupal_pre_provision_deploy Make a backup before making any changes, and add extract the file we are restoring from
drush_provision_drupal_pre_provision_deploy_rollback Remove the extracted site directory
drush_provision_drupal_provision_deploy Implementation of drush_hook_COMMAND().
drush_provision_drupal_provision_deploy_validate Make sure we have a valid site being deployd, and that the file being deployd from exists

File

platform/deploy.provision.inc
View source
  1. <?php
  2. /**
  3. * Deploy command implementation
  4. *
  5. * This command when called will
  6. * 1. Extract the backup that is being deployed to the target folder in the sites directory.
  7. * 2. Import the drushrc.php details.
  8. * 3. Do some diagnostics to make sure all the needed packages are available.
  9. * 4. Create a new database, belonging to the site's user, and import the database dump.
  10. * 5. Regenerate configuration files to show new db settings.
  11. * 6. Call the drush 'updatedb' command to update the database if neccesary.
  12. * 7. Update the file paths to the new sites directory.
  13. * 8. Rebuild the site's package manifest.
  14. * 9. Save the new drushrc.php with the newly generated settings.
  15. */
  16. /**
  17. * Make sure we have a valid site being deployd, and that the file being deployd from exists
  18. *
  19. * Implementation of drush_hook_COMMAND_validate().
  20. */
  21. function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
  22. $exists = provision_file()->exists($backup_file)
  23. ->succeed('Deploying site from @path')
  24. ->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
  25. ->status();
  26. if ($exists) {
  27. drush_set_option('backup_file', $backup_file);
  28. }
  29. $exists = provision_file()->exists(d()->site_path)
  30. ->succeed('Replacing the existing site at @path')
  31. ->status();
  32. if ($exists) {
  33. drush_set_option('extract_path', d()->site_path . '.restore');
  34. drush_set_option('old_db_name', drush_get_option('db_name', ''));
  35. }
  36. else {
  37. drush_set_option('extract_path', d()->site_path);
  38. }
  39. drush_set_option('deploy_replace_site', $exists);
  40. }
  41. /**
  42. * Make a backup before making any changes, and add extract the file we are restoring from
  43. *
  44. * Implementation of drush_hook_pre_COMMAND().
  45. */
  46. function drush_provision_drupal_pre_provision_deploy($backup_file) {
  47. // the url is likely to have changed in the deployment
  48. $extracted = provision_file()->extract($backup_file, drush_get_option('extract_path'))
  49. ->succeed('Successfully extracted the contents of @path')
  50. ->fail('Failed to extract the contents of @path to @target', 'PROVISION_BACKUP_EXTRACTION_FAILED')
  51. ->status();
  52. if ($extracted) {
  53. // Make sure the files in the files directory are accessible by the web server.
  54. provision_file()->chgrp(drush_get_option('extract_path') . '/files', d('@server_master')->web_group, TRUE)
  55. ->succeed('Changed group ownership of files in <code>@path</code> to @gid')
  56. ->fail('Could not change group ownership of files in <code>@path</code> to @gid');
  57. provision_file()->chgrp(drush_get_option('extract_path') . '/private/files', d('@server_master')->web_group, TRUE)
  58. ->succeed('Changed group ownership of private files in <code>@path</code> to @gid')
  59. ->fail('Could not change group ownership of private files in <code>@path</code> to @gid');
  60. provision_file()->chgrp(drush_get_option('extract_path') . '/private/temp', d('@server_master')->web_group, TRUE)
  61. ->succeed('Changed group ownership of temp files in <code>@path</code> to @gid')
  62. ->fail('Could not change group ownership of temp files in <code>@path</code> to @gid');
  63. if (drush_get_option('deploy_replace_site', FALSE)) {
  64. $old = d()->site_path . '.restore';
  65. $new = d()->site_path;
  66. $swapped = provision_file()->switch_paths($old, $new)
  67. ->succeed('Swapping out the @path1 and @path2 directories was successful.')
  68. ->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR')
  69. ->status();
  70. if ($swapped) {
  71. drush_set_option('site_dirs_swapped', TRUE);
  72. }
  73. else {
  74. return false;
  75. }
  76. }
  77. // We have already created a new database. Save the info to the config files.
  78. provision_prepare_environment();
  79. provision_save_site_data();
  80. // Load the newly created information, including re-loading the new db creds.
  81. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
  82. _provision_drupal_create_settings_file();
  83. provision_drupal_push_site($override_slave_authority = TRUE);
  84. $site_packages = drush_get_option('packages', array(), 'site');
  85. $drupal_packages = drush_get_option('packages', array(), 'drupal');
  86. $merged_modules = isset($drupal_packages['base']['modules']) ? $drupal_packages['base']['modules'] : array();
  87. if (isset($site_packages['profiles'])) {
  88. $profiles = array_keys($site_packages['profiles']);
  89. $profile = $profiles[0];
  90. if (isset($drupal_packages['profiles'][$profile]['modules'])) {
  91. $merged_modules = array_merge($merged_modules, $drupal_packages['profiles'][$profile]['modules']);
  92. }
  93. }
  94. if (isset($site_packages['modules']) && is_array($site_packages['modules'])) {
  95. foreach ($site_packages['modules'] as $name => $module) {
  96. if ($module['status'] == 1) {
  97. if (isset($module['platform']) && $module['platform'] != '-1') {
  98. drush_log(dt("The !name module is installed in the site's modules directory. Skipping schema version check.", array('!name' => $name)));
  99. }
  100. elseif (!array_key_exists($name, $merged_modules)) {
  101. drush_log(dt("Could not find a version of the !name module", array('!name' => $name)), 'warning');
  102. }
  103. else {
  104. if (($merged_modules[$name]['schema_version'] > 0) && ($module['schema_version'] > $merged_modules[$name]['schema_version'])) {
  105. drush_set_error('PROVISION_SCHEMA_UPGRADE_FAILURE',
  106. dt("The version of the !name module found on this platform (!versionB) has a lower Schema version than the one the site has installed (!versionA)",
  107. array('!name' => $name, '!versionA' => $module['schema_version'], '!versionB' => $merged_modules[$name]['schema_version'])));
  108. }
  109. else {
  110. drush_log(dt("Found a valid version of the !name module with schema version !schema_version",
  111. array('!name' => $name, '!schema_version' => $merged_modules[$name]['schema_version'])));
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. /**
  120. * Remove the extracted site directory
  121. *
  122. * Implementation of drush_hook_pre_COMMAND_rollback().
  123. */
  124. function drush_provision_drupal_pre_provision_deploy_rollback() {
  125. if (drush_get_option('deploy_replace_site', FALSE)) {
  126. if (drush_get_option('site_dirs_swapped', FALSE)) {
  127. // swap the site directories back if necessary.
  128. $old = d()->site_path . '.restore';
  129. $new = d()->site_path;
  130. provision_file()->switch_paths($old, $new)
  131. ->succeed('Swapping out the @path1 and @path2 directories was successful.')
  132. ->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');
  133. _provision_drupal_create_settings_file();
  134. provision_save_site_data();
  135. }
  136. }
  137. if (provision_file()->exists(drush_get_option('extract_path'))->status()) {
  138. _provision_recursive_delete(drush_get_option('extract_path'));
  139. }
  140. }
  141. /**
  142. * Implementation of drush_hook_COMMAND().
  143. */
  144. function drush_provision_drupal_provision_deploy() {
  145. _provision_drupal_maintain_aliases();
  146. _provision_drupal_create_directories();
  147. }
  148. /**
  149. * Implementation of drush_hook_post_COMMAND().
  150. */
  151. function drush_provision_drupal_post_provision_deploy() {
  152. // call the drush updatedb command.
  153. provision_backend_invoke(d()->name, 'updatedb');
  154. // We should be able to fully load Drupal now.
  155. if (drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
  156. drush_include_engine('drupal', 'deploy');
  157. drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
  158. _provision_drupal_rebuild_caches();
  159. // rebuild the node access tables only if necessary
  160. if (!function_exists("node_access_needs_rebuild") || node_access_needs_rebuild()) {
  161. node_access_rebuild();
  162. drush_log(dt('Rebuilt node access table'));
  163. }
  164. } else {
  165. drush_log("could not bootstrap drupal after updatedb");
  166. }
  167. // remove the restore directory
  168. if (!drush_get_error() && drush_get_option('deploy_replace_site', FALSE)) {
  169. _provision_recursive_delete(drush_get_option('extract_path'));
  170. }
  171. // Remove the old database.
  172. if (!drush_get_error() && drush_get_option('deploy_replace_site', FALSE)) {
  173. if ($old_database = drush_get_option('old_db_name', '')) {
  174. if (!d()->service('db')->drop_database($old_database)) {
  175. drush_log(dt('Failed to drop database @old_database', array('@old_database' => $old_database)), 'warning');
  176. }
  177. else {
  178. drush_log(dt('Dropped the old database (@old_database).', array('@old_database' => $old_database)), 'info');
  179. }
  180. }
  181. }
  182. }