Changeset 9709
- Timestamp:
- 04/08/2020 06:31:10 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-stats/stats/user.php
r4350 r9709 10 10 class WPorg_GP_User_Stats { 11 11 12 private $user_stats = array(); 12 private $user_stats = []; 13 14 private $user_project_stats = []; 13 15 14 16 public function __construct() { … … 22 24 23 25 $wpdb->user_translations_count = $gp_table_prefix . 'user_translations_count'; 26 $wpdb->user_projects = $gp_table_prefix . 'user_projects'; 24 27 } 25 28 … … 44 47 45 48 } 49 50 // Record the last time the user submitted a translation for a project/locale. 51 if ( 'gp_translation_created' == current_filter() ) { 52 $project = GP::$project->get( $translation_set->project_id ); 53 54 // Find the "root" project ID. 55 // For projects with sub-projects, we only want to store the "parent" project. 56 // ie. wp-plugins/plugin-name, wp/dev, or apps/android 57 $project_path_we_want = implode( '/', array_slice( explode( '/', $project->path ), 0, 2 ) ); 58 if ( $project_path_we_want != $project->path ) { 59 $project = GP::$project->by_path( $project_path_we_want ); 60 } 61 62 $this->user_project_stats[ "{$translation->user_id},{$project->id},{$translation_set->locale},{$translation_set->slug}" ] = true; 63 } 46 64 } 47 65 … … 65 83 $now = current_time( 'mysql', 1 ); 66 84 67 $values = array();85 $values = []; 68 86 foreach ( $this->user_stats as $key => $stats ) { 69 87 list( $user_id, $locale, $locale_slug ) = explode( ',', $key ); … … 86 104 ON DUPLICATE KEY UPDATE `suggested`=`suggested` + VALUES(`suggested`), `accepted`=`accepted` + VALUES(`accepted`), `date_modified`=VALUES(`date_modified`)" 87 105 ); 88 $values = array();106 $values = []; 89 107 } 90 108 } … … 96 114 ON DUPLICATE KEY UPDATE `suggested`=`suggested` + VALUES(`suggested`), `accepted`=`accepted` + VALUES(`accepted`), `date_modified`=VALUES(`date_modified`)" 97 115 ); 116 $values = []; 117 } 118 119 // Process the project stats too. 120 $values = []; 121 foreach ( $this->user_project_stats as $key => $dummy ) { 122 list( $user_id, $project_id, $locale, $locale_slug ) = explode( ',', $key ); 123 124 $values[] = $wpdb->prepare( '(%d, %d, %s, %s, %s)', 125 $user_id, 126 $project_id, 127 $locale, 128 $locale_slug, 129 $now 130 ); 131 132 if ( count( $values ) > 50 ) { 133 $wpdb->query( 134 "INSERT INTO {$wpdb->user_projects} (`user_id`, `project_id`, `locale`, `locale_slug`, `last_modified`) 135 VALUES " . implode( ', ', $values ) . " 136 ON DUPLICATE KEY UPDATE `last_modified` = GREATEST( `last_modified`, VALUES(`last_modified`) )" 137 ); 138 $values = []; 139 } 140 } 141 if ( $values ) { 142 $wpdb->query( 143 "INSERT INTO {$wpdb->user_projects} (`user_id`, `project_id`, `locale`, `locale_slug`, `last_modified`) 144 VALUES " . implode( ', ', $values ) . " 145 ON DUPLICATE KEY UPDATE `last_modified` = GREATEST( `last_modified`, VALUES(`last_modified`) )" 146 ); 147 $values = []; 98 148 } 99 149 } … … 101 151 102 152 /* 103 Table :153 Tables: 104 154 105 155 Note: WordPress uses BIGINT(20) for user_id; GlotPress uses int(10) … … 119 169 ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 120 170 171 CREATE TABLE `gp_user_projects` ( 172 `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 173 `user_id` int(10) unsigned NOT NULL, 174 `project_id` int(11) unsigned NOT NULL, 175 `locale` varchar(255) NOT NULL, 176 `locale_slug` varchar(255) NOT NULL DEFAULT 'default', 177 `last_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 178 PRIMARY KEY (`id`), 179 UNIQUE KEY `user_project_locale` (`user_id`,`project_id`,`locale`,`locale_slug`) 180 ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 121 181 */
Note: See TracChangeset
for help on using the changeset viewer.