From 5ef437c2a228439c46d3eda1e1452578153f9ecf Mon Sep 17 00:00:00 2001 From: "d.savuljesku" Date: Fri, 15 Nov 2024 14:20:11 +0100 Subject: [PATCH] Allow running re-index commands on demand --- bootstrap.php | 2 +- src/Maintenance/PopulateCategoryIndex.php | 20 +++++++++++++++++--- src/Maintenance/PopulateTitleIndex.php | 21 ++++++++++++++++++--- src/Maintenance/PopulateUserIndex.php | 7 +++++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 5fce3af..218ca00 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -4,7 +4,7 @@ return; } -define( 'MWSTAKE_MEDIAWIKI_COMPONENT_COMMONWEBAPIS_VERSION', '2.0.28' ); +define( 'MWSTAKE_MEDIAWIKI_COMPONENT_COMMONWEBAPIS_VERSION', '2.0.29' ); MWStake\MediaWiki\ComponentLoader\Bootstrapper::getInstance() ->register( 'commonwebapis', static function () { diff --git a/src/Maintenance/PopulateCategoryIndex.php b/src/Maintenance/PopulateCategoryIndex.php index 33ba6b3..4a7c42b 100644 --- a/src/Maintenance/PopulateCategoryIndex.php +++ b/src/Maintenance/PopulateCategoryIndex.php @@ -4,12 +4,16 @@ use LoggedUpdateMaintenance; -class PopulateCategoryIndex extends \Maintenance { +$maintPath = dirname( __DIR__, 5 ) . '/maintenance/Maintenance.php'; +if ( file_exists( $maintPath ) ) { + require_once $maintPath; +} +class PopulateCategoryIndex extends \LoggedUpdateMaintenance { /** * @return bool */ - public function execute() { - $db = $this->getDB( DB_REPLICA ); + public function doDBUpdates() { + $db = $this->getDB( DB_PRIMARY ); $db->delete( 'mws_category_index', '*', __METHOD__ ); $links = $db->select( @@ -56,4 +60,14 @@ private function insertBatch( array $batch ) { [ 'IGNORE' ] ); } + + /** + * @return string + */ + protected function getUpdateKey() { + return 'mws-category-index-init'; + } } + +$maintClass = PopulateCategoryIndex::class; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/src/Maintenance/PopulateTitleIndex.php b/src/Maintenance/PopulateTitleIndex.php index e8fe74a..b5bd5ce 100644 --- a/src/Maintenance/PopulateTitleIndex.php +++ b/src/Maintenance/PopulateTitleIndex.php @@ -4,12 +4,17 @@ use MediaWiki\MediaWikiServices; -class PopulateTitleIndex extends \Maintenance { +$maintPath = dirname( __DIR__, 5 ) . '/maintenance/Maintenance.php'; +if ( file_exists( $maintPath ) ) { + require_once $maintPath; +} + +class PopulateTitleIndex extends \LoggedUpdateMaintenance { /** * @return bool */ - public function execute() { - $db = $this->getDB( DB_REPLICA ); + public function doDBUpdates() { + $db = $this->getDB( DB_PRIMARY ); $db->delete( 'mws_title_index', '*', __METHOD__ ); $titles = $db->select( @@ -58,4 +63,14 @@ private function insertBatch( array $batch ) { [ 'IGNORE' ] ); } + + /** + * @return string + */ + protected function getUpdateKey() { + return 'mws-title-index-init'; + } } + +$maintClass = PopulateTitleIndex::class; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/src/Maintenance/PopulateUserIndex.php b/src/Maintenance/PopulateUserIndex.php index e9bbe2b..967e2f5 100644 --- a/src/Maintenance/PopulateUserIndex.php +++ b/src/Maintenance/PopulateUserIndex.php @@ -2,6 +2,10 @@ namespace MWStake\MediaWiki\Component\CommonWebAPIs\Maintenance; +$maintPath = dirname( __DIR__, 5 ) . '/maintenance/Maintenance.php'; +if ( file_exists( $maintPath ) ) { + require_once $maintPath; +} class PopulateUserIndex extends \LoggedUpdateMaintenance { /** * @return bool @@ -62,3 +66,6 @@ protected function getUpdateKey() { return 'mws-user-index-init'; } } + +$maintClass = PopulateUserIndex::class; +require_once RUN_MAINTENANCE_IF_MAIN;