Making WordPress.org

Changeset 1382


Ignore:
Timestamp:
03/06/2015 02:22:56 AM (10 years ago)
Author:
obenland
Message:

WP.org Themes: Add the ability to properly handle ticket reopenings.

In case a final approved ticket gets reopened, it sets the previous live
version to live again.

Fixes #926.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r1379 r1382  
    276276 */
    277277function wporg_themes_update_version_status( $post_id, $current_version, $new_status ) {
    278     $meta = get_post_meta( $post_id, '_status', true );
     278    $meta       = get_post_meta( $post_id, '_status', true );
     279    $old_status = $meta[ $current_version ];
     280
     281    // Don't do anything when the status hasn't changed.
     282    if ( $new_status == $old_status ) {
     283        return;
     284    }
    279285
    280286    switch ( $new_status ) {
     
    303309     * @param string $current_version The theme version that was updated.
    304310     * @param string $new_status      The new status for that theme version.
     311     * @param string $old_status      The old status for that theme version.
    305312     */
    306     do_action( 'wporg_themes_update_version_status', $post_id, $current_version, $new_status );
     313    do_action( 'wporg_themes_update_version_status', $post_id, $current_version, $new_status, $old_status );
    307314
    308315    /**
     
    312319     * @param int    $post_id         Post ID.
    313320     * @param string $current_version The theme version that was updated.
     321     * @param string $old_status      The old status for that theme version.
    314322     */
    315     do_action( "wporg_themes_update_version_{$new_status}", $post_id, $current_version );
     323    do_action( "wporg_themes_update_version_{$new_status}", $post_id, $current_version, $old_status );
    316324
    317325    return update_post_meta( $post_id, '_status', $meta );
     
    325333 * @param int    $post_id
    326334 * @param string $version
    327  */
    328 function wporg_themes_approve_version( $post_id, $version ) {
    329     $post      = get_post( $post_id );
     335 * @param string $old_status
     336 */
     337function wporg_themes_approve_version( $post_id, $version, $old_status ) {
     338    $post = get_post( $post_id );
     339
     340    wporg_themes_update_wpthemescom( $post->post_name, $version );
     341
     342    /*
     343     * Bail if we're activating an old version, the author does not need to be
     344     * notified about that.
     345     */
     346    if ( 'old' == $old_status ) {
     347        return;
     348    }
     349
    330350    $ticket_id = wporg_themes_get_version_meta( $post_id, '_ticket_id', $version );
    331351    $subject = $content = '';
     
    353373
    354374    wp_mail( get_user_by( 'id', $post->post_author )->user_email, $subject, $content, 'From: themes@wordpress.org' );
    355 
    356     wporg_themes_update_wpthemescom( $post->post_name, $version );
    357 }
    358 add_action( 'wporg_themes_update_version_live', 'wporg_themes_approve_version', 10, 2 );
     375}
     376add_action( 'wporg_themes_update_version_live', 'wporg_themes_approve_version', 10, 3 );
    359377
    360378/**
     
    382400}
    383401add_action( 'wporg_themes_update_version_old', 'wporg_themes_close_version', 10, 2 );
     402
     403/**
     404 * Rolls back a live theme version.
     405 *
     406 * If the rolledback version was live, it finds the previous live version and
     407 * sets it live again.
     408 *
     409 * @param int    $post_id
     410 * @param string $version
     411 * @param string $old_status
     412 */
     413function wporg_themes_rollback_version( $post_id, $current_version, $old_status ) {
     414    // If the version wasn't live, there's nothing for us to do.
     415    if ( 'live' != $old_status ) {
     416        return;
     417    }
     418
     419    if ( ! class_exists( 'Trac' ) ) {
     420        require_once ABSPATH . WPINC . '/class-IXR.php';
     421        require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
     422        require_once WPORGPATH . 'bb-theme/themes/lib/class-trac.php';
     423    }
     424
     425    // Check for tickets that were set to live previously.
     426    $trac    = new Trac( 'themetracbot', THEME_TRACBOT_PASSWORD, 'https://themes.trac.wordpress.org/login/xmlrpc' );
     427    $tickets = (array) $trac->ticket_query( add_query_arg( array(
     428        'status'     => 'closed',
     429        'resolution' => 'live',
     430        'keywords'   => '~theme-' . get_post( $post_id )->post_name,
     431        'order'      => 'changetime',
     432        'desc'       => 1,
     433    ) ) );
     434    $ticket = next( $tickets );
     435
     436    // Bail if there is no prior live versions.
     437    if ( ! $ticket ) {
     438        return;
     439    }
     440
     441    // Find the version number associated with the approved ticket.
     442    $ticket_ids   = get_post_meta( $post_id, '_ticket_id', true );
     443    $prev_version = array_search( $ticket, $ticket_ids );
     444
     445    wporg_themes_update_version_status( $post_id, $prev_version, 'live' );
     446}
     447add_action( 'wporg_themes_update_version_new', 'wporg_themes_rollback_version', 10, 3 );
    384448
    385449/**
Note: See TracChangeset for help on using the changeset viewer.