Ticket #16215: 16215-13.patch
File 16215-13.patch, 4.4 KB (added by , 12 years ago) |
---|
-
wp-includes/revision.php
514 514 if ( ! $post ) 515 515 return false; 516 516 517 //make sure we have a current revision, only adds one if missing518 wp_save_post_revision( $post->ID );519 520 517 if ( ! post_type_supports( $post->post_type, 'revisions' ) ) 521 518 return false; 522 519 523 520 $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest 524 521 522 if ( ! $first = reset( $revisions ) ) 523 return true; 525 524 526 if ( ! $revisions ) 525 // Check if the revisions have already been updated 526 if ( preg_match( '/^\d+-(?:autosave|revision)-v\d+$/', $first->post_name ) ) 527 527 return true; 528 528 529 529 // Add post option exclusively 530 530 $lock = "revision-upgrade-{$post->ID}"; 531 $ locked_at= number_format( microtime( true ), 10, '.', '' );532 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $ locked_at) );531 $now = number_format( microtime( true ), 10, '.', '' ); 532 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) ); 533 533 if ( ! $result ) { 534 534 // If we couldn't get a lock, see how old the previous lock is 535 $locked _at= get_option( $lock );536 if ( ! $locked_at) {535 $locked = get_option( $lock ); 536 if ( ! $locked ) { 537 537 // Can't write to the lock, and can't read the lock. 538 538 // Something broken has happened 539 539 return false; 540 540 } 541 541 542 if ( $lock_at < number_format( microtime( true ), 10, '.', '' ) - 3600 ) { 543 // Lock is too old - try again 544 delete_option( $lock ); 545 return wp_upgrade_revisions_of_post( $post ); 542 if ( $locked > $now - 3600 ) { 543 // Lock is not too old: some other process may be upgrading this post. Bail. 544 return false; 546 545 } 547 546 548 // Lock is not too old: some other process may be upgrading this post. Bail. 549 return; 550 } else { 551 // If we could get a lock, re-"add" the option to fire all the correct filters. 552 add_option( $lock, $locked_at ); 547 // Lock is too old - update it (below) and continue 553 548 } 554 549 550 // If we could get a lock, re-"add" the option to fire all the correct filters. 551 update_option( $lock, $now ); 552 555 553 $success = true; 556 554 557 555 reset( $revisions ); … … 571 569 if ( 0 < $this_revision_version ) 572 570 continue; 573 571 574 // This revision is the oldest revision of the post. 575 // The correct post_author is probably $post->post_author, but that's only a good guess. 576 // Leave un-upgraded. 577 if ( ! $prev_revision ) { 578 continue; 579 } 572 // Always update the revision version 573 $update = array( 574 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ), 575 ); 580 576 581 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 577 // If this revision is the oldest revision of the post, i.e. no $prev_revision, 578 // the correct post_author is probably $post->post_author, but that's only a good guess. 579 // Update the revision version only and Leave the author as-is 580 if ( $prev_revision ) { 581 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 582 582 583 // If the previous revision is already up to date, it no longer has the information we need :(584 if ( 0 < $prev_revision_version ) {585 continue;583 // If the previous revision is already up to date, it no longer has the information we need :( 584 if ( $prev_revision_version < 1 ) 585 $update['post_author'] = $prev_revision->post_author; 586 586 } 587 587 588 588 // Upgrade this revision 589 // Cast as object so that wp_update_post() handles slashing for us 590 $update = (object) array( 591 'ID' => $this_revision->ID, 592 'post_name' => preg_replace( '/^(\d+-)(autosave|revision)-(\d+)$/', '$1$2-v1', $this_revision->post_name ), 593 'post_author' => $prev_revision->post_author, 594 ); 595 //error_log(json_encode($update)); 596 $result = wp_update_post( $update ); 597 if ( ! $result || is_wp_error( $result ) ) { 589 $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); 590 591 if ( $result ) { 592 wp_cache_delete( $this_revision->ID, 'posts' ); 593 } else { 598 594 // Wilhelm! 599 595 $success = false; 600 596 break; … … 602 598 } while ( $prev_revision ); 603 599 604 600 delete_option( $lock ); 605 return true;601 return $success; 606 602 } 607 603 608 604