jenkins-bot has submitted this change and it was merged.
Change subject: Update for php min version 5.5
......................................................................
Update for php min version 5.5
MediaWiki minimum version is now 5.5, do away with some public
things that never needed to be public.
Depends-On: I68c5b5d60952418ff8300c163edfe2275571f41f
Change-Id: I171dce4e89b519eea31d4de69306726aeaac2633
---
M includes/CompletionSuggester.php
M includes/DataSender.php
M includes/ElasticsearchIntermediary.php
M includes/Maintenance/Reindexer.php
M includes/Maintenance/Validators/IndexAliasValidator.php
M includes/Searcher.php
M maintenance/dumpIndex.php
M maintenance/updateSuggesterIndex.php
M tests/unit/UtilTest.php
9 files changed, 87 insertions(+), 118 deletions(-)
Approvals:
Smalyshev: Looks good to me, but someone else must approve
MaxSem: Looks good to me, approved
Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/CompletionSuggester.php b/includes/CompletionSuggester.php
index 2cfde24..51fdab0 100644
--- a/includes/CompletionSuggester.php
+++ b/includes/CompletionSuggester.php
@@ -112,9 +112,8 @@
/**
* Search environment configuration
* @var SearchConfig
- * Specified as public because of closures. When we move to non-anicent
PHP version, can be made protected.
*/
- public $config;
+ private $config;
/**
* @var string Query type (comp_suggest_geo or comp_suggest)
@@ -179,19 +178,18 @@
'queryType' => $this->queryType,
);
$searcher = $this;
- $limit = $this->limit;
$result = Util::doPoolCounterWork(
'CirrusSearch-Completion',
$this->user,
function() use( $searcher, $index, $suggest,
$logContext, $queryOptions,
- $profiles, $text , $limit ) {
+ $profiles, $text ) {
$description = "{queryType} search for
'{query}'";
$searcher->start( $description, $logContext );
try {
$result = $index->request( "_suggest",
Request::POST, $suggest, $queryOptions );
if( $result->isOk() ) {
$result =
$searcher->postProcessSuggest( $result,
- $profiles, $limit );
+ $profiles, $this->limit
);
return $searcher->success(
$result );
}
return $result;
diff --git a/includes/DataSender.php b/includes/DataSender.php
index b25ba75..ad344d3 100644
--- a/includes/DataSender.php
+++ b/includes/DataSender.php
@@ -169,10 +169,9 @@
$bulk->addData( $data, 'update' );
$bulk->send();
} catch ( ResponseException $e ) {
- $cirrusLog = $this->log;
$missing =
$this->bulkResponseExceptionIsJustDocumentMissing( $e,
- function( $id ) use ( $cirrusLog, $e ) {
- $cirrusLog->info(
+ function( $id ) use ( $e ) {
+ $this->log->info(
"Updating a page that doesn't
yet exist in Elasticsearch: {id}",
array( 'id' => $id )
);
diff --git a/includes/ElasticsearchIntermediary.php
b/includes/ElasticsearchIntermediary.php
index 502123a..92a6783 100644
--- a/includes/ElasticsearchIntermediary.php
+++ b/includes/ElasticsearchIntermediary.php
@@ -119,9 +119,8 @@
/**
* Summarizes all the requests made in this process and reports
* them along with the test they belong to.
- * Only public due to php 5.3 not having access from closures
*/
- public static function reportLogContexts() {
+ private static function reportLogContexts() {
if ( !self::$logContexts ) {
return;
}
diff --git a/includes/Maintenance/Reindexer.php
b/includes/Maintenance/Reindexer.php
index fe974ed..b43031c 100644
--- a/includes/Maintenance/Reindexer.php
+++ b/includes/Maintenance/Reindexer.php
@@ -299,25 +299,24 @@
$this->outputIndented( $messagePrefix . "About to
reindex $totalDocsToReindex documents\n" );
$operationStartTime = microtime( true );
$completed = 0;
- $self = $this;
Util::iterateOverScroll( $this->oldIndex,
$result->getResponse()->getScrollId(), '1h',
- function( $results ) use ( $properties,
$retryAttempts, $messagePrefix, $self, $type,
+ function( $results ) use ( $properties,
$retryAttempts, $messagePrefix, $type,
&$completed,
$totalDocsToReindex, $operationStartTime ) {
$documents = array();
foreach( $results as $result ) {
- $documents[] =
$self->buildNewDocument( $result, $properties );
+ $documents[] =
$this->buildNewDocument( $result, $properties );
}
- $self->withRetry( $retryAttempts,
$messagePrefix, 'retrying as singles',
- function() use ( $self, $type,
$messagePrefix, $documents ) {
- $self->sendDocuments(
$type, $messagePrefix, $documents );
+ $this->withRetry( $retryAttempts,
$messagePrefix, 'retrying as singles',
+ function() use ( $type,
$messagePrefix, $documents ) {
+ $this->sendDocuments(
$type, $messagePrefix, $documents );
} );
$completed += sizeof( $results );
$rate = round( $completed / (
microtime( true ) - $operationStartTime ) );
- $self->outputIndented( $messagePrefix .
+ $this->outputIndented( $messagePrefix .
"Reindexed
$completed/$totalDocsToReindex documents at $rate/second\n");
}, 0, $retryAttempts,
- function( $e, $errors ) use ( $self,
$messagePrefix ) {
- $self->sleepOnRetry( $e, $errors,
$messagePrefix, 'fetching documents to reindex' );
+ function( $e, $errors ) use ( $messagePrefix ) {
+ $this->sleepOnRetry( $e, $errors,
$messagePrefix, 'fetching documents to reindex' );
} );
$this->outputIndented( $messagePrefix . "All done\n" );
@@ -340,7 +339,7 @@
* @param array() $properties mapping properties
* @return Document
*/
- public function buildNewDocument( $result, $properties ) {
+ private function buildNewDocument( $result, $properties ) {
// Build the new document to just contain keys which have a
mapping in the new properties. To clean
// out any old fields that we no longer use.
$data = Util::cleanUnusedFields( $result->getSource(),
$properties );
@@ -389,11 +388,10 @@
* @param callable $func
* @return mixed
*/
- public function withRetry( $attempts, $messagePrefix, $description,
$func) {
- $self = $this;
+ private function withRetry( $attempts, $messagePrefix, $description,
$func) {
return Util::withRetry ( $attempts, $func,
- function( $e, $errors ) use ( $self, $messagePrefix,
$description ) {
- $self->sleepOnRetry( $e, $errors,
$messagePrefix, $description );
+ function( $e, $errors ) use ( $messagePrefix,
$description ) {
+ $this->sleepOnRetry( $e, $errors,
$messagePrefix, $description );
} );
}
@@ -403,7 +401,7 @@
* @param string $messagePrefix
* @param string $description
*/
- public function sleepOnRetry(\Exception $e, $errors, $messagePrefix,
$description ) {
+ private function sleepOnRetry(\Exception $e, $errors, $messagePrefix,
$description ) {
$type = get_class( $e );
$seconds = Util::backoffDelay( $errors );
$message = ElasticsearchIntermediary::extractMessage( $e );
@@ -414,10 +412,8 @@
/**
* Send documents to type with retry.
- * This is really private, marked as public for closure use.
- * @access private
*/
- public function sendDocuments( Type $type, $messagePrefix, $documents )
{
+ private function sendDocuments( Type $type, $messagePrefix, $documents
) {
try {
$type->addDocuments( $documents );
} catch ( ExceptionInterface $e ) {
@@ -460,11 +456,9 @@
}
/**
- * Public for 5.3 compatibility with closures
- *
* @param string $message
*/
- public function outputIndented( $message ) {
+ private function outputIndented( $message ) {
if ( $this->out ) {
$this->out->outputIndented( $message );
}
diff --git a/includes/Maintenance/Validators/IndexAliasValidator.php
b/includes/Maintenance/Validators/IndexAliasValidator.php
index 91e253a..2ca68e2 100644
--- a/includes/Maintenance/Validators/IndexAliasValidator.php
+++ b/includes/Maintenance/Validators/IndexAliasValidator.php
@@ -100,9 +100,8 @@
* @return Status
*/
protected function updateIndices( array $add, array $remove ) {
- $client = $this->client;
- $remove = array_filter( $remove, function ( $name ) use (
$client ) {
- return $client->getIndex( $name )->exists();
+ $remove = array_filter( $remove, function ( $name ) {
+ return $this->client->getIndex( $name )->exists();
} );
if ( $remove ) {
$this->outputIndented( "\tRemoving old indices...\n" );
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 439ac69..fa7536e 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -185,9 +185,8 @@
/**
* Search environment configuration
* @var SearchConfig
- * Specified as public because of closures. When we move to non-anicent
PHP version, can be made protected.
*/
- public $config;
+ private $config;
/**
* @var SearchContext
@@ -355,7 +354,6 @@
}
// Transform Mediawiki specific syntax to filters and extra
(pre-escaped) query string
- $searcher = $this;
$originalTerm = $term;
$searchContainedSyntax = false;
$this->term = $term;
@@ -409,8 +407,8 @@
$this->extractSpecialSyntaxFromTerm(
'/^\s*local:/',
- function ( $matches ) use ( $searcher ) {
- $searcher->limitSearchToLocalWiki( true );
+ function ( $matches ) {
+ $this->limitSearchToLocalWiki( true );
return '';
}
);
@@ -421,9 +419,9 @@
$highlightSource = array();
$this->extractSpecialSyntaxFromTerm(
'/(?<not>-)?insource:\/(?<pattern>(?:[^\\\\\/]|\\\\.)+)\/(?<insensitive>i)? ?/',
- function ( $matches ) use ( $searcher, &$filters,
&$notFilters, &$searchContainedSyntax, &$searchType, &$highlightSource ) {
+ function ( $matches ) use ( &$filters, &$notFilters,
&$searchContainedSyntax, &$searchType, &$highlightSource ) {
- if ( !$searcher->config->get(
'CirrusSearchEnableRegex' ) ) {
+ if ( !$this->config->get(
'CirrusSearchEnableRegex' ) ) {
return;
}
@@ -437,11 +435,11 @@
} else {
$highlightSource[] = array(
'pattern' => $matches[
'pattern' ],
- 'locale' =>
$searcher->config->get( 'LanguageCode' ),
+ 'locale' => $this->config->get(
'LanguageCode' ),
'insensitive' => $insensitive,
);
}
- $regex = $searcher->config->getElement(
'CirrusSearchWikimediaExtraPlugin', 'regex' );
+ $regex = $this->config->getElement(
'CirrusSearchWikimediaExtraPlugin', 'regex' );
if ( $regex && in_array( 'use', $regex ) ) {
$filter = new SourceRegex( $matches[
'pattern' ], 'source_text', 'source_text.trigram' );
if ( isset( $regex[ 'max_inspect' ] ) )
{
@@ -449,7 +447,7 @@
} else {
$filter->setMaxInspect( 10000 );
}
- $filter->setMaxDeterminizedStates(
$searcher->config->get( 'CirrusSearchRegexMaxDeterminizedStates' ) );
+ $filter->setMaxDeterminizedStates(
$this->config->get( 'CirrusSearchRegexMaxDeterminizedStates' ) );
if ( isset( $regex[
'max_ngrams_extracted' ] ) ) {
$filter->setMaxNgramExtracted(
$regex[ 'max_ngrams_extracted' ] );
}
@@ -485,7 +483,7 @@
array(
'pattern' => '.*(' .
$matches[ 'pattern' ] . ').*',
'insensitive' =>
$insensitive,
- 'language' =>
$searcher->config->get( 'LanguageCode' ),
+ 'language' =>
$this->config->get( 'LanguageCode' ),
// These null here
creates a slot in which the script will shove
// an automaton while
executing.
'automaton' => null,
@@ -498,12 +496,11 @@
);
// Match filters that look like foobar:thing or foobar:"thing
thing"
// The {7,15} keeps this from having horrible performance on
big strings
- $escaper = $this->escaper;
$fuzzyQuery = $this->fuzzyQuery;
$isEmptyQuery = false;
$this->extractSpecialSyntaxFromTerm(
'/(?<key>[a-z\\-]{7,15}):\s*(?<value>"(?<quoted>(?:[^"]|(?<=\\\)")+)"|(?<unquoted>\S+))
?/',
- function ( $matches ) use ( $searcher, $escaper,
&$filters, &$notFilters,
+ function ( $matches ) use ( &$filters, &$notFilters,
&$searchContainedSyntax, &$fuzzyQuery,
&$highlightSource, &$isEmptyQuery ) {
$key = $matches['key'];
$quotedValue = $matches['value'];
@@ -520,7 +517,7 @@
switch ( $key ) {
case 'boost-templates':
$boostTemplates =
Util::parseBoostTemplates( $value );
-
$searcher->getSearchContext()->setBoostTemplatesFromQuery( $boostTemplates );
+
$this->getSearchContext()->setBoostTemplatesFromQuery( $boostTemplates );
$searchContainedSyntax = true;
return '';
case 'hastemplate':
@@ -538,16 +535,16 @@
$title->getDBkey() )->getPrefixedText();
}
}
- $filterDestination[] =
$searcher->matchPage( 'template', $value );
+ $filterDestination[] =
$this->matchPage( 'template', $value );
$searchContainedSyntax = true;
return '';
case 'linksto':
- $filterDestination[] =
$searcher->matchPage( 'outgoing_link', $value, true );
+ $filterDestination[] =
$this->matchPage( 'outgoing_link', $value, true );
$searchContainedSyntax = true;
return '';
case 'incategory':
- $categories = array_slice(
explode( '|', $value ), 0, $searcher->config->get(
'CirrusSearchMaxIncategoryOptions' ) );
- $categoryFilters =
$searcher->matchPageCategories( $categories );
+ $categories = array_slice(
explode( '|', $value ), 0, $this->config->get(
'CirrusSearchMaxIncategoryOptions' ) );
+ $categoryFilters =
$this->matchPageCategories( $categories );
if ( $categoryFilters === null
) {
$isEmptyQuery = true;
} else {
@@ -556,11 +553,11 @@
$searchContainedSyntax = true;
return '';
case 'insource':
- $updateReferences =
Filters::insource( $escaper, $searcher->getSearchContext(), $quotedValue );
+ $updateReferences =
Filters::insource( $this->escaper, $this->getSearchContext(), $quotedValue );
$updateReferences( $fuzzyQuery,
$filterDestination, $highlightSource, $searchContainedSyntax );
return '';
case 'intitle':
- $updateReferences =
Filters::intitle( $escaper, $searcher->getSearchContext(), $quotedValue );
+ $updateReferences =
Filters::intitle( $this->escaper, $this->getSearchContext(), $quotedValue );
$updateReferences( $fuzzyQuery,
$filterDestination, $highlightSource, $searchContainedSyntax );
return $keepText ?
"$quotedValue " : '';
default:
@@ -586,9 +583,9 @@
// The following all match: "a", "a boat", "a\"boat", "a
boat"~, "a boat"~9, "a boat"~9~, -"a boat", -"a boat"~9~
$slop = $this->config->get('CirrusSearchPhraseSlop');
$query = self::replacePartsOfQuery( $this->term,
'/(?<![\]])(?<negate>-|!)?(?<main>"((?:[^"]|(?<=\\\)")+)"(?<slop>~\d+)?)(?<fuzzy>~)?/',
- function ( $matches ) use ( $searcher, $escaper, $slop
) {
+ function ( $matches ) use ( $slop ) {
$negate = $matches[ 'negate' ][ 0 ] ? 'NOT ' :
'';
- $main = $escaper->fixupQueryStringPart(
$matches[ 'main' ][ 0 ] );
+ $main = $this->escaper->fixupQueryStringPart(
$matches[ 'main' ][ 0 ] );
if ( !$negate && !isset( $matches[ 'fuzzy' ] )
&& !isset( $matches[ 'slop' ] ) &&
preg_match(
'/^"([^"*]+)[*]"/', $main, $matches ) ) {
@@ -613,8 +610,8 @@
// The highlighter locks phrases to the
fields that specify them. It doesn't do
// that with terms.
return array(
- 'escaped' => $negate .
$searcher->switchSearchToExact( $main, true ),
- 'nonAll' => $negate .
$searcher->switchSearchToExact( $main, false ),
+ 'escaped' => $negate .
$this->switchSearchToExact( $main, true ),
+ 'nonAll' => $negate .
$this->switchSearchToExact( $main, false ),
);
}
return array( 'escaped' => $negate . $main );
@@ -623,11 +620,11 @@
// prevents prefix matches from getting confused by stemming.
Users really don't expect stemming
// in prefix queries.
$query = self::replaceAllPartsOfQuery( $query,
'/\w+\*(?:\w*\*?)*/u',
- function ( $matches ) use ( $searcher, $escaper ) {
- $term = $escaper->fixupQueryStringPart(
$matches[ 0 ][ 0 ] );
+ function ( $matches ) {
+ $term = $this->escaper->fixupQueryStringPart(
$matches[ 0 ][ 0 ] );
return array(
- 'escaped' =>
$searcher->switchSearchToExactForWildcards( $term ),
- 'nonAll' =>
$searcher->switchSearchToExactForWildcards( $term )
+ 'escaped' =>
$this->switchSearchToExactForWildcards( $term ),
+ 'nonAll' =>
$this->switchSearchToExactForWildcards( $term )
);
} );
@@ -659,7 +656,7 @@
// Actual text query
list( $queryStringQueryString, $this->fuzzyQuery ) =
- $escaper->fixupWholeQueryString( implode( ' ',
$escapedQuery ) );
+ $this->escaper->fixupWholeQueryString( implode( ' ',
$escapedQuery ) );
// Note that no escaping is required for near_match's match
query.
$nearMatchQuery = implode( ' ', $nearMatchQuery );
if ( $queryStringQueryString !== '' ) {
@@ -682,7 +679,7 @@
$nonAllFields = array_merge(
$this->buildFullTextSearchFields( 1,
'.plain', false ),
$this->buildFullTextSearchFields(
$this->config->get( 'CirrusSearchStemmedWeight' ), '', false ) );
- list( $nonAllQueryString, /*_*/ ) =
$escaper->fixupWholeQueryString( implode( ' ', $nonAllQuery ) );
+ list( $nonAllQueryString, /*_*/ ) =
$this->escaper->fixupWholeQueryString( implode( ' ', $nonAllQuery ) );
$this->highlightQuery =
$this->buildSearchTextQueryForFields( $nonAllFields, $nonAllQueryString, 1,
false, true );
} else {
$nonAllFields = $fields;
@@ -884,33 +881,30 @@
*/
public function get( array $pageIds, $sourceFiltering ) {
$indexType = $this->pickIndexTypeFromNamespaces();
- $searcher = $this;
- $indexBaseName = $this->indexBaseName;
- $conn = $this->connection;
return Util::doPoolCounterWork(
'CirrusSearch-Search',
$this->user,
- function() use ( $searcher, $pageIds, $sourceFiltering,
$indexType, $indexBaseName, $conn ) {
+ function() use ( $pageIds, $sourceFiltering, $indexType
) {
try {
- $searcher->start( "get of
{indexType}.{pageIds}", array(
+ $this->start( "get of
{indexType}.{pageIds}", array(
'indexType' => $indexType,
'pageIds' => array_map(
'intval', $pageIds ),
'queryType' => 'get',
) );
// Shard timeout not supported on get
requests so we just use the client side timeout
- $conn->setTimeout(
$this->config->getElement( 'CirrusSearchClientSideSearchTimeout', 'default' ) );
- $pageType = $conn->getPageType(
$indexBaseName, $indexType );
+ $this->connection->setTimeout(
$this->config->getElement( 'CirrusSearchClientSideSearchTimeout', 'default' ) );
+ $pageType =
$this->connection->getPageType( $this->indexBaseName, $indexType );
$query = new \Elastica\Query( new
\Elastica\Query\Ids( null, $pageIds ) );
$query->setParam( '_source',
$sourceFiltering );
$query->addParam( 'stats', 'get' );
$resultSet = $pageType->search( $query,
array( 'search_type' => 'query_and_fetch' ) );
- return $searcher->success(
$resultSet->getResults() );
+ return $this->success(
$resultSet->getResults() );
} catch ( \Elastica\Exception\NotFoundException
$e ) {
// NotFoundException just means the
field didn't exist.
// It is up to the caller to decide if
that is an error.
- return $searcher->success( array() );
+ return $this->success( array() );
} catch (
\Elastica\Exception\ExceptionInterface $e ) {
- return $searcher->failure( $e );
+ return $this->failure( $e );
}
});
}
@@ -920,29 +914,26 @@
* @return Status
*/
public function findNamespace( $name ) {
- $searcher = $this;
- $indexBaseName = $this->indexBaseName;
- $conn = $this->connection;
return Util::doPoolCounterWork(
'CirrusSearch-NamespaceLookup',
$this->user,
- function() use ( $searcher, $name, $indexBaseName,
$conn ) {
+ function() use ( $name ) {
try {
- $searcher->start( "lookup namespace for
{namespaceName}", array(
+ $this->start( "lookup namespace for
{namespaceName}", array(
'namespaceName' => $name,
'query' => $name,
'queryType' => 'namespace',
) );
- $pageType = $conn->getNamespaceType(
$indexBaseName );
+ $pageType =
$this->connection->getNamespaceType( $this->indexBaseName );
$match = new \Elastica\Query\Match();
$match->setField( 'name', $name );
$query = new \Elastica\Query( $match );
$query->setParam( '_source', false );
$query->addParam( 'stats', 'namespace'
);
$resultSet = $pageType->search( $query,
array( 'search_type' => 'query_and_fetch' ) );
- return $searcher->success(
$resultSet->getResults() );
+ return $this->success(
$resultSet->getResults() );
} catch (
\Elastica\Exception\ExceptionInterface $e ) {
- return $searcher->failure( $e );
+ return $this->failure( $e );
}
});
}
@@ -952,18 +943,16 @@
* @param callable $callback
*/
private function extractSpecialSyntaxFromTerm( $regex, $callback ) {
- $suggestPrefixes = $this->suggestPrefixes;
$this->term = preg_replace_callback( $regex,
- function ( $matches ) use ( $callback,
&$suggestPrefixes ) {
+ function ( $matches ) use ( $callback ) {
$result = $callback( $matches );
if ( $result === '' ) {
- $suggestPrefixes[] = $matches[ 0 ];
+ $this->suggestPrefixes[] = $matches[ 0
];
}
return $result;
},
$this->term
);
- $this->suggestPrefixes = $suggestPrefixes;
}
/**
@@ -1202,20 +1191,18 @@
}
// Perform the search
- $searcher = $this;
- $user = $this->user;
$result = Util::doPoolCounterWork(
$poolCounterType,
$this->user,
- function() use ( $searcher, $search, $description,
$logContext ) {
+ function() use ( $search, $description, $logContext ) {
try {
- $searcher->start( $description,
$logContext );
- return $searcher->success(
$search->search() );
+ $this->start( $description, $logContext
);
+ return $this->success(
$search->search() );
} catch (
\Elastica\Exception\ExceptionInterface $e ) {
- return $searcher->failure( $e );
+ return $this->failure( $e );
}
},
- function( $error, $key, $userName ) use ( $type,
$description, $user, $logContext ) {
+ function( $error, $key, $userName ) use ( $type,
$description, $logContext ) {
$forUserName = $userName ? "for {userName} " :
'';
LoggerFactory::getInstance( 'CirrusSearch'
)->warning(
"Pool error {$forUserName}on key {key}
during $description: {error}",
@@ -1228,7 +1215,7 @@
if ( $error === 'pool-queuefull' ) {
if ( strpos( $key,
'nowait:CirrusSearch:_per_user' ) === 0 ) {
- $loggedIn = $user->isLoggedIn()
? 'logged-in' : 'anonymous';
+ $loggedIn =
$this->user->isLoggedIn() ? 'logged-in' : 'anonymous';
return Status::newFatal(
"cirrussearch-too-busy-for-you-{$loggedIn}-error" );
}
if ( $type === 'regex' ) {
diff --git a/maintenance/dumpIndex.php b/maintenance/dumpIndex.php
index 4d13f44..eaba8e9 100644
--- a/maintenance/dumpIndex.php
+++ b/maintenance/dumpIndex.php
@@ -157,18 +157,17 @@
$this->logToStderr = true;
$this->output( "Dumping $totalDocsToDump documents
($totalDocsInIndex in the index)\n" );
- $self = $this;
Util::iterateOverScroll( $index,
$result->getResponse()->getScrollId(), '15m',
- function( $results ) use ( $self, &$docsDumped,
$totalDocsToDump ) {
+ function( $results ) use ( &$docsDumped,
$totalDocsToDump ) {
foreach ( $results as $result ) {
$document = array(
'_id' => $result->getId(),
'_type' => $result->getType(),
'_source' =>
$result->getSource()
);
- $self->write( $document );
+ $this->write( $document );
$docsDumped++;
- $self->outputProgress( $docsDumped,
$totalDocsToDump );
+ $this->outputProgress( $docsDumped,
$totalDocsToDump );
}
}, $limit, 5 );
$this->output( "Dump done.\n" );
diff --git a/maintenance/updateSuggesterIndex.php
b/maintenance/updateSuggesterIndex.php
index f19033d..853dd9f 100644
--- a/maintenance/updateSuggesterIndex.php
+++ b/maintenance/updateSuggesterIndex.php
@@ -357,25 +357,22 @@
$totalDocsInIndex = $result->getResponse()->getData();
$totalDocsInIndex = $totalDocsInIndex['hits']['total'];
$totalDocsToDump = $totalDocsInIndex;
- $retryAttempts = $this->indexRetryAttempts;
$this->output( "Deleting remaining docs from previous batch
($totalDocsInIndex).\n" );
- $self = $this;
Util::iterateOverScroll( $this->getIndex(),
$result->getResponse()->getScrollId(), '15m',
- function( $results ) use ( $self, &$docsDumped,
$totalDocsToDump,
- $retryAttempts ) {
+ function( $results ) use ( &$docsDumped,
$totalDocsToDump ) {
$ids = array();
foreach( $results as $result ) {
$docsDumped++;
$ids[] = $result->getId();
}
- $self->outputProgress( $docsDumped,
$totalDocsToDump );
- Util::withRetry( $retryAttempts,
- function() use ( $ids, $self ) {
- $self->getType()->deleteIds(
$ids );
+ $this->outputProgress( $docsDumped,
$totalDocsToDump );
+ Util::withRetry( $this->indexRetryAttempts,
+ function() use ( $ids ) {
+ $this->getType()->deleteIds(
$ids );
}
);
- }, 0, $retryAttempts );
+ }, 0, $this->indexRetryAttempts );
$this->output( "Done.\n" );
// Old docs should be deleted now we can optimize and flush
$this->optimize();
@@ -459,29 +456,27 @@
$docsDumped = 0;
$this->output( "Indexing $totalDocsToDump documents
($totalDocsInIndex in the index) with batchId:
{$this->builder->getBatchId()}\n" );
- $self = $this;
$destinationType = $this->getIndex()->getType(
Connection::TITLE_SUGGEST_TYPE_NAME );
- $retryAttempts = $this->indexRetryAttempts;
Util::iterateOverScroll( $sourceIndex,
$result->getResponse()->getScrollId(), '15m',
- function( $results ) use ( $self, &$docsDumped,
$totalDocsToDump,
- $destinationType, $retryAttempts ) {
+ function( $results ) use ( &$docsDumped,
$totalDocsToDump,
+ $destinationType ) {
$suggestDocs = array();
foreach ( $results as $result ) {
$docsDumped++;
- $suggests = $self->builder->build(
$result->getId(), $result->getSource() );
+ $suggests = $this->builder->build(
$result->getId(), $result->getSource() );
foreach ( $suggests as $suggest ) {
$suggestDocs[] = $suggest;
}
}
- $self->outputProgress( $docsDumped,
$totalDocsToDump );
- Util::withRetry( $retryAttempts,
+ $this->outputProgress( $docsDumped,
$totalDocsToDump );
+ Util::withRetry( $this->indexRetryAttempts,
function() use ( $destinationType,
$suggestDocs ) {
$destinationType->addDocuments(
$suggestDocs );
}
);
- }, 0, $retryAttempts );
+ }, 0, $this->indexRetryAttempts );
$this->output( "Indexing done.\n" );
}
diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php
index 91d25e3..ee16331 100644
--- a/tests/unit/UtilTest.php
+++ b/tests/unit/UtilTest.php
@@ -248,11 +248,10 @@
throw new InvalidException();
}
};
- $self = $this;
$errorCallbackCalls = 0;
- Util::withRetry( 5, $func, function ($e, $errCount) use (
$self, &$errorCallbackCalls ) {
+ Util::withRetry( 5, $func, function ($e, $errCount) use (
&$errorCallbackCalls ) {
$errorCallbackCalls++;
- $self->assertEquals(
"Elastica\Exception\InvalidException", get_class( $e ) );
+ $this->assertEquals(
"Elastica\Exception\InvalidException", get_class( $e ) );
} );
$this->assertEquals( 6, $calls );
$this->assertEquals( 5, $errorCallbackCalls );
--
To view, visit https://gerrit.wikimedia.org/r/268304
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I171dce4e89b519eea31d4de69306726aeaac2633
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits