<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12124] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php: Translate: Stats: Cleanup code and make it run without timing out.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/12124">12124</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/12124","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-10-13 06:20:37 +0000 (Thu, 13 Oct 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Translate: Stats: Cleanup code and make it run without timing out. This resolves the cron task that has been failing to process properly.
Changes include:
- Whitespace standardisation on leading/trailing lines
- Removal of mixed space/tab indentations, spaces only used for alignment purposes
- Function call syntax standardisation
- Removing all PHPCS MultipleArguments violation exclusions
- Using `$wpdb->prepare()` properly by passing the variables as arguements rather than interpolation.
- Using `$wpdb->get_var()` and `$wpdb->get_col()` when appropriate to avoid the need to `<a href="http://meta.trac.wordpress.org/changeset/[0]">[0]</a>->column` or`::object_to_string()`.
- Reformatting SQL for readability and standarisation
- Simplified some SQL using table aliases rather than full table names for readability
- Altered forum stats to use indexed `post_date` column instead of `post_date_gmt` which caused SQL to timeout (same values).
See <a href="http://meta.trac.wordpress.org/changeset/12114">[12114]</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php 2022-10-13 06:02:05 UTC (rev 12123)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php 2022-10-13 06:20:37 UTC (rev 12124)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -191,9 +191,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "SELECT
</span><span class="cx" style="display: block; padding: 0 10px"> YEAR( date_added ) as year,
</span><span class="cx" style="display: block; padding: 0 10px"> count(*) as strings
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- FROM {$wpdb->gp_originals}
- GROUP BY YEAR( date_added )
- ORDER BY YEAR( date_added ) DESC"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ FROM {$wpdb->gp_originals}
+ GROUP BY YEAR( date_added )
+ ORDER BY YEAR( date_added ) DESC"
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -236,11 +236,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $core_50_90 = $this->get_core_interval( 90, 50 );
</span><span class="cx" style="display: block; padding: 0 10px"> $core_50 = $this->get_core_interval( 50, 0, '<', '>' );
</span><span class="cx" style="display: block; padding: 0 10px"> $core_0 = $this->get_core_empty_translated();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->wordpress_translation_percentage = $this->create_gutenberg_heading( 'WordPress core: Translated percentage by the locale.' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->print_wpcli_heading( 'WordPress core: Translated percentage by the locale.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code = '................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= "Number of locales: \t" . number_format_i18n( count( $this->get_existing_locales() ) ) . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= "Number of locales with variants: \t" . number_format_i18n( count( $this->get_existing_locales( 'with_variants' ) ) ) . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -256,6 +258,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= 'The difference between the number of locales and the number of ' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= "WordPress (wp/dev) is due to some duplicated variants. \n" . PHP_EOL;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->wordpress_translation_percentage .= $this->create_gutenberg_code( $code );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -282,7 +285,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> WHERE updated >= '2010-01-01'
</span><span class="cx" style="display: block; padding: 0 10px"> GROUP BY LEFT( updated, 4 )
</span><span class="cx" style="display: block; padding: 0 10px"> ORDER BY LEFT( updated, 4 ) DESC",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ARRAY_A );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ARRAY_A
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $header = 'Language Packs generated per year.';
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -307,7 +311,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> str_pad( number_format_i18n( $package['plugin_packs'] ), 16 ) .
</span><span class="cx" style="display: block; padding: 0 10px"> str_pad( number_format_i18n( $package['theme_packs'] ), 16 ) .
</span><span class="cx" style="display: block; padding: 0 10px"> str_pad( number_format_i18n( $package['total_packs'] ), 16 ) .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- PHP_EOL;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ PHP_EOL;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '.......................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '(*) Estimated for the current year.' . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -345,7 +349,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> )a
</span><span class="cx" style="display: block; padding: 0 10px"> GROUP BY year
</span><span class="cx" style="display: block; padding: 0 10px"> ORDER BY year DESC",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ARRAY_A );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ARRAY_A
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $header = 'Unique Plugins / Themes language packs per year.';
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -387,7 +392,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * $translators = $wpdb->get_var(
</span><span class="cx" style="display: block; padding: 0 10px"> * $wpdb->prepare(
</span><span class="cx" style="display: block; padding: 0 10px"> * "SELECT COUNT( DISTINCT user_id) as translators
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * FROM translate_translations
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * FROM gp_translations
</ins><span class="cx" style="display: block; padding: 0 10px"> * WHERE date_modified >= '%s' and date_modified <= '%s'",
</span><span class="cx" style="display: block; padding: 0 10px"> * '2022-01-01 00:00:00',
</span><span class="cx" style="display: block; padding: 0 10px"> * '2022-12-31 23:59:59'
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -405,11 +410,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->print_wpcli_heading( 'Number of translations and translators in the last ' . $this->number_of_years . ' years.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code = "Year \t\t Number of translations \t Translators \t Translators with > 1 translation" . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $last_year = gmdate( 'Y' );
</span><span class="cx" style="display: block; padding: 0 10px"> $first_year = $last_year - $this->number_of_years;
</span><span class="cx" style="display: block; padding: 0 10px"> $first_id = 0;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> for ( $year = $last_year; $year > $first_year; $year -- ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( gmdate( 'Y' ) == $year ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $last_id = $wpdb->get_var( "SELECT MAX(id) FROM {$wpdb->gp_translations}" );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -416,48 +423,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $last_id = $first_id - 1;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $starting_date = $year . '-01-01 00:00:00';
- $first_id = $wpdb->get_var( $wpdb->prepare(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $first_id = $wpdb->get_var( $wpdb->prepare(
</ins><span class="cx" style="display: block; padding: 0 10px"> "SELECT MIN(id) FROM {$wpdb->gp_translations} WHERE date_added >= %s",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $starting_date
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $year . '-01-01'
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $row = $wpdb->get_row( $wpdb->prepare(
- "SELECT
- COUNT(*) as strings_added,
- COUNT( DISTINCT user_id ) as contributors
- FROM {$wpdb->gp_translations}
- WHERE id BETWEEN %d AND %d",
- $first_id,
- $last_id,
- ), ARRAY_A ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $row = $wpdb->get_row(
+ $wpdb->prepare(
+ "SELECT
+ COUNT(*) as strings_added,
+ COUNT( DISTINCT user_id ) as contributors
+ FROM {$wpdb->gp_translations}
+ WHERE id BETWEEN %d AND %d",
+ $first_id,
+ $last_id,
+ ),
+ ARRAY_A
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $strings_added = number_format_i18n( $row['strings_added'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $contributors = number_format_i18n( $row['contributors'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wpdb->get_results( $wpdb->prepare(
- "SELECT
- DISTINCT user_id, count(id) as translation_number
- FROM {$wpdb->gp_translations}
- WHERE id BETWEEN %d AND %d
- GROUP BY user_id
- HAVING( COUNT(id) > 1 )",
- $first_id,
- $last_id,
- ), ARRAY_A ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
- $repeat_contributors_rows = $wpdb->num_rows;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $repeat_contributors_val = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT COUNT(user_id) FROM (
+ SELECT DISTINCT user_id, count(id) as translations_number
+ FROM {$wpdb->gp_translations}
+ WHERE id BETWEEN %d AND %d
+ GROUP BY user_id
+ HAVING translations_number > 1
+ ) a",
+ $first_id,
+ $last_id,
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( gmdate( 'Y' ) == $year ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $strings_added = str_pad( number_format_i18n( $this->estimate_value_for_full_year( $row['strings_added'] ) ), 10, ' ', STR_PAD_LEFT );
</span><span class="cx" style="display: block; padding: 0 10px"> $contributors = str_pad( number_format_i18n( $this->estimate_value_for_full_year( $row['contributors'] ) ), 6, ' ', STR_PAD_LEFT );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $repeat_contributors = str_pad( number_format_i18n( $this->estimate_value_for_full_year( $repeat_contributors_rows ) ), 8, ' ', STR_PAD_LEFT );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $repeat_contributors = str_pad( number_format_i18n( $this->estimate_value_for_full_year( $repeat_contributors_val ) ), 8, ' ', STR_PAD_LEFT );
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= "{$year} (*) \t {$strings_added} \t\t\t {$contributors} \t {$repeat_contributors}" . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $strings_added = str_pad( number_format_i18n( $row['strings_added'] ), 10, ' ', STR_PAD_LEFT );
- $contributors = str_pad( number_format_i18n( $row['contributors'] ), 6, ' ', STR_PAD_LEFT );
- $repeat_contributors = str_pad( number_format_i18n( $repeat_contributors_rows ), 8, ' ', STR_PAD_LEFT );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $strings_added = str_pad( $strings_added, 10, ' ', STR_PAD_LEFT );
+ $contributors = str_pad( $contributors, 6, ' ', STR_PAD_LEFT );
+ $repeat_contributors = str_pad( number_format_i18n( $repeat_contributors_val ), 8, ' ', STR_PAD_LEFT );
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= "{$year} \t\t {$strings_added} \t\t\t {$contributors} \t {$repeat_contributors}" . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= '................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '(*) Estimated for the current year.' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -475,11 +488,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $forum_posts = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $forum_replies = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $code = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> for ( $year = $last_year; $year > $first_year; $year -- ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $forum_posts[ $year ] = $this->get_forums_stats( 'topic', $year );
</span><span class="cx" style="display: block; padding: 0 10px"> $forum_replies[ $year ] = $this->get_forums_stats( 'reply', $year );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> ksort($this->forum_ids);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $header = 'Forums. Topics by year and locale.';
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->forum_post_and_replies_by_year = $this->create_gutenberg_heading( $header );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -492,13 +508,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= str_pad( $year, 8,' ', STR_PAD_LEFT );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= PHP_EOL;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->forum_ids as $key => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= str_pad($key, 12 );
</span><span class="cx" style="display: block; padding: 0 10px"> for ( $year = $last_year; $year > $first_year; $year -- ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $code .= str_pad( number_format_i18n( $forum_posts[$year][$key] ), 8,' ', STR_PAD_LEFT );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $code .= str_pad( number_format_i18n( $forum_posts[$year][$key] ), 8,' ', STR_PAD_LEFT );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->forum_post_and_replies_by_year .= $this->create_gutenberg_code( $code );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -517,10 +535,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= str_pad( $year, 8,' ', STR_PAD_LEFT );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= PHP_EOL;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->forum_ids as $key => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= str_pad($key, 12 );
</span><span class="cx" style="display: block; padding: 0 10px"> for ( $year = $last_year; $year > $first_year; $year -- ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $code .= str_pad( number_format_i18n( $forum_replies[$year][$key] ), 8,' ', STR_PAD_LEFT );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $code .= str_pad( number_format_i18n( $forum_replies[$year][$key] ), 8,' ', STR_PAD_LEFT );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -539,14 +558,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function print_most_active_translators(): void {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $last_year = gmdate( 'Y' );
- $first_year = $last_year - $this->number_of_years;
- $first_id = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $last_year = gmdate( 'Y' );
+ $first_year = $last_year - $this->number_of_years;
+ $first_id = 0;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->most_active_translators = $this->create_gutenberg_heading( 'Most active translators in the last ' . $this->number_of_years . ' years.' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->print_wpcli_heading( 'Most active translators in the last ' . $this->number_of_years . ' years.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code = "Year \t Translations \t Translator" . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> for ( $year = $last_year; $year > $first_year; $year -- ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( gmdate( 'Y' ) == $year ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -554,25 +575,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $last_id = $first_id - 1;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $starting_date = $year . '-01-01 00:00:00';
- $first_id = $wpdb->get_var( $wpdb->prepare(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $first_id = $wpdb->get_var( $wpdb->prepare(
</ins><span class="cx" style="display: block; padding: 0 10px"> "SELECT MIN(id) FROM {$wpdb->gp_translations} WHERE date_added >= %s",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $starting_date
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $year . '-01-01'
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rows = $wpdb->get_results( $wpdb->prepare(
- "SELECT
- user_id,
- COUNT(*) as strings_added
- FROM {$wpdb->gp_translations}
- WHERE id BETWEEN %d AND %d
- GROUP BY user_id
- ORDER BY `strings_added` DESC
- LIMIT %d",
- $first_id,
- $last_id,
- $this->number_of_translators
- ), ARRAY_A ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $rows = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT
+ user_id,
+ COUNT(*) as strings_added
+ FROM {$wpdb->gp_translations}
+ WHERE id BETWEEN %d AND %d
+ GROUP BY user_id
+ ORDER BY `strings_added` DESC
+ LIMIT %d",
+ $first_id,
+ $last_id,
+ $this->number_of_translators
+ ),
+ ARRAY_A
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= '................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $rows as $row ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 0 == $row['user_id'] ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -625,14 +650,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $commenters = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the number of opt-in users.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $optin_users = number_format_i18n( $wpdb->get_var( $wpdb->prepare(
- "SELECT COUNT(user_id) as optin_users FROM {$wpdb->usermeta}
- WHERE meta_key = %s AND meta_value LIKE %s",
- 'wporg_351_gp_default_sort',
- '%s:19:\"notifications_optin\";s:2:\"on\";%' ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $optin_users = number_format_i18n(
+ $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT COUNT(user_id) as optin_users
+ FROM {$wpdb->usermeta}
+ WHERE meta_key = %s AND meta_value LIKE %s",
+ $wpdb->base_prefix . WPORG_TRANSLATE_BLOGID . '_gp_default_sort',
+ '%s:19:\"notifications_optin\";s:2:\"on\";%'
+ )
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the number of original strings with comments: one CPT for each original.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $feedback_posts_args = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $feedback_posts_args = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'posts_per_page' => - 1,
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_status' => 'publish',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => $this::FEEDBACK_POST_TYPE,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -640,32 +671,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> array( 'after' => '2022-07-28' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $feedback_posts = new WP_Query( $feedback_posts_args );
</span><span class="cx" style="display: block; padding: 0 10px"> $original_strings_with_comments = number_format_i18n( $feedback_posts->post_count );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the total number of comments.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $feedback_comments_args = array(
- 'number' => - 1,
- 'post_type' => $this::FEEDBACK_POST_TYPE,
- 'count' => true,
- 'date_query' => array(
- array( 'after' => '2022-07-28' ),
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $total_comments = number_format_i18n(
+ get_comments(
+ array(
+ 'number' => - 1,
+ 'post_type' => $this::FEEDBACK_POST_TYPE,
+ 'count' => true,
+ 'date_query' => array(
+ array( 'after' => '2022-07-28' ),
+ ),
+ )
+ )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $total_comments = number_format_i18n( get_comments( $feedback_comments_args ) );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get some info related with the status of the translations who get feedback.
</span><span class="cx" style="display: block; padding: 0 10px"> // First, get the comments related with a translation, because we can get comments related
</span><span class="cx" style="display: block; padding: 0 10px"> // only with the original.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $feedback_comments_args = array(
- 'post_type' => $this::FEEDBACK_POST_TYPE,
- 'count' => false,
- 'meta_key' => 'translation_id',
- 'date_query' => array(
- array( 'after' => '2022-07-28' ),
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comments = get_comments(
+ array(
+ 'post_type' => $this::FEEDBACK_POST_TYPE,
+ 'count' => false,
+ 'meta_key' => 'translation_id',
+ 'date_query' => array(
+ array( 'after' => '2022-07-28' ),
+ ),
+ )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comments = get_comments( $feedback_comments_args );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the translation ids with a feedback comment.
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $comments as $comment ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -677,11 +713,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $comment_meta_translation_ids as $comment_meta_translation_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $translation = $wpdb->get_row(
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'SELECT translate_translation_sets.locale, translate_translations.id, translate_translations.original_id,
- translate_translations.user_id, translate_translations.status
- FROM translate_translations
- INNER JOIN translate_translation_sets on translate_translations.translation_set_id=translate_translation_sets.id
- WHERE translate_translations.id= %s',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT s.locale, t.id, t.original_id, t.user_id, t.status
+ FROM {$wpdb->gp_translations} t
+ INNER JOIN {$wpdb->gp_translation_sets} s ON t.translation_set_id = s.id
+ WHERE t.id = %s",
</ins><span class="cx" style="display: block; padding: 0 10px"> $comment_meta_translation_id
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -691,14 +726,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'rejected' == $translation->status ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $is_current_from_rejection = $wpdb->get_row(
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "SELECT translate_translations.id, translate_translation_sets.locale
- FROM translate_translations
- INNER JOIN translate_translation_sets on translate_translations.translation_set_id=translate_translation_sets.id
- WHERE
- translate_translations.status='current'
- AND translate_translations.original_id=%d
- AND translate_translations.user_id=%d
- AND translate_translation_sets.locale=%s",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT t.id, s.locale
+ FROM {$wpdb->gp_translations} t
+ INNER JOIN {$wpdb->gp_translation_sets} s ON t.translation_set_id = s.id
+ WHERE
+ t.status='current'
+ AND t.original_id = %d
+ AND t.user_id = %d
+ AND s.locale = %s",
</ins><span class="cx" style="display: block; padding: 0 10px"> $translation->original_id,
</span><span class="cx" style="display: block; padding: 0 10px"> $translation->user_id,
</span><span class="cx" style="display: block; padding: 0 10px"> $translation->locale
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -712,19 +747,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get most active commenter's.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $most_active_commenters_args = array(
- 'post_type' => $this::FEEDBACK_POST_TYPE,
- 'count' => false,
- 'date_query' => array(
- array( 'after' => '2022-07-28' ),
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comments = get_comments(
+ array(
+ 'post_type' => $this::FEEDBACK_POST_TYPE,
+ 'count' => false,
+ 'date_query' => array(
+ array( 'after' => '2022-07-28' ),
+ ),
+ )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comments = get_comments( $most_active_commenters_args );
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $comments as $comment ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $comment_user_ids[] = $comment->user_id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $commenters_with_comment_count = array_count_values( $comment_user_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> arsort( $commenters_with_comment_count );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $commenters_number = number_format_i18n( count( $commenters_with_comment_count ) );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $commenters_with_comment_count as $user_id => $comment_number ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $user = get_user_by( 'id', $user_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -731,6 +769,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $user->comments_number = $comment_number;
</span><span class="cx" style="display: block; padding: 0 10px"> $commenters[] = $user;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Format and print the info.
</span><span class="cx" style="display: block; padding: 0 10px"> $comment_meta_translation_id_number = number_format_i18n( count( $comment_meta_translation_ids ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $rejected_number = number_format_i18n( $status_counter['rejected'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -738,6 +777,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $current_number = number_format_i18n( $status_counter['current'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $fuzzy_number = number_format_i18n( $status_counter['fuzzy'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $old_number = number_format_i18n( $status_counter['old'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->feedback_received = $this->create_gutenberg_heading( 'Feedback in the last ' . $this->number_of_years . ' years (starting on 2022-07-28).' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -797,6 +837,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->print_wpcli_heading( 'Managers stats.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code = 'Local managers (LM):' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total:\t\t\t\t\t\t\t\t" . number_format_i18n( array_sum( $locale_managers ) ) . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total users that have been registered this year and get the role:\t" . number_format_i18n( array_sum( $registered_this_year_new_locale_managers ) ) . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -806,6 +847,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= "\t - " . $locale->english_name . ': ' . number_format_i18n( $locale_managers[ $locale->english_name ] ) . ', ' . number_format_i18n( $registered_this_year_new_locale_managers[ $locale->english_name ] ) . ', ' . number_format_i18n( $started_this_year_new_locale_managers[ $locale->english_name ] ) . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= 'General Translator Editors (GTE):' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total:\t\t\t\t\t\t\t\t" . number_format_i18n( array_sum( $general_translation_editors ) ). PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total users that have been registered this year and get the role:\t" . number_format_i18n( array_sum( $registered_this_year_new_general_translation_editors ) ) . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -815,6 +857,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= "\t - " . $locale->english_name . ': ' . number_format_i18n( $general_translation_editors[ $locale->english_name ] ) . ', ' . number_format_i18n( $registered_this_year_new_general_translation_editors[ $locale->english_name ] ) . ', ' . number_format_i18n( $started_this_year_new_general_translation_editors[ $locale->english_name ] ) . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code .= 'Project Translation Editors (PTE):' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total:\t\t\t\t\t\t\t\t" . number_format_i18n( array_sum( $project_translation_editors ) ) . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= " - Total users that have been registered this year and get the role:\t" . number_format_i18n( array_sum( $registered_this_year_new_project_translation_editors ) ) . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -840,11 +883,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function print_contributors_per_locale():void {
</span><span class="cx" style="display: block; padding: 0 10px"> $locales = get_locales();
</span><span class="cx" style="display: block; padding: 0 10px"> $header = 'Contributors per locale';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->contributors_per_locale = $this->create_gutenberg_heading( $header );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->print_wpcli_heading( $header );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $code = '.........................................................................................' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= 'Active contributor: 1 translation in the last 365 days.' . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= '.........................................................................................' . PHP_EOL;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -854,9 +899,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $current_contributors = $this->get_translation_contributors( $locale, 365 );
</span><span class="cx" style="display: block; padding: 0 10px"> $all_contributors = $this->get_translation_contributors( $locale );
</span><span class="cx" style="display: block; padding: 0 10px"> $code .= str_pad( $locale->english_name, 40) .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- str_pad(number_format_i18n( count( $current_contributors ) ), 20) .
- str_pad(number_format_i18n( count($all_contributors) - count( $current_contributors ) ), 20) .
- str_pad(number_format_i18n( count( $all_contributors ) ), 20) . PHP_EOL;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ str_pad( number_format_i18n( count( $current_contributors ) ), 20) .
+ str_pad( number_format_i18n( count($all_contributors) - count( $current_contributors ) ), 20) .
+ str_pad( number_format_i18n( count( $all_contributors ) ), 20) . PHP_EOL;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->echo_the_values ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -889,8 +934,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 2, // 2 = wp/dev
</span><span class="cx" style="display: block; padding: 0 10px"> 'default'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- }
- if ( '' == $query ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
</ins><span class="cx" style="display: block; padding: 0 10px"> return array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -905,19 +949,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_core_total() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wpdb->get_results(
- $wpdb->prepare(
- "SELECT count(*) as counter from
- (SELECT
- (100 * stats.current/stats.all) as percent_complete
- FROM {$wpdb->project_translation_status} stats
- LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
- WHERE
- projects.path = 'wp/dev'
- AND projects.active = 1
- ) n"
- )
- )[0]->counter;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wpdb->get_var(
+ "SELECT count(*) as counter FROM (
+ SELECT
+ (100 * stats.current/stats.all) as percent_complete
+ FROM {$wpdb->project_translation_status} stats
+ LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
+ WHERE
+ projects.path = 'wp/dev'
+ AND projects.active = 1
+ ) n"
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -928,20 +970,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_core_full_translated() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wpdb->get_results(
- $wpdb->prepare(
- "SELECT count(*) as counter from
- (SELECT
- (100 * stats.current/stats.all) as percent_complete
- FROM {$wpdb->project_translation_status} stats
- LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
- WHERE
- projects.path = 'wp/dev'
- AND projects.active = 1
- HAVING
- percent_complete >= 100.00) n"
- )
- )[0]->counter;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wpdb->get_var(
+ "SELECT count(*) as counter FROM (
+ SELECT
+ (100 * stats.current/stats.all) as percent_complete
+ FROM {$wpdb->project_translation_status} stats
+ LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
+ WHERE
+ projects.path = 'wp/dev'
+ AND projects.active = 1
+ HAVING
+ percent_complete >= 100.00
+ ) n"
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -957,25 +998,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_core_interval( int $upper_value, int $lower_value, string $minor_symbol = '<', string $greater_symbol = '>=' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wpdb->get_results(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wpdb->get_var(
</ins><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "SELECT count(*) as counter from
- (SELECT
- (100 * stats.current/stats.all) as percent_complete
- FROM {$wpdb->project_translation_status} stats
- LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
- WHERE
- projects.path = 'wp/dev'
- AND projects.active = 1
- HAVING
- percent_complete %1s %2d
- AND percent_complete %3s %4d) n",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT count(*) as counter FROM (
+ SELECT
+ (100 * stats.current/stats.all) as percent_complete
+ FROM {$wpdb->project_translation_status} stats
+ LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
+ WHERE
+ projects.path = 'wp/dev'
+ AND projects.active = 1
+ HAVING
+ percent_complete %1\$s %2\$d
+ AND percent_complete %3\$s %4\$d
+ ) n",
</ins><span class="cx" style="display: block; padding: 0 10px"> $greater_symbol,
</span><span class="cx" style="display: block; padding: 0 10px"> $lower_value,
</span><span class="cx" style="display: block; padding: 0 10px"> $minor_symbol,
</span><span class="cx" style="display: block; padding: 0 10px"> $upper_value
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- )[0]->counter;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -986,20 +1028,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_core_empty_translated() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wpdb->get_results(
- $wpdb->prepare(
- "SELECT count(*) as counter from
- (SELECT
- (100 * stats.current/stats.all) as percent_complete
- FROM {$wpdb->project_translation_status} stats
- LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
- WHERE
- projects.path = 'wp/dev'
- AND projects.active = 1
- HAVING
- percent_complete <= 0.00) n"
- )
- )[0]->counter;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wpdb->get_var(
+ "SELECT count(*) as counter FROM (
+ SELECT
+ (100 * stats.current/stats.all) as percent_complete
+ FROM {$wpdb->project_translation_status} stats
+ LEFT JOIN {$wpdb->gp_projects} projects ON stats.project_id = projects.id
+ WHERE
+ projects.path = 'wp/dev'
+ AND projects.active = 1
+ HAVING
+ percent_complete <= 0.00
+ ) n"
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1009,42 +1050,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_id_first_user_of_this_year(): int {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user = $wpdb->get_row(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ return $wpdb->get_var(
</ins><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "SELECT * FROM {$wpdb->users} where user_registered >= %s limit 1",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT * FROM {$wpdb->users} WHERE user_registered >= %s LIMIT 1",
</ins><span class="cx" style="display: block; padding: 0 10px"> gmdate( 'Y-m-d H:i:s', strtotime( 'first day of january this year' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- return $user->ID;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Converts a property of an array of objects into a string with the properties of the
- * different objects separated by a parameter
- *
- * @param array $objects Array of objects to convert.
- * @param string $field Property of the object to convert.
- * @param string $glue Text used to put between the fields.
- *
- * @return string
- */
- private function object_to_string( array $objects, string $field = 'user_id', string $glue = ', ' ): string {
- $output = array();
- if ( ! empty( $objects ) && count( $objects ) > 0 ) {
- foreach ( $objects as $object ) {
- if ( is_array( $object ) && isset( $object[ $field ] ) ) {
- $output[] = $object[ $field ];
- } elseif ( is_object( $object ) && isset( $object->$field ) ) {
- $output[] = $object->$field;
- }
- }
- }
-
- return join( $glue, $output );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Gets the managers for the $role category for each locale.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * The role can be:
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1094,14 +1109,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the users that have registered this year.
</span><span class="cx" style="display: block; padding: 0 10px"> $query->query_where .= ' AND user_id >= ' . $this->id_first_user_of_this_year;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 'started_this_year' === $type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the users that have start translating this year.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql = "SELECT `user_id` FROM `translate_user_translations_count` WHERE `locale`='" .
- $locale->slug . "' AND `accepted` > 0 AND `date_added` > '" . gmdate( 'Y' ) . "-01-01 00:00:00'";
- $user_ids = $wpdb->get_results( $wpdb->prepare( $sql ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
- $user_ids = $this->object_to_string( $user_ids );
- $query->query_where .= ' AND user_id IN (' . $user_ids . ')';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_ids = $wpdb->get_col(
+ $wpdb->prepare(
+ "SELECT `user_id`
+ FROM `{$wpdb->user_translations_count}`
+ WHERE `locale` = %s AND
+ `accepted` > 0 AND
+ `date_added` > %s",
+ $locale->slug,
+ gmdate( 'Y-01-01' )
+ )
+ );
+
+ $query->query_where .= ' AND user_id IN (' . implode( ', ', array_map( 'intval', $user_ids ) ) . ')';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query->query();
</span><span class="cx" style="display: block; padding: 0 10px"> $users = $query->get_results();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1130,7 +1155,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $users = $wpdb->get_col(
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'SELECT DISTINCT user_id FROM translate_user_translations_count WHERE accepted > 0 AND locale = %s AND locale_slug = %s',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT DISTINCT user_id
+ FROM {$wpdb->user_translations_count}
+ WHERE accepted > 0 AND
+ locale = %s AND
+ locale_slug = %s",
</ins><span class="cx" style="display: block; padding: 0 10px"> $locale,
</span><span class="cx" style="display: block; padding: 0 10px"> $locale_slug
</span><span class="cx" style="display: block; padding: 0 10px"> ) . $date_constraint
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1173,19 +1202,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $date_constraint = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null !== $year ) {
- $date_constraint = $wpdb->prepare( ' AND YEAR(post_date_gmt) = ' . $year ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $year ) {
+ $date_constraint = $wpdb->prepare( ' AND YEAR(post_date) = %d', $year );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->forum_ids as $key => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql = "SELECT COUNT(id) as posts FROM wporg_{$value}_posts WHERE post_status='publish' AND post_type='{$type}'";
- $site_posts = $wpdb->get_row(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $posts[ $key ] = $wpdb->get_var(
</ins><span class="cx" style="display: block; padding: 0 10px"> $wpdb->prepare(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "SELECT COUNT(id) as posts FROM {$wpdb->base_prefix}{$value}_posts WHERE post_status = 'publish' AND post_type = %s",
+ $type
</ins><span class="cx" style="display: block; padding: 0 10px"> ) . $date_constraint
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $posts[ $key ] = $site_posts->posts;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $posts;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1217,12 +1246,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> switch_to_blog( MAKE_POLYGLOTS_BLOG_ID );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $ret = wp_update_post( array(
- 'ID' => POLYGLOTS_PAGE_ID,
- 'post_type' => 'page',
- 'post_author' => 'Amieiro',
- 'post_content' => $this->get_polyglots_stats_page_content(),
- ), true ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_update_post(
+ array(
+ 'ID' => POLYGLOTS_PAGE_ID,
+ 'post_type' => 'page',
+ 'post_author' => 'Amieiro',
+ 'post_content' => $this->get_polyglots_stats_page_content(),
+ ),
+ true
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> restore_current_blog();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1233,16 +1265,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_polyglots_stats_page_content(): string {
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->header .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->wordpress_translation_percentage .
- $this->originals_by_year .
- $this->packages_generated_by_year .
- $this->themes_plugins_by_year .
- $this->translations_translators_by_year .
- $this->forum_post_and_replies_by_year .
- $this->feedback_received .
- $this->contributors_per_locale .
- $this->managers_stats .
- $this->most_active_translators;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->wordpress_translation_percentage .
+ $this->originals_by_year .
+ $this->packages_generated_by_year .
+ $this->themes_plugins_by_year .
+ $this->translations_translators_by_year .
+ $this->forum_post_and_replies_by_year .
+ $this->feedback_received .
+ $this->contributors_per_locale .
+ $this->managers_stats .
+ $this->most_active_translators;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre>
</div>
</div>
</body>
</html>