WordPress.org

Making WordPress.org

Changeset 2114


Ignore:
Timestamp:
11/22/2015 10:30:57 PM (3 years ago)
Author:
ocean90
Message:

Translate: Convert and merge the GP plugins "wporg-user-stats" and "wporg-project-stats" to a WP plugin.

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-stats
Files:
3 added
2 copied

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-stats/stats/project.php

    r2102 r2114  
    1313 * @author dd32
    1414 */
    15 class GP_WPorg_Project_Stats extends GP_Plugin {
    16     var $id = 'wporg-project-stats';
     15class WPorg_GP_Project_Stats {
    1716
    1817    public $projects_to_update = array();
    1918
    2019    function __construct() {
    21         global $gpdb;
    22         parent::__construct();
    23         $this->add_action( 'translation_created' );
    24         $this->add_action( 'translation_saved' );
    25         $this->add_action( 'originals_imported', array( 'args' => 5 ) );
     20        global $wpdb, $gp_table_prefix;
     21
     22        add_action( 'translation_created', array( $this, 'translation_created' ) );
     23        add_action( 'translation_saved', array( $this, 'translation_saved' ) );
     24        add_action( 'originals_imported', array( $this, 'originals_imported' ), 10, 5 );
    2625
    2726        // DB Writes are delayed until shutdown to bulk-update the stats during imports
    28         $this->add_action( 'shutdown' );
     27        add_action( 'shutdown', array( $this, 'shutdown' ) );
    2928
    30         $gpdb->project_translation_status = $gpdb->prefix . 'project_translation_status';
     29        $wpdb->project_translation_status = $gp_table_prefix . 'project_translation_status';
    3130    }
    3231
     
    7978
    8079    function shutdown() {
    81         global $gpdb;
     80        global $wpdb;
    8281        $values = array();
    8382
     
    119118                $counts = $this->get_project_translation_counts( $project_id, $locale, $locale_slug );
    120119
    121                 $values[] = $gpdb->prepare( '(%d, %s, %s, %d, %d, %d, %d, %d, %d)',
     120                $values[] = $wpdb->prepare( '(%d, %s, %s, %d, %d, %d, %d, %d, %d)',
    122121                    $project_id,
    123122                    $locale,
     
    134133            // If we're processing a large batch, add them as we go to avoid query lengths & memory limits
    135134            if ( count( $values ) > 50 ) {
    136                 $gpdb->query( "INSERT INTO {$gpdb->project_translation_status} (`project_id`, `locale`, `locale_slug`, `all`, `current`, `waiting`, `fuzzy`, `warnings`, `untranslated` ) VALUES " . implode( ', ', $values ) . " ON DUPLICATE KEY UPDATE `all`=VALUES(`all`), `current`=VALUES(`current`), `waiting`=VAlUES(`waiting`), `fuzzy`=VALUES(`fuzzy`), `warnings`=VALUES(`warnings`), `untranslated`=VALUES(`untranslated`)" );
     135                $wpdb->query( "INSERT INTO {$wpdb->project_translation_status} (`project_id`, `locale`, `locale_slug`, `all`, `current`, `waiting`, `fuzzy`, `warnings`, `untranslated` ) VALUES " . implode( ', ', $values ) . " ON DUPLICATE KEY UPDATE `all`=VALUES(`all`), `current`=VALUES(`current`), `waiting`=VAlUES(`waiting`), `fuzzy`=VALUES(`fuzzy`), `warnings`=VALUES(`warnings`), `untranslated`=VALUES(`untranslated`)" );
    137136                $values = array();
    138137            }
     
    141140
    142141        if ( $values ) {
    143             $gpdb->query( "INSERT INTO {$gpdb->project_translation_status} (`project_id`, `locale`, `locale_slug`, `all`, `current`, `waiting`, `fuzzy`, `warnings`, `untranslated` ) VALUES " . implode( ', ', $values ) . " ON DUPLICATE KEY UPDATE `all`=VALUES(`all`), `current`=VALUES(`current`), `waiting`=VALUES(`waiting`), `fuzzy`=VALUES(`fuzzy`), `warnings`=VALUES(`warnings`), `untranslated`=VALUES(`untranslated`)" );
     142            $wpdb->query( "INSERT INTO {$wpdb->project_translation_status} (`project_id`, `locale`, `locale_slug`, `all`, `current`, `waiting`, `fuzzy`, `warnings`, `untranslated` ) VALUES " . implode( ', ', $values ) . " ON DUPLICATE KEY UPDATE `all`=VALUES(`all`), `current`=VALUES(`current`), `waiting`=VALUES(`waiting`), `fuzzy`=VALUES(`fuzzy`), `warnings`=VALUES(`warnings`), `untranslated`=VALUES(`untranslated`)" );
    144143        }
    145144    }
    146145
    147146}
    148 GP::$plugins->wporg_project_stats = new GP_WPorg_Project_Stats;
    149147
    150148/*
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-stats/stats/user.php

    r2102 r2114  
    88 * @author dd32
    99 */
    10 class GP_WPorg_User_Stats extends GP_Plugin {
    11     var $id = 'wporg-user-stats';
     10class WPorg_GP_User_Stats {
    1211
    1312    function __construct() {
    14         global $gpdb;
     13        global $wpdb, $gp_table_prefix;
    1514
    16         parent::__construct();
    17         $this->add_action( 'translation_created' );
    18         $this->add_action( 'translation_saved' );
     15        add_action( 'translation_created', array( $this, 'translation_created' ) );
     16        add_action( 'translation_saved', array( $this, 'translation_saved' ) );
    1917
    20         $gpdb->user_translations_count = $gpdb->prefix . 'user_translations_count';
     18        $wpdb->user_translations_count = $gp_table_prefix . 'user_translations_count';
    2119    }
    2220
     
    4543
    4644        }
    47 
    4845    }
    4946
    5047    function bump_user_stat( $user_id, $locale, $locale_slug, $suggested = 0, $accepted = 0 ) {
    51         global $gpdb;
    52         $gpdb->query( $gpdb->prepare(
    53             "INSERT INTO {$gpdb->user_translations_count} (`user_id`, `locale`, `locale_slug`, `suggested`, `accepted`) VALUES (%d, %s, %s, %d, %d)
     48        global $wpdb;
     49        $wpdb->query( $wpdb->prepare(
     50            "INSERT INTO {$wpdb->user_translations_count} (`user_id`, `locale`, `locale_slug`, `suggested`, `accepted`) VALUES (%d, %s, %s, %d, %d)
    5451            ON DUPLICATE KEY UPDATE `suggested`=`suggested` + VALUES(`suggested`), `accepted`=`accepted` + VALUES(`accepted`)",
    5552            $user_id, $locale, $locale_slug, $suggested, $accepted
     
    5855
    5956}
    60 GP::$plugins->wporg_user_stats = new GP_WPorg_User_Stats;
    6157
    6258/*
Note: See TracChangeset for help on using the changeset viewer.