jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/350383 )

Change subject: CorporaLookup::getByTranslationId: always use latest content
......................................................................


CorporaLookup::getByTranslationId: always use latest content

CorporaLookup::getByTranslationId was not taking into account
that the database might contain multiple entries for (section, origin)
tuple for given translation. Now handling this explicitly.

Change-Id: Id6e1bb19b138444eab4d76374115de3fc4bf433f
---
M includes/CorporaLookup.php
1 file changed, 14 insertions(+), 4 deletions(-)

Approvals:
  jenkins-bot: Verified
  Santhosh: Looks good to me, approved



diff --git a/includes/CorporaLookup.php b/includes/CorporaLookup.php
index c0155b0..b69990b 100644
--- a/includes/CorporaLookup.php
+++ b/includes/CorporaLookup.php
@@ -59,6 +59,8 @@
                                        'sequenceid' => 
(int)$row->cxc_sequence_id,
                                        self::TYPE_SOURCE => null,
                                        self::TYPE_MT => null,
+                                       // In the future this could be an 
array, but for now to
+                                       // keep it simple just show one version
                                        self::TYPE_USER => null,
                                ];
                        }
@@ -66,13 +68,21 @@
                        $blob = [
                                'engine' => $type === self::TYPE_MT ? 
$row->cxc_origin : null,
                                'content' => $row->cxc_content,
-                               // TS_ISO_8601 was chosen because it includes 
explicit timezone
+                               // TS_ISO_8601 is used because it includes 
timezone (always Z)
                                'timestamp' => wfTimestamp( TS_ISO_8601, 
$row->cxc_timestamp ),
                        ];
 
-                       // In the future 'user' could be an array, but for now 
to keep it simple and consistent,
-                       // just allow one blob (the latest & final user version)
-                       $sections[$id][$type] = $blob;
+                       if ( !isset( $sections[$id][$type] ) ) {
+                               $sections[$id][$type] = $blob;
+                               continue;
+                       }
+
+                       // It's possible we have a "conflict", since we don't 
enforce uniqueness
+                       // in the database. In this case, the one with latest 
timestamp is used.
+                       // Note: TS_ISO_8601 is suitable for string comparison 
if timezone is Z.
+                       if ( $blob['timestamp'] > 
$sections[$id][$type]['timestamp'] ) {
+                               $sections[$id][$type] = $blob;
+                       }
                }
 
                return $sections;

-- 
To view, visit https://gerrit.wikimedia.org/r/350383
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id6e1bb19b138444eab4d76374115de3fc4bf433f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to