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

Change subject: Allow to explicitly index archive when given option.
......................................................................


Allow to explicitly index archive when given option.

Now it should work this way:
--deletes indexes deletes and if enabled by option, indexes archive too.
--archive indexes only archive regardless of the option.

This allows to pre-index deletes for a wiki before enabling it in config
(which requires mapping already being there).

Change-Id: I6bf8edc2fc91f8af03d2dfdfbe3dbdee73c03d4e
---
M includes/Updater.php
M maintenance/forceSearchIndex.php
2 files changed, 16 insertions(+), 11 deletions(-)

Approvals:
  EBernhardson: 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/Updater.php b/includes/Updater.php
index 8758245..ba8ba34 100644
--- a/includes/Updater.php
+++ b/includes/Updater.php
@@ -258,10 +258,11 @@
        /**
         * Add documents to archive index.
         * @param array $archived
+        * @param bool $forceIndex If true, index to archive regardless of 
config.
         * @return bool
         */
-       public function archivePages( $archived ) {
-               if ( !$this->searchConfig->getElement( 
'CirrusSearchIndexDeletes' ) ) {
+       public function archivePages( $archived, $forceIndex = false ) {
+               if ( !$this->searchConfig->getElement( 
'CirrusSearchIndexDeletes' ) && !$forceIndex ) {
                        // Disabled by config - don't do anything
                        return true;
                }
diff --git a/maintenance/forceSearchIndex.php b/maintenance/forceSearchIndex.php
index d53404f..dae8a9b 100644
--- a/maintenance/forceSearchIndex.php
+++ b/maintenance/forceSearchIndex.php
@@ -46,7 +46,7 @@
        public $toDate = null;
        public $toId = null;
        public $indexUpdates;
-       public $archiveOnly;
+       public $archive;
        public $limit;
        public $queue;
        public $maxJobs;
@@ -80,7 +80,7 @@
                $this->addOption( 'toId', 'Stop indexing at a specific page_id. 
 Not useful with --deletes or --from or --to.', false, true );
                $this->addOption( 'ids', 'List of page ids (comma separated) to 
reindex. Not allowed with deletes/from/to/fromId/toId/limit.', false, true );
                $this->addOption( 'deletes', 'If this is set then just index 
deletes, not updates or creates.', false );
-               $this->addOption( 'archiveOnly', 'Don\'t delete pages, only 
index them into the archive. Only useful with --deletes', false, false );
+               $this->addOption( 'archive', 'Don\'t delete pages, only index 
them into the archive.', false, false );
                $this->addOption( 'limit', 'Maximum number of pages to process 
before exiting the script. Default to unlimited.', false, true );
                $this->addOption( 'buildChunks', 'Instead of running the script 
spit out commands that can be farmed out to ' .
                        'different processes or machines to rebuild the index.  
Works with fromId and toId, not from and to.  ' .
@@ -130,7 +130,11 @@
                }
                $this->toId = $this->getOption( 'toId' );
                $this->indexUpdates = !$this->getOption( 'deletes', false );
-               $this->archiveOnly = (bool) $this->getOption( 'archiveOnly', 
false );
+               $this->archive = (bool) $this->getOption( 'archive', false );
+               if ( $this->archive ) {
+                       // If we're indexing only for archive, this implies 
deletes
+                       $this->indexUpdates = false;
+               }
                $this->limit = $this->getOption( 'limit' );
                $buildChunks = $this->getOption( 'buildChunks' );
                if ( $buildChunks !== null ) {
@@ -144,7 +148,7 @@
                $updateFlags = $this->buildUpdateFlags();
 
                if ( !$this->getOption( 'batch-size' ) &&
-                       ( $this->getOption( 'queue' ) || $this->getOption( 
'deletes' ) )
+                       ( $this->getOption( 'queue' ) || !$this->indexUpdates )
                ) {
                        $this->setBatchSize( 100 );
                }
@@ -159,7 +163,7 @@
 
                $operationName = $this->indexUpdates
                        ? ( $this->queue ? 'Queued' : 'Indexed' )
-                       : 'Deleted';
+                       : ( $this->archive ? 'Archived' : 'Deleted' );
 
                $operationStartTime = microtime( true );
                $completed = 0;
@@ -192,8 +196,8 @@
                        } else {
                                $size = count( $batch['titlesToDelete'] );
                                $updater = $this->createUpdater();
-                               $updater->archivePages( $batch['archive'] );
-                               if ( !$this->archiveOnly ) {
+                               $updater->archivePages( $batch['archive'], 
$this->archive );
+                               if ( !$this->archive ) {
                                        $updater->deletePages( 
$batch['titlesToDelete'], $batch['docIdsToDelete'] );
                                }
                        }
@@ -212,11 +216,11 @@
        }
 
        private function buildPageIdBatches() {
-               if ( $this->getOption( 'deletes' ) || $this->hasOption( 'limit' 
)
+               if ( !$this->indexUpdates || $this->hasOption( 'limit' )
                        || $this->hasOption( 'from' ) || $this->hasOption( 'to' 
)
                        || $this->hasOption( 'fromId' ) || $this->hasOption( 
'toId' )
                ) {
-                       $this->error( '--ids cannot be used with 
deletes/from/to/fromId/toId/limit', 1 );
+                       $this->error( '--ids cannot be used with 
deletes/archive/from/to/fromId/toId/limit', 1 );
                }
 
                $pageIds = array_map( function( $pageId ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6bf8edc2fc91f8af03d2dfdfbe3dbdee73c03d4e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <smalys...@wikimedia.org>
Gerrit-Reviewer: Cindy-the-browser-test-bot <bernhardsone...@gmail.com>
Gerrit-Reviewer: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org>
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