Making WordPress.org


Ignore:
Timestamp:
12/17/2015 11:09:09 AM (11 years ago)
Author:
ocean90
Message:

Credits API: Use the new table for locale validators.

Validators aka Translation Editors are now stored in a separate database table to be able to distinguish between Project Translation Editors and General Translation Editors.

See #1240.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/core/credits/wp-credits.php

    r2168 r2195  
    116116
    117117                if ( false === $validators ) {
    118                         $validators = $this->_grab_validators( $gp_locale );
     118                        $validators = $this->_grab_validators( $gp_locale, $path );
    119119                        $this->cache_set( $cache_key['validators'], $validators );
    120120                }
     
    176176        }
    177177
    178         private function _grab_validators( $gp_locale ) {
     178        private function _grab_validators( $gp_locale, $path ) {
    179179                global $wpdb;
    180                 $users = $this->grab_validators( $gp_locale );
     180                $users = $this->grab_validators( $gp_locale, $path );
    181181
    182182                if ( ! $users )
     
    199199        }
    200200
    201         protected function grab_validators( $gp_locale ) {
     201        protected function grab_validators( $gp_locale, $path ) {
    202202                global $wpdb;
    203                 $subdomain = $wpdb->get_var( $wpdb->prepare( "SELECT subdomain FROM locales WHERE locale = %s", $gp_locale->wp_locale ) );
    204                 $blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM wporg_blogs WHERE domain = %s AND path = '/'", "$subdomain.wordpress.org" ) );
    205                 if ( $blog_id ) {
    206                         $meta_key = 'wporg_' . intval( $blog_id ) . '_capabilities';
    207                         return $wpdb->get_col( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$meta_key' AND meta_value LIKE '%translation_editor%'" );
    208                 }
    209                 return array();
     203
     204                $path = 'wp/' . $path;
     205                $path = like_escape( $path ) . '%';
     206
     207                $project_ids = $wpdb->get_col( "SELECT `id` FROM `translate_projects` WHERE ( `path` LIKE '$path' OR `path` = 'wp' ) AND `active` = 1" ); // Project validators
     208                if ( ! $project_ids ) {
     209                        $project_ids = array();
     210                }
     211
     212                $project_ids[] = '0'; // Global validators
     213
     214                return $wpdb->get_col( $wpdb->prepare( "
     215                        SELECT `user_id` FROM `translate_translation_editors`
     216                        WHERE `project_id` IN (" . implode( ', ', $project_ids ) . ") AND `locale` = %s
     217                ", $gp_locale->slug ) );
    210218        }
    211219
Note: See TracChangeset for help on using the changeset viewer.