Skip to content

Commit

Permalink
Allow running re-index commands on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
it-spiderman committed Nov 15, 2024
1 parent ecb5d8b commit 5ef437c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
20 changes: 17 additions & 3 deletions src/Maintenance/PopulateCategoryIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
21 changes: 18 additions & 3 deletions src/Maintenance/PopulateTitleIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
7 changes: 7 additions & 0 deletions src/Maintenance/PopulateUserIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,3 +66,6 @@ protected function getUpdateKey() {
return 'mws-user-index-init';
}
}

$maintClass = PopulateUserIndex::class;
require_once RUN_MAINTENANCE_IF_MAIN;

0 comments on commit 5ef437c

Please sign in to comment.