Denny Vrandecic has submitted this change and it was merged.

Change subject: (bug 46867) skip bad search keys and report them.
......................................................................


(bug 46867) skip bad search keys and report them.

rebuildTermsSearchKey.php now reports terms for which no search key
could be calculated, and skips them.

Change-Id: Iedd9cc3b56c0db2e5ed6c02a398d7c35b1c96a1b
---
M repo/includes/store/sql/TermSearchKeyBuilder.php
1 file changed, 19 insertions(+), 4 deletions(-)

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



diff --git a/repo/includes/store/sql/TermSearchKeyBuilder.php 
b/repo/includes/store/sql/TermSearchKeyBuilder.php
index f8fa085..d2fc77e 100644
--- a/repo/includes/store/sql/TermSearchKeyBuilder.php
+++ b/repo/includes/store/sql/TermSearchKeyBuilder.php
@@ -173,16 +173,24 @@
                        );
 
                        $c = 0;
+                       $cError = 0;
 
                        foreach ( $terms as $row ) {
-                               $this->updateSearchKey( $dbw, 
$row->term_row_id, $row->term_text, $row->term_language );
+                               $key = $this->updateSearchKey( $dbw, 
$row->term_row_id, $row->term_text, $row->term_language );
+
+                               if ( $key === false ) {
+                                       $this->report( "Unable to calculate 
search key for " . $row->term_text );
+                                       $cError += 1;
+                               } else {
+                                       $c+= 1;
+                               }
+
                                $rowId = $row->term_row_id;
-                               $c+= 1;
                        }
 
                        $dbw->commit();
 
-                       $this->report( "Updated $c search keys, up to row 
$rowId." );
+                       $this->report( "Updated $c search keys (skipped 
$cError), up to row $rowId." );
                        $total += $c;
 
                        if ( $c < $this->batchSize ) {
@@ -230,11 +238,18 @@
         * @param string $text the term's text
         * @param string $lang the term's language
         *
-        * @return string the search key
+        * @return string|bool the search key, or false if no search key could 
be calculated.
         */
        protected function updateSearchKey( \DatabaseBase $dbw, $rowId, $text, 
$lang ) {
                $key = Term::normalizeText( $text, $lang );
 
+               if ( $key === '' ) {
+                       wfDebugLog( __CLASS__, __FUNCTION__ . ": failed to 
normalized term: $text" );
+                       return false;
+               }
+
+               wfDebugLog( __CLASS__, __FUNCTION__ . ": row_id = $rowId, 
search_key = `$key`" );
+
                $dbw->update(
                        $this->table->getTableName(),
                        array(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iedd9cc3b56c0db2e5ed6c02a398d7c35b1c96a1b
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to