Ejemplo n.º 1
0
    if (mysql_error() != '') {
        pb_backupbuddy::status('error', 'mysql error: ' . mysql_error());
    }
    pb_backupbuddy::status('details', 'Finished migration steps for `Multisite Export -> Standalone` sites.');
}
// ********** END MULTISITE EXPORT -> STANDALONE **********
// Loop through the tables matching this prefix. Does NOT change data in other tables.
// This changes actual data on a column by column basis for very row in every table.
$tables = array();
$rows = $wpdb->get_results("SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" . str_replace('_', '\\_', $destination_db_prefix) . "%' AND table_schema = DATABASE()", ARRAY_A);
foreach ($rows as $row) {
    $tables[] = $row['table_name'];
}
pb_backupbuddy::status('message', 'Found ' . count($rows) . ' WordPress tables. ');
unset($rows);
$bruteforce_tables = pb_backupbuddy::array_remove($tables, $bruteforce_excluded_tables);
// Removes all tables listed in $excluded_tables from $tables.
unset($tables);
if ($destination_type == 'multisite_import') {
    require_once pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php';
} else {
    require_once 'importbuddy/lib/dbreplace/dbreplace.php';
}
$dbreplace = new pluginbuddy_dbreplace($this);
// ********** BEGIN MAKING OLD URLS UNIQUE AND TRIMMING CORRESPONDING NEW URLS **********
// This entire section is in place to prevent duplicate replacements.
/*	array_pairs_unique_first()
 *	
 *	Takes two arrays. Looks for any duplicate values in the first array. That item is removed. The corresponding item in the second array is removed also.
 *	Resets indexes as a courtesy while maintaining order.
 *	
 function bruteforceTables()
 {
     global $wpdb;
     // Loop through the tables matching this prefix. Does NOT change data in other tables.
     // This changes actual data on a column by column basis for very row in every table.
     $tables = array();
     $rows = $wpdb->get_results("SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" . str_replace('_', '\\_', $this->overridePrefix) . "%' AND table_schema = DATABASE()", ARRAY_A);
     foreach ($rows as $row) {
         $tables[] = $row['table_name'];
     }
     pb_backupbuddy::status('message', 'Found ' . count($rows) . ' WordPress tables. ');
     unset($rows);
     $bruteforce_tables = pb_backupbuddy::array_remove($tables, $this->bruteforceExcludedTables);
     // Removes all tables listed in $excluded_tables from $tables.
     unset($tables);
     if ($this->destinationType == 'multisite_import') {
         require_once pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php';
     } else {
         require_once 'importbuddy/lib/dbreplace/dbreplace.php';
     }
     // Instantiate db replace class.
     $dbreplace = new pluginbuddy_dbreplace($this->startTime, self::TIME_WIGGLE_ROOM, $this->restoreData['maxExecutionTime']);
     if (is_array($this->restoreData['databaseSettings']['migrateResumePoint'])) {
         $steps = $this->restoreData['databaseSettings']['migrateResumePoint'][0];
         $stepResumePoint = $this->restoreData['databaseSettings']['migrateResumePoint'][1];
     } else {
         $stepResumePoint = '';
         $steps = array(array('Posts table site URLs.', 'text', $this->overridePrefix . 'posts', $this->oldURLs, $this->newURLs, array('post_content', 'post_excerpt', 'post_content_filtered')), array('WordPress core database text data.', 'text', $this->overridePrefix . 'users', $this->oldURLs, $this->newURLs, array('user_url')), array('WordPress core database text data.', 'text', $this->overridePrefix . 'comments', $this->oldURLs, $this->newURLs, array('comment_content', 'comment_author_url')), array('WordPress core database text data.', 'text', $this->overridePrefix . 'links', $this->oldURLs, $this->newURLs, array('link_url', 'link_image', 'link_target', 'link_description', 'link_notes', 'link_rss')), array('WordPress core database serialized data.', 'serialized', $this->overridePrefix . 'options', $this->oldFullReplace, $this->newFullReplace, array('option_value')), array('WordPress core database serialized data.', 'serialized', $this->networkPrefix . 'usermeta', $this->oldFullReplace, $this->newFullReplace, array('meta_value')), array('WordPress core database serialized data.', 'serialized', $this->overridePrefix . 'postmeta', $this->oldFullReplace, $this->newFullReplace, array('meta_value')), array('WordPress core database serialized data.', 'serialized', $this->overridePrefix . 'commentmeta', $this->oldFullReplace, $this->newFullReplace, array('meta_value')));
         if (!isset($this->restoreData['databaseSettings']['migrateDatabaseBruteForce']) || true !== $this->restoreData['databaseSettings']['migrateDatabaseBruteForce']) {
             // skip bruteforce.
             pb_backupbuddy::status('details', 'Brute force database migration skipped based on advanced settings');
         } else {
             // dont skip bruteforce.
             foreach ($bruteforce_tables as $bruteforce_table) {
                 $steps[] = array('Bruteforcing entire tables: `' . implode(',', $bruteforce_tables) . '`.', 'bruteforce_table', $bruteforce_table, $this->oldFullReplace, $this->newFullReplace);
             }
         }
     }
     foreach ($steps as $step) {
         $this->restoreData['databaseSettings']['migrateResumePoint'][1] = '';
         // Clear out needing to resume this substep for now.
         // Run the function.
         pb_backupbuddy::status('details', 'Starting substep `' . $step[0] . '`.');
         if ('bruteforce_table' == $step[1]) {
             // Table bruteforce has different param count.
             $results = call_user_func(array($dbreplace, $step[1]), $step[2], $step[3], $step[4], $stepResumePoint);
         } else {
             $results = call_user_func(array($dbreplace, $step[1]), $step[2], $step[3], $step[4], $step[5], $stepResumePoint);
         }
         pb_backupbuddy::status('details', 'Finished substep `' . $step[0] . '`.');
         if (TRUE === $results) {
             // Success so move to next loop.
             array_shift($steps);
             // Shifts step off the front of the array.
             // Do nothing... will just continue to next step.
             pb_backupbuddy::status('details', 'Database migration substep `' . $step[0] . '` finished successfully.');
             if ($this->nearTimeLimit()) {
                 return array($steps, '');
                 // array of remaining steps, no resume point since not within a function.
             }
         } elseif (is_array($results)) {
             // NEEDS CHUNKING.
             $steps = array_unshift($steps, $step);
             // This step did not finish so put it back at the beginning for resuming.
             pb_backupbuddy::status('details', 'Substep migrating the database did not complete in the first pass. Chunking into multiple parts. Resuming substep `' . $step . '` shortly at point `' . $results[0] . '`.');
             return array($steps, $results[0]);
             // Array of steps to run, resume point.
         } else {
             // FALSE or something weird...
             pb_backupbuddy::status('error', 'Database migration substep `' . $step[0] . '` failed. See log for details. This may only be a non-fatal warning.');
             return FALSE;
         }
     }
     // end foreach.
     // Update table prefixes in some WordPress meta data. $this->networkPrefix is set to the normal prefix in non-ms environment.
     $old_prefix = backupbuddy_core::dbEscape($this->restoreData['dat']['db_prefix']);
     $finalPrefix = backupbuddy_core::dbEscape($this->finalPrefix);
     pb_backupbuddy::status('details', 'Old DB prefix: `' . $old_prefix . '`; Override prefix: `' . $this->overridePrefix . '`. New final DB prefix (override does not apply): `' . $finalPrefix . '`. Network prefix: `' . $this->networkPrefix . '`');
     if ($old_prefix != $finalPrefix) {
         mysql_query("UPDATE `" . $this->overridePrefix . "usermeta` SET meta_key = REPLACE(meta_key, '" . $old_prefix . "', '" . $finalPrefix . "' );");
         // usermeta table temporarily is in the new subsite's prefix until next step.
         pb_backupbuddy::status('details', 'Modified ' . mysql_affected_rows() . ' row(s) while updating meta_key\'s for DB prefix in site\'s [subsite; temporary if multisite] usermeta table from `' . $old_prefix . '` to `' . $finalPrefix . '`.');
         if (mysql_error() != '') {
             pb_backupbuddy::status('error', 'mysql error: ' . mysql_error());
         }
         mysql_query("UPDATE `" . $this->overridePrefix . "options` SET option_name = '" . $finalPrefix . "user_roles' WHERE option_name ='" . $old_prefix . "user_roles' LIMIT 1");
         pb_backupbuddy::status('details', 'Modified ' . mysql_affected_rows() . ' row(s) while updating option_name user_roles DB prefix in [subsite if multisite] options table to `' . backupbuddy_core::dbEscape($finalPrefix) . '`.');
         if (mysql_error() != '') {
             pb_backupbuddy::status('error', 'mysql error: ' . mysql_error());
         }
         pb_backupbuddy::status('message', 'Updated prefix META data.');
     }
     pb_backupbuddy::status('message', 'Migrated ' . count($bruteforce_tables) . ' tables via brute force.');
     return true;
 }
Ejemplo n.º 3
0


// Loop through the tables matching this prefix. Does NOT change data in other tables.
// This changes actual data on a column by column basis for very row in every table.
$tables = array();
$result = mysql_query( "SHOW TABLES LIKE '" . str_replace( '_', '\_', $destination_db_prefix ) . "%'" );
while ( $table = mysql_fetch_row( $result ) ) {
	$tables[] = $table[0];
}
unset( $table );
pb_backupbuddy::status( 'message', 'Found ' . mysql_num_rows( $result ) . ' WordPress tables. ' );
unset( $result );


$bruteforce_tables = pb_backupbuddy::array_remove( $tables, $bruteforce_excluded_tables ); // Removes all tables listed in $excluded_tables from $tables.
unset( $tables );


if ( $destination_type == 'multisite_import' ) {
	require_once( pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php' );
} else {
	require_once( 'importbuddy/lib/dbreplace/dbreplace.php' );
}
$dbreplace = new pluginbuddy_dbreplace( $this );