Skip to content

Commit 43e63ce

Browse files
malbertsclaude
authored andcommitted
Don't crash rebuilding the graph on a wiki with no subjects
RebuildGraphDatabases looked up the numeric id of the subject slot role before querying for subject pages. On a wiki that has never stored a Subject, that role was never registered, so the lookup threw NameTableAccessException and the script aborted. Guard the lookup and treat a missing slot role as "no subject pages", mirroring the existing handling in DumpRdf and DatabaseDeletedSubjectPageIdsLookup. The rebuild now completes and reports zero pages instead of failing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c81ceab commit 43e63ce

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

maintenance/RebuildGraphDatabases.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use LogicException;
99
use Maintenance;
1010
use MediaWiki\MediaWikiServices;
11+
use MediaWiki\Storage\NameTableAccessException;
1112
use MediaWiki\Title\Title;
1213
use ProfessionalWiki\NeoWiki\Application\PageRefreshOutcome;
1314
use ProfessionalWiki\NeoWiki\Application\SubjectPageRebuilder;
@@ -145,7 +146,14 @@ private static function skipReason( PageRefreshOutcome $outcome ): string {
145146
*/
146147
private function getSubjectPageIds(): array {
147148
$services = MediaWikiServices::getInstance();
148-
$roleId = $services->getSlotRoleStore()->getId( MediaWikiSubjectRepository::SLOT_NAME );
149+
150+
try {
151+
$roleId = $services->getSlotRoleStore()->getId( MediaWikiSubjectRepository::SLOT_NAME );
152+
} catch ( NameTableAccessException ) {
153+
// No page has ever stored a Subject, so the slot role was never registered. There is
154+
// nothing to rebuild; report an empty run instead of crashing.
155+
return [];
156+
}
149157

150158
$rows = $this->getReplicaDB()->newSelectQueryBuilder()
151159
->select( 'page_id' )

tests/phpunit/Maintenance/RebuildGraphDatabasesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ protected function tearDown(): void {
3737
NeoWikiExtension::resetInstance();
3838
}
3939

40+
public function testRebuildSucceedsOnAWikiThatHasNeverStoredASubject(): void {
41+
// A wiki with no Subjects has never registered the 'neo' slot role, so the role-id lookup
42+
// throws NameTableAccessException. Forcing that state (empty table + a store without a warmed
43+
// cache) proves the rebuild treats it as an empty run instead of crashing.
44+
$this->truncateTable( 'slot_roles' );
45+
$this->getServiceContainer()->resetServiceForTesting( 'SlotRoleStore' );
46+
47+
$spy = new SpyGraphDatabasePlugin();
48+
$this->registerGraphDatabasePlugins( $spy );
49+
50+
$this->runRebuild();
51+
52+
$this->assertSame( [], $spy->savedPages, 'a wiki with no Subjects has nothing to project' );
53+
}
54+
4055
public function testRebuildRemovesADeletedSubjectPageFromTheGraph(): void {
4156
$this->createPageWithSubjects( 'Surviving page before', TestSubject::build() );
4257
$deleted = $this->createPageWithSubjects( 'Deleted during outage', TestSubject::build() );

0 commit comments

Comments
 (0)