EBernhardson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392469 )
Change subject: Add API action for dumping cirrus articles ...................................................................... Add API action for dumping cirrus articles This is particularly convenient for the browser tests to use, so they can ping the api to see if an article that it created/updated is now in cirrussearch. Change-Id: I5dbd02592eebb166362c7cb9dabcd2b93bae66c5 --- M CirrusSearch.php M autoload.php A includes/Api/ArticleDump.php M includes/Connection.php M tests/integration/features/step_definitions/page_step_helpers.js 5 files changed, 133 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/69/392469/1 diff --git a/CirrusSearch.php b/CirrusSearch.php index bf53382..b7a8682 100644 --- a/CirrusSearch.php +++ b/CirrusSearch.php @@ -1336,6 +1336,7 @@ $wgAPIModules['cirrus-config-dump'] = 'CirrusSearch\Api\ConfigDump'; $wgAPIModules['cirrus-mapping-dump'] = 'CirrusSearch\Api\MappingDump'; $wgAPIModules['cirrus-settings-dump'] = 'CirrusSearch\Api\SettingsDump'; +$wgAPIModules['cirrus-article-dump'] = 'CirrusSearch\Api\ArticleDump'; /** * Configs diff --git a/autoload.php b/autoload.php index 1cb17de..094cff9 100644 --- a/autoload.php +++ b/autoload.php @@ -6,6 +6,7 @@ $wgAutoloadClasses += [ 'CirrusSearch' => __DIR__ . '/includes/CirrusSearch.php', 'CirrusSearch\\Api\\ApiBase' => __DIR__ . '/includes/Api/ApiBase.php', + 'CirrusSearch\\Api\\ArticleDump' => __DIR__ . '/includes/Api/ArticleDump.php', 'CirrusSearch\\Api\\ConfigDump' => __DIR__ . '/includes/Api/ConfigDump.php', 'CirrusSearch\\Api\\FreezeWritesToCluster' => __DIR__ . '/includes/Api/FreezeWritesToCluster.php', 'CirrusSearch\\Api\\MappingDump' => __DIR__ . '/includes/Api/MappingDump.php', diff --git a/includes/Api/ArticleDump.php b/includes/Api/ArticleDump.php new file mode 100644 index 0000000..5840eb9 --- /dev/null +++ b/includes/Api/ArticleDump.php @@ -0,0 +1,93 @@ +<?php + +namespace CirrusSearch\Api; + +use CirrusSearch\Searcher; +use CirrusSearch\Updater; +use Title; + +/** + * Dumps CirrusSearch mappings for easy viewing. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + */ +class ArticleDump extends ApiBase { + public function execute() { + $conn = $this->getCirrusConnection(); + $config = $conn->getConfig(); + $searcher = new Searcher( $conn, 0, 0, $config, [], $this->getUser() ); + + $params = $this->extractRequestParams(); + $title = Title::newFromText( $params['title'] ); + if ( !$title->exists() ) { + $this->dieWithError( 'apierror-missingtitle' ); + } + + // Reuse updater to find the final target post-redirect + $updater = new Updater( $conn, $config ); + list( $page, $redirects ) = $updater->traceRedirects( $title ); + + if ( !$page ) { + // Slight lie .. the title itself exists but not the redirect target. + // Use custom error message? + $this->dieWithError( 'apierror-missingtitle' ); + } + + $docId = $config->makeId( $page->getId() ); + $esSources = $searcher->get( [ $docId ], true ); + $result = []; + if ( $esSources->isOK() ) { + foreach ( $esSources->getValue() as $i => $esSource ) { + $result[] = [ + 'index' => $esSource->getIndex(), + 'type' => $esSource->getType(), + 'id' => $esSource->getId(), + 'version' => $esSource->getVersion(), + 'source' => $esSource->getData(), + ]; + } + } + $this->getResult()->addValue( null, 'cirrus-article-dump', $result ); + } + + public function getAllowedParams() { + return [ + 'title' => [ + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => true, + ], + ]; + } + + /** + * @deprecated since MediaWiki core 1.25 + */ + public function getDescription() { + return 'Dump stored CirrusSearch document for article.'; + } + + /** + * @see ApiBase::getExamplesMessages + * @return array + */ + protected function getExamplesMessages() { + return [ + 'action=cirrus-article-dump' => + 'apihelp-cirrus-article-dump-example' + ]; + } + +} diff --git a/includes/Connection.php b/includes/Connection.php index a17ce88..8e2e389 100644 --- a/includes/Connection.php +++ b/includes/Connection.php @@ -138,6 +138,13 @@ } /** + * @return SearchConfig + */ + public function getConfig() { + return $this->config; + } + + /** * @return string */ public function getClusterName() { diff --git a/tests/integration/features/step_definitions/page_step_helpers.js b/tests/integration/features/step_definitions/page_step_helpers.js index a67761e..fbcff9d 100644 --- a/tests/integration/features/step_definitions/page_step_helpers.js +++ b/tests/integration/features/step_definitions/page_step_helpers.js @@ -12,7 +12,8 @@ const expect = require( 'chai' ).expect, fs = require( 'fs' ), - path = require( 'path' ); + path = require( 'path' ), + Promise = require( 'bluebird' ); class StepHelpers { constructor( world, wiki ) { @@ -110,6 +111,35 @@ ( response ) => this.world.setApiResponse( response ), ( error ) => this.world.setApiError( error ) ); } + + waitForOperation( operation, title ) { + return Promise.coroutine( function* () { + let expect = operation === 'delete' ? false : true; + let exists; + do { + exists = yield this.checkExists( title ); + } while ( expect !== exists ); + } ).call( this ); + } + + checkExists( title ) { + return Promise.coroutine( function* () { + let client = yield this.apiPromise; + try { + let response = yield client.request( { + action: 'cirrus-article-dump', + title: title + } ); + return response['cirrus-article-dump'].length > 0; + } catch ( err ) { + if ( err.code === 'missingtitle' ) { + return false; + } + console.log( err ); + throw err; + } + } ).call( this ); + } } module.exports = StepHelpers; -- To view, visit https://gerrit.wikimedia.org/r/392469 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5dbd02592eebb166362c7cb9dabcd2b93bae66c5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits