Making WordPress.org


Ignore:
Timestamp:
10/11/2016 08:27:15 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Add a plugin_committer taxonomy and sync it with the svn_access table.
The taxonomy is only used to ease querying, and allows for /author/$self to display both plugins you're listed as a contributor for and those you have commit access for.

See #2111

File:
1 edited

Legend:

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

    r3830 r4214  
    122122
    123123    /**
     124     * Syncs the list of committers from the svn_access table to a taxonomy.
     125     *
     126     * @static
     127     * @param string $plugin_slug The Plugin Slug to sync.
     128     */
     129    public static function sync_plugin_committers_with_taxonomy( $plugin_slug ) {
     130        $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     131        if ( ! $post ) {
     132            return false;
     133        }
     134
     135        $committer_slugs = array();
     136        foreach ( Tools::get_plugin_committers( $plugin_slug ) as $committer ) {
     137            $user = get_user_by( 'login', $committer );
     138            if ( $user ) {
     139                $committer_slugs[] = $user->user_nicename;
     140            }
     141        }
     142
     143        wp_set_post_terms( $post->ID, $committer_slugs, 'plugin_committers' );
     144    }
     145
     146    /**
    124147     * Grant a user RW access to a plugin.
    125148     *
     
    149172        }
    150173
    151         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    152         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    153 
    154         return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     174        $result = (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
    155175            'path'   => "/{$plugin_slug}",
    156176            'user'   => $user->user_login,
    157177            'access' => 'rw',
    158178        ) );
     179
     180        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     181        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     182        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     183
     184        return $result;
    159185    }
    160186
     
    180206        }
    181207
    182         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    183         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    184 
    185         return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     208        $result = (bool) $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
    186209            'path' => "/{$plugin_slug}",
    187210            'user' => $user->user_login,
    188211        ) );
     212
     213        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     214        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     215        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     216
     217        return $result;
    189218    }
    190219
Note: See TracChangeset for help on using the changeset viewer.