Changeset 12766 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php
- Timestamp:
- 08/01/2023 02:58:10 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php
r12434 r12766 121 121 private string $header = ''; 122 122 private string $originals_by_year = ''; 123 private string $originals_by_translation_source = ''; 123 124 private string $translations_translators_by_year = ''; 124 125 private string $forum_post_and_replies_by_year = ''; … … 146 147 147 148 /** 149 * The id of the blog where the stats are stored. 150 * 151 * @var int 152 */ 153 private const MAKE_POLYGLOTS_BLOG_ID = 19; 154 155 /** 156 * The id of the page where the stats are stored. 157 * 158 * @var int 159 */ 160 private const POLYGLOTS_PAGE_ID = 42132; 161 162 /** 148 163 * Prints the Polyglots stats or stores them on a page. 149 164 * … … 161 176 } 162 177 163 define( 'MAKE_POLYGLOTS_BLOG_ID', 19 );164 define( 'POLYGLOTS_PAGE_ID', 42132 );165 166 178 $this->echo_the_values = $echo_the_values; 167 179 $this->set_number_of_years_with_data(); 168 180 $this->print_header(); 181 $this->print_stats_comparison( gmdate( 'Y-m-d' ) ); 169 182 $this->print_wordpress_translation_percentage(); 183 $this->print_stats_for_translation_sources(); 170 184 $this->print_packages_generated(); 171 185 $this->print_unique_themes_plugins_by_year(); … … 178 192 $this->print_most_active_translators(); 179 193 $this->store_stats(); 180 $this->print_stats_comparison( gmdate( 'Y-m-d' ) );181 194 182 195 $this->update_page(); … … 240 253 private function get_locale_requests() { 241 254 $locale_requests = array(); 242 switch_to_blog( MAKE_POLYGLOTS_BLOG_ID );255 switch_to_blog( self::MAKE_POLYGLOTS_BLOG_ID ); 243 256 $args = array( 244 257 'post_type' => 'post', … … 282 295 private function get_editor_requests() { 283 296 $editor_requests = array(); 284 switch_to_blog( MAKE_POLYGLOTS_BLOG_ID );297 switch_to_blog( self::MAKE_POLYGLOTS_BLOG_ID ); 285 298 register_taxonomy( 286 299 'p2_resolved', … … 943 956 'posts_per_page' => - 1, 944 957 'post_status' => 'publish', 945 'post_type' => $this::FEEDBACK_POST_TYPE,958 'post_type' => self::FEEDBACK_POST_TYPE, 946 959 'date_query' => array( 947 960 array( 'after' => '2022-07-28' ), 948 961 ), 949 962 ); 950 $feedback_posts_count = $wpdb->get_var( $wpdb->prepare( 951 "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status='publish' AND post_type=%s AND post_date > %s", $this::FEEDBACK_POST_TYPE, '2022-07-28' 952 )); 963 $feedback_posts_count = $wpdb->get_var( 964 $wpdb->prepare( 965 "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status='publish' AND post_type=%s AND post_date > %s", 966 self::FEEDBACK_POST_TYPE, 967 '2022-07-28' 968 ) 969 ); 953 970 $original_strings_with_comments = number_format_i18n( $feedback_posts_count ); 954 971 … … 958 975 array( 959 976 'number' => - 1, 960 'post_type' => $this::FEEDBACK_POST_TYPE,977 'post_type' => self::FEEDBACK_POST_TYPE, 961 978 'count' => true, 962 979 'date_query' => array( … … 970 987 // First, get the comments related with a translation, because we can get comments related 971 988 // only with the original. 972 $comment_meta_translation_ids = $wpdb->get_col( $wpdb->prepare( 973 "SELECT cm.meta_value FROM $wpdb->commentmeta cm, $wpdb->comments c, $wpdb->posts p WHERE p.post_status='publish' AND p.post_type=%s AND p.post_date > %s AND cm.meta_key = 'translation_id' AND c.comment_post_id = p.id AND cm.comment_id = c.comment_id", $this::FEEDBACK_POST_TYPE, '2022-07-28' 974 )); 989 $comment_meta_translation_ids = $wpdb->get_col( 990 $wpdb->prepare( 991 "SELECT cm.meta_value FROM $wpdb->commentmeta cm, $wpdb->comments c, $wpdb->posts p WHERE p.post_status='publish' AND p.post_type=%s AND p.post_date > %s AND cm.meta_key = 'translation_id' AND c.comment_post_id = p.id AND cm.comment_id = c.comment_id", 992 self::FEEDBACK_POST_TYPE, 993 '2022-07-28' 994 ) 995 ); 975 996 976 997 // Check all comments with a related translation. … … 1016 1037 1017 1038 // Get most active commenter's. 1018 $comment_user_ids = $wpdb->get_col( $wpdb->prepare( 1019 "SELECT c.user_id FROM $wpdb->comments c, $wpdb->posts p WHERE p.post_status='publish' AND p.post_type=%s AND p.post_date > %s AND c.comment_post_id = p.id", $this::FEEDBACK_POST_TYPE, '2022-07-28' 1020 )); 1039 $comment_user_ids = $wpdb->get_col( 1040 $wpdb->prepare( 1041 "SELECT c.user_id FROM $wpdb->comments c, $wpdb->posts p WHERE p.post_status='publish' AND p.post_type=%s AND p.post_date > %s AND c.comment_post_id = p.id", 1042 self::FEEDBACK_POST_TYPE, 1043 '2022-07-28' 1044 ) 1045 ); 1021 1046 1022 1047 $commenters_with_comment_count = array_count_values( $comment_user_ids ); … … 1166 1191 if ( ! $this->echo_the_values ) { 1167 1192 $this->contributors_per_locale .= $this->create_gutenberg_code( $code ); 1193 } else { 1194 WP_CLI::log( $code ); 1195 } 1196 } 1197 1198 /** 1199 * Print the stats for translation sources. 1200 * 1201 * @return void 1202 */ 1203 private function print_stats_for_translation_sources(): void { 1204 global $wpdb; 1205 // Source used: frontend, file import, playground 1206 $originals = $wpdb->get_results( 1207 "SELECT 1208 meta_key, 1209 meta_value, 1210 count(*) as number_of_strings 1211 FROM `translate_meta` 1212 WHERE 1213 object_type = 'translation' 1214 AND meta_key = 'source' 1215 AND meta_value <> '' 1216 GROUP BY 1217 meta_key, 1218 meta_value 1219 ORDER BY 1220 `translate_meta`. 1221 `meta_key` ASC, 1222 count(*) desc 1223 " 1224 ); 1225 if ( ! $this->echo_the_values ) { 1226 $this->originals_by_translation_source = $this->create_gutenberg_heading( 'Number of translations by translation source (starting on 2023-06-30)' ); 1227 } else { 1228 $this->print_wpcli_heading( 'Number of translations by translation source (starting on 2023-06-30)' ); 1229 } 1230 $code = "Source \t\t\t\t Number of strings" . PHP_EOL; 1231 $code .= '................................................................' . PHP_EOL; 1232 1233 foreach ( $originals as $original ) { 1234 $code .= str_pad( ucfirst( $original->meta_value ), 15 ) . " \t\t " . str_pad( number_format_i18n( $original->number_of_strings ), 15, ' ', STR_PAD_LEFT ) . PHP_EOL; 1235 } 1236 $code .= PHP_EOL; 1237 1238 if ( ! $this->echo_the_values ) { 1239 $this->originals_by_translation_source .= $this->create_gutenberg_code( $code ); 1240 } else { 1241 WP_CLI::log( $code ); 1242 } 1243 1244 // Suggestion used: TM, OpenAI, DeepL, undefined. 1245 $suggestions = $wpdb->get_results( 1246 "SELECT 1247 meta_key, 1248 meta_value, 1249 count(*) as number_of_strings 1250 FROM `translate_meta` 1251 WHERE 1252 object_type = 'translation' 1253 AND meta_key = 'suggestion_used' 1254 AND 1255 (meta_value LIKE 'tm%' 1256 OR meta_value LIKE 'openai%' 1257 OR meta_value LIKE 'deepl%') 1258 GROUP BY 1259 meta_key, 1260 meta_value 1261 ORDER BY 1262 `translate_meta`. 1263 `meta_key` ASC, 1264 count(*) desc 1265 " 1266 ); 1267 if ( ! $this->echo_the_values ) { 1268 $this->originals_by_translation_source .= $this->create_gutenberg_heading( 'Number of translations by suggestion source (starting on 2023-06-30)' ); 1269 } else { 1270 $this->print_wpcli_heading( 'Number of translations by suggestion source (starting on 2023-06-30)' ); 1271 } 1272 $code = "Source \t\t\t\t Number of strings" . PHP_EOL; 1273 $code .= '................................................................' . PHP_EOL; 1274 1275 foreach ( $suggestions as $suggestion ) { 1276 $code .= str_pad( $suggestion->meta_value, 15 ) . " \t\t " . str_pad( number_format_i18n( $suggestion->number_of_strings ), 15, ' ', STR_PAD_LEFT ) . PHP_EOL; 1277 } 1278 $code .= PHP_EOL; 1279 1280 if ( ! $this->echo_the_values ) { 1281 $this->originals_by_translation_source .= $this->create_gutenberg_code( $code ); 1282 } else { 1283 WP_CLI::log( $code ); 1284 } 1285 1286 // Suggestion from other languages. 1287 $suggestions_ol = $wpdb->get_results( 1288 "SELECT 1289 meta_key, 1290 meta_value, 1291 count(*) as number_of_strings 1292 FROM `translate_meta` 1293 WHERE 1294 object_type = 'translation' 1295 AND meta_key = 'suggestion_used' 1296 AND 1297 NOT (meta_value LIKE 'tm%' 1298 OR meta_value LIKE 'undefined%' 1299 OR meta_value LIKE 'openai%' 1300 OR meta_value LIKE 'deepl%') 1301 GROUP BY 1302 meta_key, 1303 meta_value 1304 ORDER BY 1305 `translate_meta`. 1306 `meta_key` ASC, 1307 count(*) desc 1308 " 1309 ); 1310 if ( ! $this->echo_the_values ) { 1311 $this->originals_by_translation_source .= $this->create_gutenberg_heading( 'Number of translations suggested from another language (starting on 2023-06-30)' ); 1312 } else { 1313 $this->print_wpcli_heading( 'Number of translations suggested from another language (starting on 2023-06-30)' ); 1314 } 1315 $code = "Language \t\t\t\t Number of strings" . PHP_EOL; 1316 $code .= '................................................................' . PHP_EOL; 1317 1318 foreach ( $suggestions_ol as $suggestion ) { 1319 $code .= str_pad( $suggestion->meta_value, 15 ) . " \t\t " . str_pad( number_format_i18n( $suggestion->number_of_strings ), 15, ' ', STR_PAD_LEFT ) . PHP_EOL; 1320 } 1321 $code .= PHP_EOL; 1322 1323 if ( ! $this->echo_the_values ) { 1324 $this->originals_by_translation_source .= $this->create_gutenberg_code( $code ); 1168 1325 } else { 1169 1326 WP_CLI::log( $code ); … … 1496 1653 'wp_revisions_to_keep', 1497 1654 function ( $num, $post ) { 1498 if ( POLYGLOTS_PAGE_ID === $post->ID ) {1655 if ( self::POLYGLOTS_PAGE_ID === $post->ID ) { 1499 1656 $num = 0; // pretend we don't want to keep revisions so that it will not lookup all old revisions. 1500 1657 } … … 1505 1662 2 1506 1663 ); 1507 switch_to_blog( MAKE_POLYGLOTS_BLOG_ID );1664 switch_to_blog( self::MAKE_POLYGLOTS_BLOG_ID ); 1508 1665 1509 1666 wp_update_post( 1510 1667 array( 1511 'ID' => POLYGLOTS_PAGE_ID,1668 'ID' => self::POLYGLOTS_PAGE_ID, 1512 1669 'post_type' => 'page', 1513 1670 'post_author' => 'Amieiro', … … 1528 1685 $this->stats_comparison . 1529 1686 $this->wordpress_translation_percentage . 1687 $this->originals_by_translation_source . 1530 1688 $this->originals_by_year . 1531 1689 $this->packages_generated_by_year .
Note: See TracChangeset
for help on using the changeset viewer.