Skip to content

Commit b164a23

Browse files
committed
fix RebuildQueryserviceData
1 parent eada312 commit b164a23

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

app/Console/Commands/RebuildQueryserviceData.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Constants\MediawikiNamespace;
66
use App\Jobs\SpawnQueryserviceUpdaterJob;
7+
use App\Services\MediaWikiHostResolver;
78
use App\QueryserviceNamespace;
89
use App\Traits;
910
use App\Wiki;
@@ -25,7 +26,7 @@ class RebuildQueryserviceData extends Command {
2526

2627
protected string $queueName;
2728

28-
public function handle() {
29+
public function handle(MediaWikiHostResolver $mwHostResolver) {
2930
$this->chunkSize = intval($this->option('chunkSize'));
3031
$this->sparqlUrlFormat = $this->option('sparqlUrlFormat');
3132
$this->queueName = $this->option('queueName');
@@ -41,6 +42,8 @@ public function handle() {
4142
$skippedWikis = 0;
4243
$processedWikis = 0;
4344
foreach ($wikis as $wiki) {
45+
$this->apiUrl = $mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace
46+
4447
try {
4548
$entities = $this->getEntitiesForWiki($wiki);
4649
$sparqlUrl = $this->getSparqlUrl($wiki);

tests/Commands/RebuildQueryserviceDataTest.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Constants\MediawikiNamespace;
66
use App\Jobs\SpawnQueryserviceUpdaterJob;
7+
use App\Services\MediaWikiHostResolver;
78
use App\QueryserviceNamespace;
89
use App\Wiki;
910
use App\WikiSetting;
@@ -16,11 +17,22 @@
1617
class RebuildQueryserviceDataTest extends TestCase {
1718
use DatabaseTransactions;
1819

20+
private $mwBackendHost;
21+
1922
protected function setUp(): void {
2023
parent::setUp();
2124
Wiki::query()->delete();
2225
WikiSetting::query()->delete();
2326
QueryserviceNamespace::query()->delete();
27+
28+
$this->mwBackendHost = 'mediawiki.localhost';
29+
30+
$mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
31+
$mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
32+
$this->mwBackendHost
33+
);
34+
35+
$this->app->instance(MediaWikiHostResolver::class, $mockMwHostResolver);
2436
}
2537

2638
protected function tearDown(): void {
@@ -55,7 +67,7 @@ public function testWikiWithLexemes() {
5567
]);
5668

5769
Http::fake([
58-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
70+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
5971
'query' => [
6072
'allpages' => [
6173
[
@@ -73,7 +85,7 @@ public function testWikiWithLexemes() {
7385
],
7486
],
7587
], 200),
76-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
88+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
7789
'continue' => [
7890
'apcontinue' => 'Q6',
7991
],
@@ -102,7 +114,7 @@ public function testWikiWithLexemes() {
102114
],
103115
],
104116
], 200),
105-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
117+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
106118
'query' => [
107119
'allpages' => [
108120
[
@@ -124,7 +136,7 @@ public function testWikiWithLexemes() {
124136
],
125137
],
126138
], 200),
127-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
139+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
128140
'query' => [
129141
'allpages' => [
130142
[
@@ -185,7 +197,7 @@ public function testWikiNoLexemes() {
185197
]);
186198

187199
Http::fake([
188-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
200+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
189201
'query' => [
190202
'allpages' => [
191203
[
@@ -203,7 +215,7 @@ public function testWikiNoLexemes() {
203215
],
204216
],
205217
], 200),
206-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
218+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
207219
'query' => [
208220
'allpages' => [
209221
[
@@ -229,7 +241,7 @@ public function testWikiNoLexemes() {
229241
],
230242
],
231243
], 200),
232-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
244+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
233245
'error' => 'Lexemes not enabled for this wiki',
234246
], 400),
235247
]);
@@ -261,7 +273,7 @@ public function testFailure() {
261273
]);
262274

263275
Http::fake([
264-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
276+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
265277
'query' => [
266278
'allpages' => [
267279
[
@@ -279,10 +291,10 @@ public function testFailure() {
279291
],
280292
],
281293
], 200),
282-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
294+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
283295
'error' => 'THE DINOSAURS ESCAPED!',
284296
], 500),
285-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
297+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
286298
'error' => 'Lexemes not enabled for this wiki',
287299
], 400),
288300
]);
@@ -301,17 +313,17 @@ public function testEmptyWiki() {
301313
]);
302314

303315
Http::fake([
304-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
316+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
305317
'query' => [
306318
'allpages' => [],
307319
],
308320
], 200),
309-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
321+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
310322
'query' => [
311323
'allpages' => [],
312324
],
313325
], 200),
314-
getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
326+
$this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
315327
'error' => 'Lexemes not enabled for this wiki',
316328
], 400),
317329
]);

0 commit comments

Comments
 (0)