Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/209033

Change subject: Check if eu_touched field exists
......................................................................

Check if eu_touched field exists

e.g. schema change not applied yet, then we need
skip this part of the usage tracking update.

Bug: T98186
Change-Id: I5b00c96b7aa99286728ff0aab55eedc48bc5aca4
---
M client/includes/Usage/Sql/UsageTableUpdater.php
1 file changed, 30 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/33/209033/1

diff --git a/client/includes/Usage/Sql/UsageTableUpdater.php 
b/client/includes/Usage/Sql/UsageTableUpdater.php
index 7325491..537573b 100644
--- a/client/includes/Usage/Sql/UsageTableUpdater.php
+++ b/client/includes/Usage/Sql/UsageTableUpdater.php
@@ -31,6 +31,11 @@
        private $batchSize;
 
        /**
+        * @var bool
+        */
+       private $hasTouchedField;
+
+       /**
         * @param DatabaseBase $connection
         * @param string $tableName
         * @param int $batchSize
@@ -137,7 +142,7 @@
         * @param string|false $touched timestamp
         */
        private function touchUsageForPage( $pageId, $touched ) {
-               if ( $touched === false ) {
+               if ( $touched === false || !$this->hasTouchedField() ) {
                        return;
                }
 
@@ -151,6 +156,22 @@
                        ),
                        __METHOD__
                );
+       }
+
+       /**
+        * Check if the usage tracking table has the touched field.
+        *
+        * @return bool
+        */
+       private function hasTouchedField() {
+               if ( !isset( $this->hasTouchedField ) ) {
+                       $this->hasTouchedField = $this->connection->fieldExists(
+                               $this->tableName,
+                               'eu_touched'
+                       );
+               }
+
+               return $this->hasTouchedField;
        }
 
        /**
@@ -193,12 +214,17 @@
                                throw new InvalidArgumentException( '$usages 
must contain EntityUsage objects.' );
                        }
 
-                       $rows[] = array(
+                       $fields = array(
                                'eu_page_id' => (int)$pageId,
                                'eu_aspect' => $usage->getAspect(),
-                               'eu_entity_id' => 
$usage->getEntityId()->getSerialization(),
-                               'eu_touched' => wfTimestamp( TS_MW, $touched ),
+                               'eu_entity_id' => 
$usage->getEntityId()->getSerialization()
                        );
+
+                       if ( $this->hasTouchedField() ) {
+                               $fields['eu_touched'] = wfTimestamp( TS_MW, 
$touched );
+                       }
+
+                       $rows[] = $fields;
                }
 
                return $rows;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b00c96b7aa99286728ff0aab55eedc48bc5aca4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to