PageRenderTime 80ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/_importbuddy/importbuddy/controllers/pages/5.php

https://bitbucket.org/betaimages/chakalos
PHP | 158 lines | 98 code | 30 blank | 30 comment | 26 complexity | a845ae2c1f7680bb697b8e5bafebd672 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. $data = array(
  3. 'step' => '5',
  4. );
  5. pb_backupbuddy::set_greedy_script_limits( true );
  6. /**
  7. * migrate_database()
  8. *
  9. * Connects database and performs migration of DB content. Handles skipping.
  10. *
  11. * @return null
  12. */
  13. function migrate_database() {
  14. pb_backupbuddy::$classes['import']->connect_database();
  15. if ( false === pb_backupbuddy::$options['skip_database_migration'] ) {
  16. return pb_backupbuddy::$classes['import']->migrate_database();
  17. } else {
  18. pb_backupbuddy::status( 'message', 'Skipping database migration based on settings.' );
  19. return true;
  20. }
  21. }
  22. /**
  23. * migrate_wp_config()
  24. *
  25. * Passthrough for suture use; trying to funnel all essential migration steps through the API files.
  26. *
  27. * @return true on success, new wp config file content on failure.
  28. */
  29. function migrate_wp_config() {
  30. if ( isset( pb_backupbuddy::$options['dat_file']['wp-config_in_parent'] ) ) {
  31. if ( pb_backupbuddy::$options['dat_file']['wp-config_in_parent'] === true ) { // wp-config.php used to be in parent. Must copy from temp dir to root.
  32. pb_backupbuddy::status( 'details', 'DAT file indicates wp-config.php was previously in the parent directory. Copying into site root.' );
  33. $config_source = ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/wp-config.php';
  34. $result = copy( $config_source, ABSPATH . 'wp-config.php' );
  35. if ( $result === true ) {
  36. pb_backupbuddy::status( 'message', 'wp-config.php file was restored to the root of the site `' . ABSPATH . 'wp-config.php`. It was previously in the parent directory of the source site. You may move it manually to the parent directory.' );
  37. } else {
  38. pb_backupbuddy::status( 'error', 'Unable to move wp-config.php file from temporary location `' . $config_source . '` to root.' );
  39. }
  40. } else { // wp-config.php was in normal location on source site. Nothing to do.
  41. pb_backupbuddy::status( 'details', 'DAT file indicates wp-config.php was previously in the normal location.' );
  42. }
  43. } else { // Pre 3.0 backup
  44. pb_backupbuddy::status( 'details', 'Backup pre-v3.0 so wp-config.php must be in normal location.' );
  45. }
  46. return pb_backupbuddy::$classes['import']->migrate_wp_config();
  47. }
  48. /* verify_database()
  49. *
  50. * Verify various contents of the database after all migration is complete.
  51. *
  52. * @param
  53. * @return
  54. */
  55. function verify_database() {
  56. pb_backupbuddy::$classes['import']->connect_database();
  57. $db_prefix = pb_backupbuddy::$options['db_prefix'];
  58. // Check site URL.
  59. $result = mysql_query( "SELECT option_value FROM `{$db_prefix}options` WHERE option_name='siteurl' LIMIT 1" );
  60. if ( $result === false ) {
  61. pb_backupbuddy::status( 'error', 'Unable to retrieve siteurl from database. A portion of the database may not have imported (or with the wrong prefix).' );
  62. } else {
  63. while( $row = mysql_fetch_row( $result ) ) {
  64. pb_backupbuddy::status( 'details', 'Final site URL: `' . $row[0] . '`.' );
  65. }
  66. mysql_free_result( $result ); // Free memory.
  67. }
  68. // Check home URL.
  69. $result = mysql_query( "SELECT option_value FROM `{$db_prefix}options` WHERE option_name='home' LIMIT 1" );
  70. if ( $result === false ) {
  71. pb_backupbuddy::status( 'error', 'Unable to retrieve home [url] from database. A portion of the database may not have imported (or with the wrong prefix).' );
  72. } else {
  73. while( $row = mysql_fetch_row( $result ) ) {
  74. pb_backupbuddy::status( 'details', 'Final home URL: `' . $row[0] . '`.' );
  75. }
  76. }
  77. mysql_free_result( $result ); // Free memory.
  78. // Verify media upload path.
  79. $result = mysql_query( "SELECT option_value FROM `{$db_prefix}options` WHERE option_name='upload_path' LIMIT 1" );
  80. if ( $result === false ) {
  81. pb_backupbuddy::status( 'error', 'Unable to retrieve upload_path from database. A portion of the database may not have imported (or with the wrong prefix).' );
  82. $media_upload_path = '{ERR_34834984-UNKNOWN}';
  83. } else {
  84. while( $row = mysql_fetch_row( $result ) ) {
  85. $media_upload_path = $row[0];
  86. }
  87. }
  88. mysql_free_result( $result ); // Free memory.
  89. pb_backupbuddy::status( 'details', 'Media upload path in database options table: `' . $media_upload_path . '`.' );
  90. if ( substr( $media_upload_path, 0, 1 ) == '/' ) { // Absolute path.
  91. if ( !file_exists( $media_upload_path ) ) { // Media path does not exist.
  92. $media_upload_message = 'Your media upload path is assigned a directory which does not appear to exist on this server. Please verify it is correct in your WordPress settings. Current path: `' . $media_upload_path . '`.';
  93. pb_backupbuddy::alert( $media_upload_message );
  94. pb_backupbuddy::status( 'warning', $media_upload_message );
  95. } else { // Media path does exist.
  96. pb_backupbuddy::status( 'details', 'Your media upload path is assigned an absolute path which appears to be correct.' );
  97. }
  98. } else { // Relative path.
  99. pb_backupbuddy::status( 'details', 'Your media upload path is assigned a relative path; validity not tested.' );
  100. }
  101. } // End verify_database().
  102. /* rename_htaccess_temp_back()
  103. *
  104. * Renames .htaccess to .htaccess.bb_temp until last ImportBuddy step to avoid complications.
  105. *
  106. * @return null
  107. */
  108. function rename_htaccess_temp_back() {
  109. if ( !file_exists( ABSPATH . '.htaccess.bb_temp' ) ) {
  110. pb_backupbuddy::status( 'details', 'No `.htaccess.bb_temp` file found. Skipping temporary file rename.' );
  111. }
  112. $result = @rename( ABSPATH . '.htaccess.bb_temp', ABSPATH . '.htaccess' );
  113. if ( $result === true ) { // Rename succeeded.
  114. pb_backupbuddy::status( 'message', 'Renamed `.htaccess.bb_temp` file to `.htaccess` until final ImportBuddy step.' );
  115. } else { // Rename failed.
  116. pb_backupbuddy::status( 'error', 'Unable to rename `.htaccess.bb_temp` file to `.htaccess`. Your file permissions may be too strict. You may wish to manually rename this file and/or check permissions before proceeding.' );
  117. }
  118. } // End rename_htaccess_temp_back().
  119. if ( $mode == 'html' ) {
  120. pb_backupbuddy::load_view( 'html_5', $data );
  121. } else { // API mode.
  122. $result = migrate_database();
  123. if ( $result === true ) {
  124. migrate_wp_config();
  125. verify_database();
  126. }
  127. }
  128. ?>