Skip to content

Commit

Permalink
Merge pull request #21 from bradt/exclude-commentmeta-spam
Browse files Browse the repository at this point in the history
Spam commentmeta included when "Do not export spam comments" checked, fixes #18
  • Loading branch information
bradt committed Jul 26, 2013
2 parents 9654f76 + 61383cd commit 33c2803
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions wp-migrate-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,25 @@ function backup_table( $table, $segment = 'none' ) {
$where = '';
// We need ORDER BY here because with LIMIT, sometimes it will return
// the same results from the previous query and we'll have duplicate insert statements
if ( isset( $_POST['exclude-spam'] ) && $wpdb->comments == $table ) {
$where = ' WHERE comment_approved != "spam" ORDER BY comment_ID';
if ( isset( $_POST['exclude-spam'] ) ) {
if ( $wpdb->comments == $table ) {
$where = ' WHERE comment_approved != "spam" ORDER BY comment_ID';
}
elseif ( $wpdb->commentmeta == $table ) {
$where = sprintf( ' INNER JOIN %1$s
ON %1$s.comment_ID = %2$s.comment_id AND %1$s.comment_approved != \'spam\'
ORDER BY %2$s.meta_id',
$this->backquote( $wpdb->comments ), $this->backquote( $wpdb->commentmeta ) );
}
} elseif ( isset( $_POST['exclude-revisions'] ) && $wpdb->posts == $table ) {
$where = ' WHERE post_type != "revision" ORDER BY ID';
}

if ( !ini_get( 'safe_mode' ) ) @set_time_limit( 15*60 );
$table_data = $wpdb->get_results( "SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A );

$sql = "SELECT " . $this->backquote( $table ) . ".* FROM " . $this->backquote( $table ) . " $where LIMIT {$row_start}, {$row_inc}";

$table_data = $wpdb->get_results( $sql, ARRAY_A );

$entries = 'INSERT INTO ' . $this->backquote( $table ) . ' VALUES (';
// \x08\\x09, not required
Expand Down

0 comments on commit 33c2803

Please sign in to comment.