From 0d8a250722a019dc6c905fa0a0cdcd42fda8d8c3 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:38:37 +0100 Subject: [PATCH 01/45] remove obsolete apiUrl assignment --- app/Console/Commands/RebuildQueryserviceData.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php index 1f1ac79ab..46bf921a2 100644 --- a/app/Console/Commands/RebuildQueryserviceData.php +++ b/app/Console/Commands/RebuildQueryserviceData.php @@ -29,7 +29,6 @@ public function handle() { $this->chunkSize = intval($this->option('chunkSize')); $this->sparqlUrlFormat = $this->option('sparqlUrlFormat'); $this->queueName = $this->option('queueName'); - $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php'; $wikiDomains = $this->option('domain'); $exitCode = 0; From ee34067cf9db089b1a37510c6cf728355782c69f Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:39:28 +0100 Subject: [PATCH 02/45] refactor MediawikiInit Job --- app/Jobs/MediawikiInit.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Jobs/MediawikiInit.php b/app/Jobs/MediawikiInit.php index 9fd6b5123..364986c7f 100644 --- a/app/Jobs/MediawikiInit.php +++ b/app/Jobs/MediawikiInit.php @@ -3,6 +3,7 @@ namespace App\Jobs; use App\Http\Curl\HttpRequest; +use App\Services\MediaWikiHostResolver; class MediawikiInit extends Job { private $wikiDomain; @@ -23,14 +24,16 @@ public function __construct($wikiDomain, $username, $email) { /** * @return void */ - public function handle(HttpRequest $request) { + public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) { $data = [ 'username' => $this->username, 'email' => $this->email, ]; + $mwHost = $mwHostResolver->getMwVersionForDomain($this->wikiDomain); + $request->setOptions([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackInit&format=json', + CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackInit&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60, From ab06aaf9f0040cc5b3d6943c170efe5358bec8a8 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:43:25 +0100 Subject: [PATCH 03/45] refactor MediawikiSandboxLoadData --- app/Jobs/MediawikiSandboxLoadData.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Jobs/MediawikiSandboxLoadData.php b/app/Jobs/MediawikiSandboxLoadData.php index ace75498b..c0d4c3a4b 100644 --- a/app/Jobs/MediawikiSandboxLoadData.php +++ b/app/Jobs/MediawikiSandboxLoadData.php @@ -2,6 +2,8 @@ namespace App\Jobs; +use App\Services\MediaWikiHostResolver; + class MediawikiSandboxLoadData extends Job { private $wikiDomain; @@ -18,14 +20,16 @@ public function __construct($wikiDomain, $dataSet) { /** * @return void */ - public function handle() { + public function handle(MediaWikiHostResolver $mwHostResolver) { $data = [ 'dataSet' => $this->dataSet, ]; + $mwHost = $mwHostResolver->getMwVersionForDomain($this->wikiDomain); + $curl = curl_init(); curl_setopt_array($curl, [ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/rest.php/wikibase-exampledata/v0/load', + CURLOPT_URL => $mwHost . '/w/rest.php/wikibase-exampledata/v0/load', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 10 * 60, // TODO Long 10 mins (probably shouldn't keep the request open...) From 335c75637f130f3124222bdde476bf9e3965527b Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:48:49 +0100 Subject: [PATCH 04/45] refactor CirrusSearchJob --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index 8e86dabac..c3cd663c4 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -6,6 +6,7 @@ use App\Jobs\Job; use App\Wiki; use App\WikiSetting; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\ShouldBeUnique; abstract class CirrusSearchJob extends Job implements ShouldBeUnique { @@ -41,7 +42,7 @@ public function wikiId(): int { /** * @return void */ - public function handle(HttpRequest $request) { + public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) { $this->wiki = Wiki::whereId($this->wikiId)->with('settings')->with('wikiDb')->first(); // job got triggered but no wiki @@ -67,9 +68,11 @@ public function handle(HttpRequest $request) { return; } + $mwHost = $mwHostResolver->getMwVersionForDomain($this->wiki->domain); + $request->setOptions( [ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), + CURLOPT_URL => $mwHost . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => $this->getRequestTimeout(), From 76d63bec5c8c84d0124b941bd16761e2f0788969 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:50:38 +0100 Subject: [PATCH 05/45] refactor SiteStatsUpdateJob --- app/Jobs/SiteStatsUpdateJob.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php index 118e35d32..185d4beff 100644 --- a/app/Jobs/SiteStatsUpdateJob.php +++ b/app/Jobs/SiteStatsUpdateJob.php @@ -4,6 +4,7 @@ use App\Http\Curl\HttpRequest; use App\Wiki; +use App\Services\MediaWikiHostResolver; use Illuminate\Bus\Batchable; use Illuminate\Support\Facades\Log; @@ -22,7 +23,7 @@ public function __construct($wiki_id) { $this->wiki_id = $wiki_id; } - public function handle(HttpRequest $request): void { + public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver): void { $timeStart = microtime(true); $wiki = Wiki::where('id', $this->wiki_id)->first(); @@ -30,10 +31,12 @@ public function handle(HttpRequest $request): void { $this->fail(new \RuntimeException(" Could not find wiki with id: $this->wiki_id")); } - Log::info(__METHOD__ . ": Updating stats for or $wiki->domain"); + Log::info(__METHOD__ . ": Updating stats for $wiki->domain"); + + $mwHost = $mwHostResolver->getMwVersionForDomain($wiki->domain); $request->setOptions([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', + CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60 * 5, From e8d89a11396d60b5db679b8cf2af3c7bc3ae77f2 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 15:58:22 +0100 Subject: [PATCH 06/45] Revert "remove obsolete apiUrl assignment" This reverts commit f8635db8f277dd06e27074fbf45548da5680d352. --- app/Console/Commands/RebuildQueryserviceData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php index 46bf921a2..1f1ac79ab 100644 --- a/app/Console/Commands/RebuildQueryserviceData.php +++ b/app/Console/Commands/RebuildQueryserviceData.php @@ -29,6 +29,7 @@ public function handle() { $this->chunkSize = intval($this->option('chunkSize')); $this->sparqlUrlFormat = $this->option('sparqlUrlFormat'); $this->queueName = $this->option('queueName'); + $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php'; $wikiDomains = $this->option('domain'); $exitCode = 0; From 41e2db260ce2e08cbea810f39613cab0dad15ae0 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:02:09 +0100 Subject: [PATCH 07/45] refactor PageFetcher and its uses --- app/Console/Commands/RebuildQueryserviceData.php | 1 - app/Jobs/PlatformStatsSummaryJob.php | 1 - app/Traits/PageFetcher.php | 10 ++++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php index 1f1ac79ab..46bf921a2 100644 --- a/app/Console/Commands/RebuildQueryserviceData.php +++ b/app/Console/Commands/RebuildQueryserviceData.php @@ -29,7 +29,6 @@ public function handle() { $this->chunkSize = intval($this->option('chunkSize')); $this->sparqlUrlFormat = $this->option('sparqlUrlFormat'); $this->queueName = $this->option('queueName'); - $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php'; $wikiDomains = $this->option('domain'); $exitCode = 0; diff --git a/app/Jobs/PlatformStatsSummaryJob.php b/app/Jobs/PlatformStatsSummaryJob.php index d882e6159..5df37ae0a 100644 --- a/app/Jobs/PlatformStatsSummaryJob.php +++ b/app/Jobs/PlatformStatsSummaryJob.php @@ -42,7 +42,6 @@ class PlatformStatsSummaryJob extends Job { public function __construct() { $this->inactiveThreshold = Config::get('wbstack.platform_summary_inactive_threshold'); $this->creationRateRanges = Config::get('wbstack.platform_summary_creation_rate_ranges'); - $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php'; } private function isNullOrEmpty($value): bool { diff --git a/app/Traits/PageFetcher.php b/app/Traits/PageFetcher.php index 09bc04e97..4584e09ce 100644 --- a/app/Traits/PageFetcher.php +++ b/app/Traits/PageFetcher.php @@ -3,16 +3,14 @@ namespace App\Traits; use App\Constants\MediawikiNamespace; +use App\Services\MediaWikiHostResolver; use Illuminate\Support\Facades\Http; trait PageFetcher { - private string $apiUrl; - // this function is used to fetch pages on namespace public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $namespace): array { - if (empty($this->apiUrl)) { - throw new \RuntimeException('API URL has not been set.'); - } + $mwHostResolver = new MediaWikiHostResolver; + $apiUrl = $mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php'; $titles = []; $cursor = ''; @@ -20,7 +18,7 @@ public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $na $response = Http::withHeaders([ 'host' => $wikiDomain, ])->get( - $this->apiUrl, + $apiUrl, [ 'action' => 'query', 'list' => 'allpages', From 6a2b3705f27908883b7d5eab28093493df29a8b5 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:09:11 +0100 Subject: [PATCH 08/45] refactor PollForMediaWikiJobsJob --- app/Jobs/PollForMediaWikiJobsJob.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Jobs/PollForMediaWikiJobsJob.php b/app/Jobs/PollForMediaWikiJobsJob.php index 91b00cae4..ce6fa60e0 100644 --- a/app/Jobs/PollForMediaWikiJobsJob.php +++ b/app/Jobs/PollForMediaWikiJobsJob.php @@ -3,14 +3,21 @@ namespace App\Jobs; use App\Wiki; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class PollForMediaWikiJobsJob extends Job implements ShouldBeUnique, ShouldQueue { + private MediaWikiHostResolver $mwHostResolver; + public $timeout = 1800; + public function __construct(MediaWikiHostResolver $mwHostResolver = null) { + $this->mwHostResolver = $mwHostResolver ?? new MediaWikiHostResolver(); + } + public function handle(): void { $allWikiDomains = Wiki::all()->pluck('domain'); foreach ($allWikiDomains as $wikiDomain) { @@ -24,7 +31,7 @@ private function hasPendingJobs(string $wikiDomain): bool { $response = Http::withHeaders([ 'host' => $wikiDomain, ])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' + $this->mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' ); if ($response->failed()) { From e7fa35d7692dc9ce44d98ac85afb33b6b1d21220 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:15:16 +0100 Subject: [PATCH 09/45] refactor WikiEntityImportJob --- app/Jobs/WikiEntityImportJob.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index 6b0af4736..6587736af 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -5,6 +5,7 @@ use App\Wiki; use App\WikiEntityImport; use App\WikiEntityImportStatus; +use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -20,6 +21,8 @@ class WikiEntityImportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + private MediaWikiHostResolver $mwHostResolver; + /** * Create a new job instance. */ @@ -28,6 +31,7 @@ public function __construct( public string $sourceWikiUrl, public array $entityIds, public int $importId, + private MediaWikiHostResolver $mwHostResolver ) {} private string $targetWikiUrl; @@ -79,7 +83,7 @@ private static function domainToOrigin(string $domain): string { private static function acquireCredentials(string $wikiDomain): OAuthCredentials { $response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackPlatformOauthGet&format=json', + $this->mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', [ 'consumerName' => 'WikiEntityImportJob', 'ownerOnly' => '1', From 7b212474b43053359175ff431ac9fa8277db620b Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:25:19 +0100 Subject: [PATCH 10/45] refactor UpdateWikiSiteStatsJob --- app/Jobs/UpdateWikiSiteStatsJob.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index 04e5368b1..eba41d627 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -4,6 +4,7 @@ use App\Wiki; use App\WikiSiteStats; +use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Contracts\Queue\ShouldBeUnique; @@ -17,6 +18,10 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique { public $timeout = 3600; + public function __construct( + private MediaWikiHostResolver $mwHostResolver + ) {} + public function handle(): void { $allWikis = Wiki::all(); foreach ($allWikis as $wiki) { @@ -54,7 +59,7 @@ private function updateSiteStats(Wiki $wiki): void { $response = Http::withHeaders([ 'host' => $wiki->getAttribute('domain'), ])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' ); if ($response->failed()) { @@ -76,7 +81,7 @@ private function updateSiteStats(Wiki $wiki): void { private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -94,7 +99,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -114,7 +119,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -132,7 +137,7 @@ private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', From 432d652370ede5cf32fe772a6601cf394386db93 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:25:30 +0100 Subject: [PATCH 11/45] fix copypasta --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 2 +- app/Jobs/MediawikiInit.php | 2 +- app/Jobs/MediawikiSandboxLoadData.php | 2 +- app/Jobs/PollForMediaWikiJobsJob.php | 2 +- app/Jobs/SiteStatsUpdateJob.php | 2 +- app/Jobs/WikiEntityImportJob.php | 4 +--- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index c3cd663c4..d3a430600 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -68,7 +68,7 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv return; } - $mwHost = $mwHostResolver->getMwVersionForDomain($this->wiki->domain); + $mwHost = $mwHostResolver->getBackendHostForDomain($this->wiki->domain); $request->setOptions( [ diff --git a/app/Jobs/MediawikiInit.php b/app/Jobs/MediawikiInit.php index 364986c7f..3a2bad142 100644 --- a/app/Jobs/MediawikiInit.php +++ b/app/Jobs/MediawikiInit.php @@ -30,7 +30,7 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv 'email' => $this->email, ]; - $mwHost = $mwHostResolver->getMwVersionForDomain($this->wikiDomain); + $mwHost = $mwHostResolver->getBackendHostForDomain($this->wikiDomain); $request->setOptions([ CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackInit&format=json', diff --git a/app/Jobs/MediawikiSandboxLoadData.php b/app/Jobs/MediawikiSandboxLoadData.php index c0d4c3a4b..8d95540ef 100644 --- a/app/Jobs/MediawikiSandboxLoadData.php +++ b/app/Jobs/MediawikiSandboxLoadData.php @@ -25,7 +25,7 @@ public function handle(MediaWikiHostResolver $mwHostResolver) { 'dataSet' => $this->dataSet, ]; - $mwHost = $mwHostResolver->getMwVersionForDomain($this->wikiDomain); + $mwHost = $mwHostResolver->getBackendHostForDomain($this->wikiDomain); $curl = curl_init(); curl_setopt_array($curl, [ diff --git a/app/Jobs/PollForMediaWikiJobsJob.php b/app/Jobs/PollForMediaWikiJobsJob.php index ce6fa60e0..654696a11 100644 --- a/app/Jobs/PollForMediaWikiJobsJob.php +++ b/app/Jobs/PollForMediaWikiJobsJob.php @@ -31,7 +31,7 @@ private function hasPendingJobs(string $wikiDomain): bool { $response = Http::withHeaders([ 'host' => $wikiDomain, ])->get( - $this->mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' + $this->mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' ); if ($response->failed()) { diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php index 185d4beff..0f10d74f1 100644 --- a/app/Jobs/SiteStatsUpdateJob.php +++ b/app/Jobs/SiteStatsUpdateJob.php @@ -33,7 +33,7 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv Log::info(__METHOD__ . ": Updating stats for $wiki->domain"); - $mwHost = $mwHostResolver->getMwVersionForDomain($wiki->domain); + $mwHost = $mwHostResolver->getBackendHostForDomain($wiki->domain); $request->setOptions([ CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index 6587736af..bf3959dda 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -21,8 +21,6 @@ class WikiEntityImportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - private MediaWikiHostResolver $mwHostResolver; - /** * Create a new job instance. */ @@ -83,7 +81,7 @@ private static function domainToOrigin(string $domain): string { private static function acquireCredentials(string $wikiDomain): OAuthCredentials { $response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post( - $this->mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', + $this->mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', [ 'consumerName' => 'WikiEntityImportJob', 'ownerOnly' => '1', From ad2ac558816a8d25eddca676cd8991a6fb0ae659 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:31:29 +0100 Subject: [PATCH 12/45] add Wiki::getBackendHost --- app/Wiki.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Wiki.php b/app/Wiki.php index 109c55881..c35a5a7c7 100644 --- a/app/Wiki.php +++ b/app/Wiki.php @@ -3,6 +3,7 @@ namespace App; use App\Helper\DomainHelper; +use App\Services\MediaWikiHostResolver; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -159,4 +160,11 @@ public function getDomainDecodedAttribute(): string { public function wikiLatestProfile() { return $this->hasOne(WikiProfile::class)->latestOfMany(); } + + /** + * Retrieve correct backend host for the mediawiki version of this wiki + */ + public function getBackendHost() { + return (new MediaWikiHostResolver)->getBackendHostForDomain($this->domain); + } } From ced73c8f745949d075449e419fc2f9417efc5b5d Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:31:38 +0100 Subject: [PATCH 13/45] use Wiki::getBackendHost in UpdateWikiSiteStatsJob --- app/Jobs/UpdateWikiSiteStatsJob.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index eba41d627..1d230a69f 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -4,7 +4,6 @@ use App\Wiki; use App\WikiSiteStats; -use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Contracts\Queue\ShouldBeUnique; @@ -18,10 +17,6 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique { public $timeout = 3600; - public function __construct( - private MediaWikiHostResolver $mwHostResolver - ) {} - public function handle(): void { $allWikis = Wiki::all(); foreach ($allWikis as $wiki) { @@ -59,7 +54,7 @@ private function updateSiteStats(Wiki $wiki): void { $response = Http::withHeaders([ 'host' => $wiki->getAttribute('domain'), ])->get( - $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' + $wiki->getBackendHost() . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' ); if ($response->failed()) { @@ -81,7 +76,7 @@ private function updateSiteStats(Wiki $wiki): void { private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', + $wiki->getBackendHost() . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -99,7 +94,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', + $wiki->getBackendHost() . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -119,7 +114,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', + $wiki->getBackendHost() . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -137,7 +132,7 @@ private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', + $wiki->getBackendHost() . '/w/api.php', [ 'action' => 'query', 'format' => 'json', From 72ca100b4d5bd257c3b3e46ef48c1850a7cd3465 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:34:42 +0100 Subject: [PATCH 14/45] refactor CirrusSearchJob --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index d3a430600..929debdad 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -6,7 +6,6 @@ use App\Jobs\Job; use App\Wiki; use App\WikiSetting; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\ShouldBeUnique; abstract class CirrusSearchJob extends Job implements ShouldBeUnique { @@ -42,7 +41,7 @@ public function wikiId(): int { /** * @return void */ - public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) { + public function handle(HttpRequest $request) { $this->wiki = Wiki::whereId($this->wikiId)->with('settings')->with('wikiDb')->first(); // job got triggered but no wiki @@ -68,11 +67,9 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv return; } - $mwHost = $mwHostResolver->getBackendHostForDomain($this->wiki->domain); - $request->setOptions( [ - CURLOPT_URL => $mwHost . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), + CURLOPT_URL => $this->wiki->getBackendHost() . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => $this->getRequestTimeout(), From a3788e256fe0c09d1dce7b97c752c613fb9e68f4 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:37:06 +0100 Subject: [PATCH 15/45] update SiteStatsUpdateJob --- app/Jobs/SiteStatsUpdateJob.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php index 0f10d74f1..c815d0f47 100644 --- a/app/Jobs/SiteStatsUpdateJob.php +++ b/app/Jobs/SiteStatsUpdateJob.php @@ -4,7 +4,6 @@ use App\Http\Curl\HttpRequest; use App\Wiki; -use App\Services\MediaWikiHostResolver; use Illuminate\Bus\Batchable; use Illuminate\Support\Facades\Log; @@ -23,7 +22,7 @@ public function __construct($wiki_id) { $this->wiki_id = $wiki_id; } - public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver): void { + public function handle(HttpRequest $request): void { $timeStart = microtime(true); $wiki = Wiki::where('id', $this->wiki_id)->first(); @@ -33,10 +32,8 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv Log::info(__METHOD__ . ": Updating stats for $wiki->domain"); - $mwHost = $mwHostResolver->getBackendHostForDomain($wiki->domain); - $request->setOptions([ - CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', + CURLOPT_URL => $wiki->getBackendHost() . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60 * 5, From 4c3765cc7f516d71541ca4da4924404a1ceecb71 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 16:59:15 +0100 Subject: [PATCH 16/45] attempt to fix wikiEntityImportJob --- app/Jobs/WikiEntityImportJob.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index bf3959dda..7eb594e9d 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -21,6 +21,8 @@ class WikiEntityImportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + private MediaWikiHostResolver $mwHostResolver + /** * Create a new job instance. */ @@ -28,9 +30,10 @@ public function __construct( public int $wikiId, public string $sourceWikiUrl, public array $entityIds, - public int $importId, - private MediaWikiHostResolver $mwHostResolver - ) {} + public int $importId + ) { + $this->mwHostResolver = new MediaWikiHostResolver; + } private string $targetWikiUrl; From b0246ad5037320ecaaed0f8442258eb22a965780 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 17:13:25 +0100 Subject: [PATCH 17/45] remove Wiki::getBackendHost() --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 5 +++-- app/Jobs/SiteStatsUpdateJob.php | 5 +++-- app/Jobs/UpdateWikiSiteStatsJob.php | 17 ++++++++++++----- app/Wiki.php | 10 +--------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index 929debdad..41af2df63 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -6,6 +6,7 @@ use App\Jobs\Job; use App\Wiki; use App\WikiSetting; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\ShouldBeUnique; abstract class CirrusSearchJob extends Job implements ShouldBeUnique { @@ -41,7 +42,7 @@ public function wikiId(): int { /** * @return void */ - public function handle(HttpRequest $request) { + public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) { $this->wiki = Wiki::whereId($this->wikiId)->with('settings')->with('wikiDb')->first(); // job got triggered but no wiki @@ -69,7 +70,7 @@ public function handle(HttpRequest $request) { $request->setOptions( [ - CURLOPT_URL => $this->wiki->getBackendHost() . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), + CURLOPT_URL => $this->mwHostResolver->getBackendHostForDomain($this->wiki->domain); . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => $this->getRequestTimeout(), diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php index c815d0f47..de8efe967 100644 --- a/app/Jobs/SiteStatsUpdateJob.php +++ b/app/Jobs/SiteStatsUpdateJob.php @@ -4,6 +4,7 @@ use App\Http\Curl\HttpRequest; use App\Wiki; +use App\Services\MediaWikiHostResolver; use Illuminate\Bus\Batchable; use Illuminate\Support\Facades\Log; @@ -22,7 +23,7 @@ public function __construct($wiki_id) { $this->wiki_id = $wiki_id; } - public function handle(HttpRequest $request): void { + public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver): void { $timeStart = microtime(true); $wiki = Wiki::where('id', $this->wiki_id)->first(); @@ -33,7 +34,7 @@ public function handle(HttpRequest $request): void { Log::info(__METHOD__ . ": Updating stats for $wiki->domain"); $request->setOptions([ - CURLOPT_URL => $wiki->getBackendHost() . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', + CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60 * 5, diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index 1d230a69f..6e6cd913f 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -4,6 +4,7 @@ use App\Wiki; use App\WikiSiteStats; +use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Contracts\Queue\ShouldBeUnique; @@ -17,6 +18,12 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique { public $timeout = 3600; + private MediaWikiHostResolver $mwHostResolver; + + public __construct() { + $this->mwHostResolver = new MediaWikiHostResolver; + } + public function handle(): void { $allWikis = Wiki::all(); foreach ($allWikis as $wiki) { @@ -54,7 +61,7 @@ private function updateSiteStats(Wiki $wiki): void { $response = Http::withHeaders([ 'host' => $wiki->getAttribute('domain'), ])->get( - $wiki->getBackendHost() . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' ); if ($response->failed()) { @@ -76,7 +83,7 @@ private function updateSiteStats(Wiki $wiki): void { private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $wiki->getBackendHost() . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -94,7 +101,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $wiki->getBackendHost() . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -114,7 +121,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface { private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { $allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $wiki->getBackendHost() . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', @@ -132,7 +139,7 @@ private function getLastEditedDate(Wiki $wiki): ?CarbonInterface { } $revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get( - $wiki->getBackendHost() . '/w/api.php', + $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php', [ 'action' => 'query', 'format' => 'json', diff --git a/app/Wiki.php b/app/Wiki.php index c35a5a7c7..72c4b0f9a 100644 --- a/app/Wiki.php +++ b/app/Wiki.php @@ -3,7 +3,6 @@ namespace App; use App\Helper\DomainHelper; -use App\Services\MediaWikiHostResolver; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -159,12 +158,5 @@ public function getDomainDecodedAttribute(): string { public function wikiLatestProfile() { return $this->hasOne(WikiProfile::class)->latestOfMany(); - } - - /** - * Retrieve correct backend host for the mediawiki version of this wiki - */ - public function getBackendHost() { - return (new MediaWikiHostResolver)->getBackendHostForDomain($this->domain); - } + } From c48b168bbdbfed18c8d5f783eadad1a4161dc236 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 17:15:03 +0100 Subject: [PATCH 18/45] typo --- app/Wiki.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Wiki.php b/app/Wiki.php index 72c4b0f9a..109c55881 100644 --- a/app/Wiki.php +++ b/app/Wiki.php @@ -158,5 +158,5 @@ public function getDomainDecodedAttribute(): string { public function wikiLatestProfile() { return $this->hasOne(WikiProfile::class)->latestOfMany(); - + } } From 3a6fcc46bd5b6577ed87b06d94524554dd0ab9e9 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 17:19:50 +0100 Subject: [PATCH 19/45] add function keyword --- app/Jobs/UpdateWikiSiteStatsJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index 6e6cd913f..83a8a20eb 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -20,7 +20,7 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique { private MediaWikiHostResolver $mwHostResolver; - public __construct() { + public function __construct() { $this->mwHostResolver = new MediaWikiHostResolver; } From e321fa1a212439dd74090788fd550a113eb428aa Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 17:24:53 +0100 Subject: [PATCH 20/45] add ; --- app/Jobs/WikiEntityImportJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index 7eb594e9d..70403d5dd 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -21,7 +21,7 @@ class WikiEntityImportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - private MediaWikiHostResolver $mwHostResolver + private MediaWikiHostResolver $mwHostResolver; /** * Create a new job instance. From e16637bc581e320ca153aa7439e8f379772fe9e6 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 4 Nov 2025 17:31:58 +0100 Subject: [PATCH 21/45] remove ; --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index 41af2df63..1e52d99a5 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -70,7 +70,7 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv $request->setOptions( [ - CURLOPT_URL => $this->mwHostResolver->getBackendHostForDomain($this->wiki->domain); . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), + CURLOPT_URL => $this->mwHostResolver->getBackendHostForDomain($this->wiki->domain) . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => $this->getRequestTimeout(), From 38f39578af909e42d2cc9f3fedae8018369d9b67 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 12:46:24 +0100 Subject: [PATCH 22/45] fix MediawikiInitTest --- tests/Jobs/MediawikiInitTest.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/Jobs/MediawikiInitTest.php b/tests/Jobs/MediawikiInitTest.php index 6398b9b65..999d9060a 100644 --- a/tests/Jobs/MediawikiInitTest.php +++ b/tests/Jobs/MediawikiInitTest.php @@ -4,6 +4,7 @@ use App\Http\Curl\HttpRequest; use App\Jobs\MediawikiInit; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Tests\TestCase; @@ -14,11 +15,14 @@ class MediawikiInitTest extends TestCase { private $username; + private $mwBackendHost; + protected function setUp(): void { parent::setUp(); $this->wikiDomain = 'some.domain.com'; $this->username = 'username'; $this->email = 'some@email.com'; + $this->mwBackendHost = 'mediawiki.localhost'; } private function getMockRequest(string $mockResponse): HttpRequest { @@ -29,7 +33,7 @@ private function getMockRequest(string $mockResponse): HttpRequest { ->method('setOptions') ->with( [ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackInit&format=json', + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackInit&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60, @@ -49,7 +53,18 @@ private function getMockRequest(string $mockResponse): HttpRequest { return $request; } + private function getMockMwHostResolver() { + $mwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $mwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); + + return $mwHostResolver; + } + public function testSuccess() { + $mockHostResolver = $this->getMockMwHostResolver(); + $mockResponse = [ 'warnings' => [], 'wbstackInit' => [ @@ -68,10 +83,12 @@ public function testSuccess() { $job = new MediawikiInit($this->wikiDomain, $this->username, $this->email); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $mockHostResolver); } public function testFatalErrorIsHandled() { + $mockHostResolver = $this->getMockMwHostResolver(); + $mockResponse = 'oh no'; $request = $this->getMockRequest($mockResponse); @@ -84,6 +101,6 @@ public function testFatalErrorIsHandled() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedExceptionMessage); - $job->handle($request); + $job->handle($request, $mockHostResolver); } } From 74cfddab7f567c0663b1a8a876556dac58eac391 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 12:48:24 +0100 Subject: [PATCH 23/45] CirrusSearchJob fix resolver access --- app/Jobs/CirrusSearch/CirrusSearchJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index 1e52d99a5..5fce41be6 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -70,7 +70,7 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv $request->setOptions( [ - CURLOPT_URL => $this->mwHostResolver->getBackendHostForDomain($this->wiki->domain) . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), + CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wiki->domain) . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(), CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => $this->getRequestTimeout(), From be0bb51afe7fb65cc907d6c70e49274d56382c94 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 12:51:06 +0100 Subject: [PATCH 24/45] wikiEntityImportJob: fix mwHostResolver access in static method --- app/Jobs/WikiEntityImportJob.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index 70403d5dd..fa5c07cdb 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -21,8 +21,6 @@ class WikiEntityImportJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - private MediaWikiHostResolver $mwHostResolver; - /** * Create a new job instance. */ @@ -31,9 +29,7 @@ public function __construct( public string $sourceWikiUrl, public array $entityIds, public int $importId - ) { - $this->mwHostResolver = new MediaWikiHostResolver; - } + ) {} private string $targetWikiUrl; @@ -83,8 +79,10 @@ private static function domainToOrigin(string $domain): string { } private static function acquireCredentials(string $wikiDomain): OAuthCredentials { + $mwHostResolver = app()->make(MediaWikiHostResolver::class); + $response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post( - $this->mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', + $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', [ 'consumerName' => 'WikiEntityImportJob', 'ownerOnly' => '1', From 978410c8e7cd4ca2ab7886eb4f5653f09d2b7812 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 13:29:36 +0100 Subject: [PATCH 25/45] refactor class creation --- app/Jobs/WikiEntityImportJob.php | 3 ++- app/Traits/PageFetcher.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index fa5c07cdb..fbb7d516b 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\App; use Maclof\Kubernetes\Client; use Maclof\Kubernetes\Models\Job as KubernetesJob; @@ -79,7 +80,7 @@ private static function domainToOrigin(string $domain): string { } private static function acquireCredentials(string $wikiDomain): OAuthCredentials { - $mwHostResolver = app()->make(MediaWikiHostResolver::class); + $mwHostResolver = App::make(MediaWikiHostResolver::class); $response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post( $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', diff --git a/app/Traits/PageFetcher.php b/app/Traits/PageFetcher.php index 4584e09ce..6ea2a3118 100644 --- a/app/Traits/PageFetcher.php +++ b/app/Traits/PageFetcher.php @@ -5,11 +5,12 @@ use App\Constants\MediawikiNamespace; use App\Services\MediaWikiHostResolver; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\App; trait PageFetcher { // this function is used to fetch pages on namespace public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $namespace): array { - $mwHostResolver = new MediaWikiHostResolver; + $mwHostResolver = App::make(MediaWikiHostResolver::class); $apiUrl = $mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php'; $titles = []; From ba556298176ed6e4ac5f8413590b2e9e5d55a845 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 13:39:07 +0100 Subject: [PATCH 26/45] add mock resoler to ElasticSearchIndexInitTest --- .../ElasticSearchIndexInitTest.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php index 1d538f324..c87d02b19 100644 --- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php +++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php @@ -5,6 +5,7 @@ use App\Http\Curl\CurlRequest; use App\Http\Curl\HttpRequest; use App\Jobs\CirrusSearch\ElasticSearchIndexInit; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; @@ -25,6 +26,10 @@ class ElasticSearchIndexInitTest extends TestCase { private $user; + private $mwBackendHost; + + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); @@ -42,6 +47,13 @@ protected function setUp(): void { $this->wikiDb = WikiDb::factory()->create([ 'wiki_id' => $this->wiki->id, ]); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } public function testDispatching() { @@ -50,7 +62,7 @@ public function testDispatching() { $job->setJob($mockJob); $mockJob->expects($this->once()) ->method('fail'); - $job->handle(new CurlRequest); + $job->handle(new CurlRequest, $this->mockMwHostResolver); } public function testSuccess() { @@ -71,7 +83,7 @@ public function testSuccess() { $request->expects($this->once()) ->method('setOptions') ->with([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackElasticSearchInit&format=json&cluster=all', + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackElasticSearchInit&format=json&cluster=all', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 1234, @@ -90,7 +102,7 @@ public function testSuccess() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); // feature should get enabled $this->assertSame( @@ -119,7 +131,7 @@ public function testUpdate() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); // feature should get enabled $this->assertSame( @@ -134,7 +146,7 @@ public function testJobTriggeredButNoSetting() { $request->expects($this->never())->method('execute'); $job = new ElasticSearchIndexInit($this->wiki->id); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); } /** @@ -152,7 +164,7 @@ public function testFailure(string $expectedFailure, $mockResponse) { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); $this->assertSame( 1, @@ -174,7 +186,7 @@ public function testCurlFailure() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); $this->assertSame( 1, From 811aaee74937d3aed84cb6e882c682cf0bc49e83 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 13:42:00 +0100 Subject: [PATCH 27/45] mock resolver in ForceSearchIndexTest --- .../CirrusSearch/ElasticSearchIndexInitTest.php | 2 +- tests/Jobs/CirrusSearch/ForceSearchIndexTest.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php index c87d02b19..90596e3ed 100644 --- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php +++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php @@ -5,12 +5,12 @@ use App\Http\Curl\CurlRequest; use App\Http\Curl\HttpRequest; use App\Jobs\CirrusSearch\ElasticSearchIndexInit; -use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; use App\WikiManager; use App\WikiSetting; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; diff --git a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php index 43df89ab5..218a501ac 100644 --- a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php +++ b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php @@ -9,6 +9,7 @@ use App\WikiDb; use App\WikiManager; use App\WikiSetting; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -25,6 +26,10 @@ class ForceSearchIndexTest extends TestCase { private $user; + private $mwBackendHost; + + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); @@ -42,6 +47,13 @@ protected function setUp(): void { $this->wikiDb = WikiDb::factory()->create([ 'wiki_id' => $this->wiki->id, ]); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } public function testSuccess() { @@ -89,7 +101,7 @@ public function testSuccess() { $request->expects($this->once()) ->method('setOptions') ->with([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackForceSearchIndex&format=json&fromId=' . $fromId . '&toId=' . $toId, + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackForceSearchIndex&format=json&fromId=' . $fromId . '&toId=' . $toId, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 1000, @@ -108,6 +120,6 @@ public function testSuccess() { $job = new ForceSearchIndex('id', $this->wiki->id, $fromId, $toId); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); } } From eaecfca4e1d604091b050379373ea7685a6f5571 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 13:45:20 +0100 Subject: [PATCH 28/45] mock resolver in QueueSearchIndexBatchesTest --- .../QueueSearchIndexBatchesTest.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php index 892ddb347..2be9ecce0 100644 --- a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php +++ b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php @@ -10,6 +10,7 @@ use App\WikiDb; use App\WikiManager; use App\WikiSetting; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -26,6 +27,8 @@ class QueueSearchIndexBatchesTest extends TestCase { private $user; + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); @@ -43,6 +46,13 @@ protected function setUp(): void { $this->wikiDb = WikiDb::factory()->create([ 'wiki_id' => $this->wiki->id, ]); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } public function testSuccess() { @@ -65,7 +75,7 @@ public function testSuccess() { $request->expects($this->once()) ->method('setOptions') ->with([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json', + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 1000, @@ -84,7 +94,7 @@ public function testSuccess() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); Queue::assertPushed(function (ForceSearchIndex $job) { return $job->wikiId() === $this->wiki->id @@ -114,7 +124,7 @@ public function testMediawikiErrorResponse() { $request->expects($this->once()) ->method('setOptions') ->with([ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json', + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 1000, @@ -133,6 +143,6 @@ public function testMediawikiErrorResponse() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwHostResolver); } } From 3276b12f17e7d008aec57cca57fa475e54f4aebd Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 13:59:39 +0100 Subject: [PATCH 29/45] fix PollForMediaWikiJobsJob --- app/Jobs/PollForMediaWikiJobsJob.php | 7 ++----- tests/Jobs/PollForMediaWikiJobsJobTest.php | 24 ++++++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Jobs/PollForMediaWikiJobsJob.php b/app/Jobs/PollForMediaWikiJobsJob.php index 654696a11..e34e7b5d6 100644 --- a/app/Jobs/PollForMediaWikiJobsJob.php +++ b/app/Jobs/PollForMediaWikiJobsJob.php @@ -14,11 +14,8 @@ class PollForMediaWikiJobsJob extends Job implements ShouldBeUnique, ShouldQueue public $timeout = 1800; - public function __construct(MediaWikiHostResolver $mwHostResolver = null) { - $this->mwHostResolver = $mwHostResolver ?? new MediaWikiHostResolver(); - } - - public function handle(): void { + public function handle(MediaWikiHostResolver $mwHostResolver): void { + $this->mwHostResolver = $mwHostResolver; $allWikiDomains = Wiki::all()->pluck('domain'); foreach ($allWikiDomains as $wikiDomain) { if ($this->hasPendingJobs($wikiDomain)) { diff --git a/tests/Jobs/PollForMediaWikiJobsJobTest.php b/tests/Jobs/PollForMediaWikiJobsJobTest.php index b46b1eb69..eb67d2836 100644 --- a/tests/Jobs/PollForMediaWikiJobsJobTest.php +++ b/tests/Jobs/PollForMediaWikiJobsJobTest.php @@ -5,6 +5,7 @@ use App\Jobs\PollForMediaWikiJobsJob; use App\Jobs\ProcessMediaWikiJobsJob; use App\Wiki; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -17,14 +18,25 @@ class PollForMediaWikiJobsJobTest extends TestCase { private Model $wiki; + private $mwBackendHost; + + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); $this->wiki = Wiki::factory()->create(); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } public function testNoJobs() { Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ 'query' => [ 'statistics' => [ 'jobs' => 0, @@ -40,13 +52,13 @@ public function testNoJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); Bus::assertNothingDispatched(); } public function testWithJobs() { Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ 'query' => [ 'statistics' => [ 'jobs' => 3, @@ -63,13 +75,13 @@ public function testWithJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); Bus::assertDispatched(ProcessMediaWikiJobsJob::class); } public function testWithFailure() { Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([ 'error' => 'Something went wrong', ], 500), ]); @@ -82,7 +94,7 @@ public function testWithFailure() { $mockJob->expects($this->once())->method('markAsFailed'); $mockJob->expects($this->never())->method('fail'); - $job->handle(); + $job->handle($this->mockMwHostResolver); Bus::assertNothingDispatched(); } } From 1ca13ce23a87bca7e302955eedd201694f2e48ac Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:05:19 +0100 Subject: [PATCH 30/45] fix SiteStatsUpdateJobTest --- tests/Jobs/SiteStatsUpdateJobTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/Jobs/SiteStatsUpdateJobTest.php b/tests/Jobs/SiteStatsUpdateJobTest.php index c2cd839d7..490a09934 100644 --- a/tests/Jobs/SiteStatsUpdateJobTest.php +++ b/tests/Jobs/SiteStatsUpdateJobTest.php @@ -7,6 +7,7 @@ use App\User; use App\Wiki; use App\WikiManager; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -14,11 +15,23 @@ class SiteStatsUpdateJobTest extends TestCase { use RefreshDatabase; + private $user; + private $wiki; + private $manager; + private $mwBackendHost; + private $mockMwBackendHostResolver; + protected function setUp(): void { parent::setUp(); $this->user = User::factory()->create(['verified' => true]); $this->wiki = Wiki::factory()->create(); $this->manager = WikiManager::factory()->create(['wiki_id' => $this->wiki->id, 'user_id' => $this->user->id]); + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } private function getMockRequest(string $mockResponse): HttpRequest { @@ -29,7 +42,7 @@ private function getMockRequest(string $mockResponse): HttpRequest { ->method('setOptions') ->with( [ - CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', + CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackSiteStatsUpdate&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60 * 5, @@ -63,7 +76,7 @@ public function testSuccess() { $job = new SiteStatsUpdateJob($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwBackendHostResolver); } public function testFatalErrorIsHandled() { @@ -83,6 +96,6 @@ public function testFatalErrorIsHandled() { $job = new SiteStatsUpdateJob($this->wiki->id); $job->setJob($mockJob); - $job->handle($request); + $job->handle($request, $this->mockMwBackendHostResolver); } } From 66eae8ffc65b13d57fd10fb5dc691b22e31cc3c9 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:09:36 +0100 Subject: [PATCH 31/45] streamline tests --- .../ElasticSearchIndexInitTest.php | 18 +++++++------- .../CirrusSearch/ForceSearchIndexTest.php | 8 +++---- .../QueueSearchIndexBatchesTest.php | 10 ++++---- tests/Jobs/MediawikiInitTest.php | 24 +++++++------------ tests/Jobs/PollForMediaWikiJobsJobTest.php | 12 +++++----- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php index 90596e3ed..cdcab4fb7 100644 --- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php +++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php @@ -28,7 +28,7 @@ class ElasticSearchIndexInitTest extends TestCase { private $mwBackendHost; - private $mockMwHostResolver; + private $mockMwBackendHostResolver; protected function setUp(): void { parent::setUp(); @@ -50,8 +50,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -62,7 +62,7 @@ public function testDispatching() { $job->setJob($mockJob); $mockJob->expects($this->once()) ->method('fail'); - $job->handle(new CurlRequest, $this->mockMwHostResolver); + $job->handle(new CurlRequest, $this->mockMwBackendHostResolver); } public function testSuccess() { @@ -102,7 +102,7 @@ public function testSuccess() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); // feature should get enabled $this->assertSame( @@ -131,7 +131,7 @@ public function testUpdate() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); // feature should get enabled $this->assertSame( @@ -146,7 +146,7 @@ public function testJobTriggeredButNoSetting() { $request->expects($this->never())->method('execute'); $job = new ElasticSearchIndexInit($this->wiki->id); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); } /** @@ -164,7 +164,7 @@ public function testFailure(string $expectedFailure, $mockResponse) { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); $this->assertSame( 1, @@ -186,7 +186,7 @@ public function testCurlFailure() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); $this->assertSame( 1, diff --git a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php index 218a501ac..edf69e9da 100644 --- a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php +++ b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php @@ -28,7 +28,7 @@ class ForceSearchIndexTest extends TestCase { private $mwBackendHost; - private $mockMwHostResolver; + private $mockMwBackendHostResolver; protected function setUp(): void { parent::setUp(); @@ -50,8 +50,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -120,6 +120,6 @@ public function testSuccess() { $job = new ForceSearchIndex('id', $this->wiki->id, $fromId, $toId); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); } } diff --git a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php index 2be9ecce0..837feb558 100644 --- a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php +++ b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php @@ -27,7 +27,7 @@ class QueueSearchIndexBatchesTest extends TestCase { private $user; - private $mockMwHostResolver; + private $mockMwBackendHostResolver; protected function setUp(): void { parent::setUp(); @@ -49,8 +49,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -94,7 +94,7 @@ public function testSuccess() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); Queue::assertPushed(function (ForceSearchIndex $job) { return $job->wikiId() === $this->wiki->id @@ -143,6 +143,6 @@ public function testMediawikiErrorResponse() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); } } diff --git a/tests/Jobs/MediawikiInitTest.php b/tests/Jobs/MediawikiInitTest.php index 999d9060a..1f81eae99 100644 --- a/tests/Jobs/MediawikiInitTest.php +++ b/tests/Jobs/MediawikiInitTest.php @@ -17,12 +17,19 @@ class MediawikiInitTest extends TestCase { private $mwBackendHost; + private $mockMwBackendHostResolver; + protected function setUp(): void { parent::setUp(); $this->wikiDomain = 'some.domain.com'; $this->username = 'username'; $this->email = 'some@email.com'; $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } private function getMockRequest(string $mockResponse): HttpRequest { @@ -53,18 +60,7 @@ private function getMockRequest(string $mockResponse): HttpRequest { return $request; } - private function getMockMwHostResolver() { - $mwHostResolver = $this->createMock(MediaWikiHostResolver::class); - $mwHostResolver->method('getBackendHostForDomain')->willReturn( - $this->mwBackendHost - ); - - return $mwHostResolver; - } - public function testSuccess() { - $mockHostResolver = $this->getMockMwHostResolver(); - $mockResponse = [ 'warnings' => [], 'wbstackInit' => [ @@ -83,12 +79,10 @@ public function testSuccess() { $job = new MediawikiInit($this->wikiDomain, $this->username, $this->email); $job->setJob($mockJob); - $job->handle($request, $mockHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); } public function testFatalErrorIsHandled() { - $mockHostResolver = $this->getMockMwHostResolver(); - $mockResponse = 'oh no'; $request = $this->getMockRequest($mockResponse); @@ -101,6 +95,6 @@ public function testFatalErrorIsHandled() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedExceptionMessage); - $job->handle($request, $mockHostResolver); + $job->handle($request, $this->mockMwBackendHostResolver); } } diff --git a/tests/Jobs/PollForMediaWikiJobsJobTest.php b/tests/Jobs/PollForMediaWikiJobsJobTest.php index eb67d2836..a1c7dff6e 100644 --- a/tests/Jobs/PollForMediaWikiJobsJobTest.php +++ b/tests/Jobs/PollForMediaWikiJobsJobTest.php @@ -20,7 +20,7 @@ class PollForMediaWikiJobsJobTest extends TestCase { private $mwBackendHost; - private $mockMwHostResolver; + private $mockMwBackendHostResolver; protected function setUp(): void { parent::setUp(); @@ -28,8 +28,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -52,7 +52,7 @@ public function testNoJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle($this->mockMwHostResolver); + $job->handle($this->mockMwBackendHostResolver); Bus::assertNothingDispatched(); } @@ -75,7 +75,7 @@ public function testWithJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle($this->mockMwHostResolver); + $job->handle($this->mockMwBackendHostResolver); Bus::assertDispatched(ProcessMediaWikiJobsJob::class); } @@ -94,7 +94,7 @@ public function testWithFailure() { $mockJob->expects($this->once())->method('markAsFailed'); $mockJob->expects($this->never())->method('fail'); - $job->handle($this->mockMwHostResolver); + $job->handle($this->mockMwBackendHostResolver); Bus::assertNothingDispatched(); } } From 4ced0fa3588608c92a2898aa9313b85b2c8b2c2b Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:16:09 +0100 Subject: [PATCH 32/45] streamline naming --- .../ElasticSearchIndexInitTest.php | 18 +++++++++--------- .../Jobs/CirrusSearch/ForceSearchIndexTest.php | 8 ++++---- .../QueueSearchIndexBatchesTest.php | 10 +++++----- tests/Jobs/MediawikiInitTest.php | 10 +++++----- tests/Jobs/PollForMediaWikiJobsJobTest.php | 12 ++++++------ tests/Jobs/SiteStatsUpdateJobTest.php | 10 +++++----- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php index cdcab4fb7..90596e3ed 100644 --- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php +++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php @@ -28,7 +28,7 @@ class ElasticSearchIndexInitTest extends TestCase { private $mwBackendHost; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -50,8 +50,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -62,7 +62,7 @@ public function testDispatching() { $job->setJob($mockJob); $mockJob->expects($this->once()) ->method('fail'); - $job->handle(new CurlRequest, $this->mockMwBackendHostResolver); + $job->handle(new CurlRequest, $this->mockMwHostResolver); } public function testSuccess() { @@ -102,7 +102,7 @@ public function testSuccess() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); // feature should get enabled $this->assertSame( @@ -131,7 +131,7 @@ public function testUpdate() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); // feature should get enabled $this->assertSame( @@ -146,7 +146,7 @@ public function testJobTriggeredButNoSetting() { $request->expects($this->never())->method('execute'); $job = new ElasticSearchIndexInit($this->wiki->id); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } /** @@ -164,7 +164,7 @@ public function testFailure(string $expectedFailure, $mockResponse) { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); $this->assertSame( 1, @@ -186,7 +186,7 @@ public function testCurlFailure() { $job = new ElasticSearchIndexInit($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); $this->assertSame( 1, diff --git a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php index edf69e9da..218a501ac 100644 --- a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php +++ b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php @@ -28,7 +28,7 @@ class ForceSearchIndexTest extends TestCase { private $mwBackendHost; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -50,8 +50,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -120,6 +120,6 @@ public function testSuccess() { $job = new ForceSearchIndex('id', $this->wiki->id, $fromId, $toId); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } } diff --git a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php index 837feb558..2be9ecce0 100644 --- a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php +++ b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php @@ -27,7 +27,7 @@ class QueueSearchIndexBatchesTest extends TestCase { private $user; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -49,8 +49,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -94,7 +94,7 @@ public function testSuccess() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); Queue::assertPushed(function (ForceSearchIndex $job) { return $job->wikiId() === $this->wiki->id @@ -143,6 +143,6 @@ public function testMediawikiErrorResponse() { $job = new QueueSearchIndexBatches($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } } diff --git a/tests/Jobs/MediawikiInitTest.php b/tests/Jobs/MediawikiInitTest.php index 1f81eae99..0bd26a25b 100644 --- a/tests/Jobs/MediawikiInitTest.php +++ b/tests/Jobs/MediawikiInitTest.php @@ -17,7 +17,7 @@ class MediawikiInitTest extends TestCase { private $mwBackendHost; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -26,8 +26,8 @@ protected function setUp(): void { $this->email = 'some@email.com'; $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -79,7 +79,7 @@ public function testSuccess() { $job = new MediawikiInit($this->wikiDomain, $this->username, $this->email); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } public function testFatalErrorIsHandled() { @@ -95,6 +95,6 @@ public function testFatalErrorIsHandled() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedExceptionMessage); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } } diff --git a/tests/Jobs/PollForMediaWikiJobsJobTest.php b/tests/Jobs/PollForMediaWikiJobsJobTest.php index a1c7dff6e..eb67d2836 100644 --- a/tests/Jobs/PollForMediaWikiJobsJobTest.php +++ b/tests/Jobs/PollForMediaWikiJobsJobTest.php @@ -20,7 +20,7 @@ class PollForMediaWikiJobsJobTest extends TestCase { private $mwBackendHost; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -28,8 +28,8 @@ protected function setUp(): void { $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -52,7 +52,7 @@ public function testNoJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle($this->mockMwBackendHostResolver); + $job->handle($this->mockMwHostResolver); Bus::assertNothingDispatched(); } @@ -75,7 +75,7 @@ public function testWithJobs() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle($this->mockMwBackendHostResolver); + $job->handle($this->mockMwHostResolver); Bus::assertDispatched(ProcessMediaWikiJobsJob::class); } @@ -94,7 +94,7 @@ public function testWithFailure() { $mockJob->expects($this->once())->method('markAsFailed'); $mockJob->expects($this->never())->method('fail'); - $job->handle($this->mockMwBackendHostResolver); + $job->handle($this->mockMwHostResolver); Bus::assertNothingDispatched(); } } diff --git a/tests/Jobs/SiteStatsUpdateJobTest.php b/tests/Jobs/SiteStatsUpdateJobTest.php index 490a09934..16620f56b 100644 --- a/tests/Jobs/SiteStatsUpdateJobTest.php +++ b/tests/Jobs/SiteStatsUpdateJobTest.php @@ -19,7 +19,7 @@ class SiteStatsUpdateJobTest extends TestCase { private $wiki; private $manager; private $mwBackendHost; - private $mockMwBackendHostResolver; + private $mockMwHostResolver; protected function setUp(): void { parent::setUp(); @@ -28,8 +28,8 @@ protected function setUp(): void { $this->manager = WikiManager::factory()->create(['wiki_id' => $this->wiki->id, 'user_id' => $this->user->id]); $this->mwBackendHost = 'mediawiki.localhost'; - $this->mockMwBackendHostResolver = $this->createMock(MediaWikiHostResolver::class); - $this->mockMwBackendHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( $this->mwBackendHost ); } @@ -76,7 +76,7 @@ public function testSuccess() { $job = new SiteStatsUpdateJob($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } public function testFatalErrorIsHandled() { @@ -96,6 +96,6 @@ public function testFatalErrorIsHandled() { $job = new SiteStatsUpdateJob($this->wiki->id); $job->setJob($mockJob); - $job->handle($request, $this->mockMwBackendHostResolver); + $job->handle($request, $this->mockMwHostResolver); } } From 66634caed9b849ea491740412f2b3a484bc14f32 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:18:40 +0100 Subject: [PATCH 33/45] fix PageFetcher --- app/Traits/PageFetcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Traits/PageFetcher.php b/app/Traits/PageFetcher.php index 6ea2a3118..751fc91c4 100644 --- a/app/Traits/PageFetcher.php +++ b/app/Traits/PageFetcher.php @@ -11,7 +11,7 @@ trait PageFetcher { // this function is used to fetch pages on namespace public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $namespace): array { $mwHostResolver = App::make(MediaWikiHostResolver::class); - $apiUrl = $mwHostResolver->getMwVersionForDomain($wikiDomain) . '/w/api.php'; + $apiUrl = $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php'; $titles = []; $cursor = ''; From 40b39c28d3e095df7d47f66bb80f159ac244d620 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:26:30 +0100 Subject: [PATCH 34/45] cleanup --- app/Jobs/MediawikiInit.php | 4 +--- app/Jobs/MediawikiSandboxLoadData.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Jobs/MediawikiInit.php b/app/Jobs/MediawikiInit.php index 3a2bad142..76bb5b4e4 100644 --- a/app/Jobs/MediawikiInit.php +++ b/app/Jobs/MediawikiInit.php @@ -30,10 +30,8 @@ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolv 'email' => $this->email, ]; - $mwHost = $mwHostResolver->getBackendHostForDomain($this->wikiDomain); - $request->setOptions([ - CURLOPT_URL => $mwHost . '/w/api.php?action=wbstackInit&format=json', + CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wikiDomain) . '/w/api.php?action=wbstackInit&format=json', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 60, diff --git a/app/Jobs/MediawikiSandboxLoadData.php b/app/Jobs/MediawikiSandboxLoadData.php index 8d95540ef..8d2944326 100644 --- a/app/Jobs/MediawikiSandboxLoadData.php +++ b/app/Jobs/MediawikiSandboxLoadData.php @@ -25,11 +25,9 @@ public function handle(MediaWikiHostResolver $mwHostResolver) { 'dataSet' => $this->dataSet, ]; - $mwHost = $mwHostResolver->getBackendHostForDomain($this->wikiDomain); - $curl = curl_init(); curl_setopt_array($curl, [ - CURLOPT_URL => $mwHost . '/w/rest.php/wikibase-exampledata/v0/load', + CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wikiDomain) . '/w/rest.php/wikibase-exampledata/v0/load', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_TIMEOUT => 10 * 60, // TODO Long 10 mins (probably shouldn't keep the request open...) From aa785c89297c9e7f3557bfe94b123f36c2452175 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:28:31 +0100 Subject: [PATCH 35/45] fix UpdateWikiSiteStatsJob --- app/Jobs/UpdateWikiSiteStatsJob.php | 6 ++-- tests/Jobs/UpdateWikiSiteStatsJobTest.php | 36 +++++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index 83a8a20eb..a22aa24db 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -20,11 +20,9 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique { private MediaWikiHostResolver $mwHostResolver; - public function __construct() { - $this->mwHostResolver = new MediaWikiHostResolver; - } + public function handle(MediaWikiHostResolver $mwHostResolver): void { + $this->mwHostResolver = $mwHostResolver; - public function handle(): void { $allWikis = Wiki::all(); foreach ($allWikis as $wiki) { try { diff --git a/tests/Jobs/UpdateWikiSiteStatsJobTest.php b/tests/Jobs/UpdateWikiSiteStatsJobTest.php index 56f9709d6..27eff73ca 100644 --- a/tests/Jobs/UpdateWikiSiteStatsJobTest.php +++ b/tests/Jobs/UpdateWikiSiteStatsJobTest.php @@ -2,8 +2,9 @@ namespace Tests\Jobs; -use App\Jobs\UpdateWikiSiteStatsJob; use App\Wiki; +use App\Jobs\UpdateWikiSiteStatsJob; +use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Client\Request; @@ -15,12 +16,23 @@ class UpdateWikiSiteStatsJobTest extends TestCase { private $fakeResponses; + private $mwBackendHost; + + private $mockMwHostResolver; + protected function setUp(): void { // Other tests leave dangling wikis around so we need to clean them up parent::setUp(); Wiki::query()->delete(); $this->fakeResponses = []; Http::preventStrayRequests(); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } protected function tearDown(): void { @@ -29,12 +41,12 @@ protected function tearDown(): void { } private function addFakeSiteStatsResponse($site, $response) { - $siteStatsUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'; + $siteStatsUrl = $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'; $this->fakeResponses[$siteStatsUrl][$site] = $response; } private function addFakeRevisionTimestamp($site, $revid, $timestamp) { - $revTimestampUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&prop=revisions&rvprop=timestamp&formatversion=2&revids=' . $revid; + $revTimestampUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&prop=revisions&rvprop=timestamp&formatversion=2&revids=' . $revid; $this->fakeResponses[$revTimestampUrl][$site] = Http::response([ 'query' => [ 'pages' => [ @@ -51,13 +63,13 @@ private function addFakeRevisionTimestamp($site, $revid, $timestamp) { } private function addFakeEmptyRevisionList($site) { - $firstRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer'; + $firstRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer'; $this->fakeResponses[$firstRevisionIdUrl][$site] = Http::response([ 'query' => [ 'allrevisions' => [], ], ]); - $lastRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older'; + $lastRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older'; $this->fakeResponses[$lastRevisionIdUrl][$site] = Http::response([ 'query' => [ 'allrevisions' => [], @@ -66,7 +78,7 @@ private function addFakeEmptyRevisionList($site) { } private function addFakeFirstRevisionId($site, $id) { - $firstRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer'; + $firstRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer'; $this->fakeResponses[$firstRevisionIdUrl][$site] = Http::response([ 'query' => [ 'allrevisions' => [ @@ -83,7 +95,7 @@ private function addFakeFirstRevisionId($site, $id) { } private function addFakeLastRevisionId($site, $id) { - $lastRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older'; + $lastRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older'; $this->fakeResponses[$lastRevisionIdUrl][$site] = Http::response([ 'query' => [ 'allrevisions' => [ @@ -148,7 +160,7 @@ public function testWikiSiteStatsIsSuccessfullyUpdated() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); $stats1 = Wiki::with('wikiSiteStats')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiSiteStats()->first(); $this->assertEquals($stats1['admins'], 7); @@ -214,7 +226,7 @@ public function testSuccessOfMultipleWikisTogether() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); $stats1 = Wiki::with('wikiSiteStats')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiSiteStats()->first(); $this->assertEquals($stats1['admins'], 7); @@ -247,7 +259,7 @@ public function testJobFailsIfSiteStatsLookupFails() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->once())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); } public function testIncompleteSiteStatsDoesNotCauseFailure() { @@ -276,7 +288,7 @@ public function testIncompleteSiteStatsDoesNotCauseFailure() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); $stats2 = Wiki::with('wikiSiteStats')->where(['domain' => 'incomplete.wikibase.cloud'])->first()->wikiSiteStats()->first(); $this->assertEquals($stats2['articles'], 99); @@ -298,7 +310,7 @@ public function testNeverEditedWikiCreatesEmptyLifecycleEvents() { $mockJob->expects($this->never())->method('fail'); $mockJob->expects($this->never())->method('markAsFailed'); - $job->handle(); + $job->handle($this->mockMwHostResolver); $events = Wiki::with('wikiLifecycleEvents')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiLifecycleEvents()->first(); $this->assertNull($events['first_edited']); From 9c60d3ce0b872574ea3914ec9ce0ebe823055727 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 14:41:31 +0100 Subject: [PATCH 36/45] fix WikiEntityImportJob --- app/Jobs/WikiEntityImportJob.php | 8 +++----- tests/Jobs/WikiEntityImportJobTest.php | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index fbb7d516b..95a20aef2 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -37,12 +37,12 @@ public function __construct( /** * Execute the job. */ - public function handle(Client $kubernetesClient): void { + public function handle(Client $kubernetesClient, MediaWikiHostResolver $mwHostResolver): void { $import = null; try { $wiki = Wiki::findOrFail($this->wikiId); $import = WikiEntityImport::findOrFail($this->importId); - $creds = $this->acquireCredentials($wiki->domain); + $creds = $this->acquireCredentials($wiki->domain, $mwHostResolver); $this->targetWikiUrl = $this->domainToOrigin($wiki->domain); @@ -79,9 +79,7 @@ private static function domainToOrigin(string $domain): string { : 'https://' . $domain; } - private static function acquireCredentials(string $wikiDomain): OAuthCredentials { - $mwHostResolver = App::make(MediaWikiHostResolver::class); - + private static function acquireCredentials(string $wikiDomain, MediaWikiHostResolver $mwHostResolver): OAuthCredentials { $response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post( $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json', [ diff --git a/tests/Jobs/WikiEntityImportJobTest.php b/tests/Jobs/WikiEntityImportJobTest.php index ad8e62a48..224144d0f 100644 --- a/tests/Jobs/WikiEntityImportJobTest.php +++ b/tests/Jobs/WikiEntityImportJobTest.php @@ -6,6 +6,7 @@ use App\Wiki; use App\WikiEntityImport; use App\WikiEntityImportStatus; +use App\Services\MediaWikiHostResolver; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; @@ -19,10 +20,20 @@ class WikiEntityImportJobTest extends TestCase { use RefreshDatabase; + private $mwBackendHost; + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); Wiki::query()->delete(); WikiEntityImport::query()->delete(); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } protected function tearDown(): void { @@ -34,7 +45,7 @@ protected function tearDown(): void { public function testJobDoesNotFail() { Http::fake([ - 'mediawiki-139-app-backend.default.svc.cluster.default/w/api.php?action=wbstackPlatformOauthGet&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=wbstackPlatformOauthGet&format=json' => Http::response([ 'wbstackPlatformOauthGet' => [ 'success' => '1', 'data' => [ @@ -80,9 +91,11 @@ public function testJobDoesNotFail() { 'verify' => '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt', ]); - $job->handle(new Client([ + $k8sClient = new Client([ 'master' => 'https://kubernetes.default.svc', 'token' => '/var/run/secrets/kubernetes.io/serviceaccount/token', - ], null, $mockGuzzle)); + ], null, $mockGuzzle); + + $job->handle($k8sClient, $this->mockMwHostResolver); } } From 13fa7e4bf64fc0f05632e861fcf768dbbbdf8096 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 15:09:50 +0100 Subject: [PATCH 37/45] undo refactoring --- app/Traits/PageFetcher.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Traits/PageFetcher.php b/app/Traits/PageFetcher.php index 751fc91c4..09bc04e97 100644 --- a/app/Traits/PageFetcher.php +++ b/app/Traits/PageFetcher.php @@ -3,15 +3,16 @@ namespace App\Traits; use App\Constants\MediawikiNamespace; -use App\Services\MediaWikiHostResolver; use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\App; trait PageFetcher { + private string $apiUrl; + // this function is used to fetch pages on namespace public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $namespace): array { - $mwHostResolver = App::make(MediaWikiHostResolver::class); - $apiUrl = $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php'; + if (empty($this->apiUrl)) { + throw new \RuntimeException('API URL has not been set.'); + } $titles = []; $cursor = ''; @@ -19,7 +20,7 @@ public function fetchPagesInNamespace(string $wikiDomain, MediawikiNamespace $na $response = Http::withHeaders([ 'host' => $wikiDomain, ])->get( - $apiUrl, + $this->apiUrl, [ 'action' => 'query', 'list' => 'allpages', From eada31253bc2f2eababea6a6381b0ada8b0f9375 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 15:10:16 +0100 Subject: [PATCH 38/45] fix PlatformStatsSummaryJob --- app/Jobs/PlatformStatsSummaryJob.php | 7 ++++++- tests/Jobs/PlatformStatsSummaryJobTest.php | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/Jobs/PlatformStatsSummaryJob.php b/app/Jobs/PlatformStatsSummaryJob.php index 5df37ae0a..0312820a0 100644 --- a/app/Jobs/PlatformStatsSummaryJob.php +++ b/app/Jobs/PlatformStatsSummaryJob.php @@ -4,6 +4,7 @@ use App\Constants\MediawikiNamespace; use App\Helper\MWTimestampHelper; +use App\Services\MediaWikiHostResolver; use App\Traits; use App\User; use App\Wiki; @@ -39,6 +40,8 @@ class PlatformStatsSummaryJob extends Job { private $platformSummaryStatsVersion = 'v1'; + private MediaWikiHostResolver $mwHostResolver; + public function __construct() { $this->inactiveThreshold = Config::get('wbstack.platform_summary_inactive_threshold'); $this->creationRateRanges = Config::get('wbstack.platform_summary_creation_rate_ranges'); @@ -76,6 +79,7 @@ public function prepareStats(array $allStats, $wikis): array { $currentTime = CarbonImmutable::now(); foreach ($wikis as $wiki) { + $this->apiUrl = $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace if (!is_null($wiki->deleted_at)) { $deletedWikis[] = $wiki; @@ -163,7 +167,8 @@ public function prepareStats(array $allStats, $wikis): array { ]; } - public function handle(DatabaseManager $manager): void { + public function handle(DatabaseManager $manager, MediaWikiHostResolver $mwHostResolver): void { + $this->mwHostResolver = $mwHostResolver; $wikis = Wiki::withTrashed()->with('wikidb')->get(); $conn = $manager->connection('mysql'); diff --git a/tests/Jobs/PlatformStatsSummaryJobTest.php b/tests/Jobs/PlatformStatsSummaryJobTest.php index 282d32131..a1ee413db 100644 --- a/tests/Jobs/PlatformStatsSummaryJobTest.php +++ b/tests/Jobs/PlatformStatsSummaryJobTest.php @@ -6,6 +6,7 @@ use App\Helper\MWTimestampHelper; use App\Jobs\PlatformStatsSummaryJob; use App\Jobs\ProvisionWikiDbJob; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; @@ -31,6 +32,10 @@ class PlatformStatsSummaryJobTest extends TestCase { private $db_name = 'some_cool_db_name'; + private $mwBackendHost; + + private $mockMwHostResolver; + protected function setUp(): void { parent::setUp(); for ($n = 0; $n < $this->numWikis; $n++) { @@ -38,6 +43,13 @@ protected function setUp(): void { } $this->wikis = []; $this->users = []; + + $this->mwBackendHost = 'mediawiki.localhost'; + + $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); } protected function tearDown(): void { @@ -57,7 +69,7 @@ private function seedWikis() { WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]); $job = new ProvisionWikiDbJob($this->db_prefix . $n, $this->db_name . $n, null); - $job->handle($manager); + $job->handle($manager, $this->mockMwHostResolver); $wikiDb = WikiDb::whereName($this->db_name . $n)->first(); $wikiDb->update(['wiki_id' => $wiki->id]); @@ -80,7 +92,7 @@ public function testQueryGetsStats() { $job = new PlatformStatsSummaryJob; $job->setJob($mockJob); - $job->handle($manager); + $job->handle($manager, $this->mockMwHostResolver); } public function testGroupings() { From b164a23db849b2ec74987f8545faf2a29e7f60ab Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 15:15:56 +0100 Subject: [PATCH 39/45] fix RebuildQueryserviceData --- .../Commands/RebuildQueryserviceData.php | 5 ++- .../Commands/RebuildQueryserviceDataTest.php | 38 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php index 46bf921a2..adee741e5 100644 --- a/app/Console/Commands/RebuildQueryserviceData.php +++ b/app/Console/Commands/RebuildQueryserviceData.php @@ -4,6 +4,7 @@ use App\Constants\MediawikiNamespace; use App\Jobs\SpawnQueryserviceUpdaterJob; +use App\Services\MediaWikiHostResolver; use App\QueryserviceNamespace; use App\Traits; use App\Wiki; @@ -25,7 +26,7 @@ class RebuildQueryserviceData extends Command { protected string $queueName; - public function handle() { + public function handle(MediaWikiHostResolver $mwHostResolver) { $this->chunkSize = intval($this->option('chunkSize')); $this->sparqlUrlFormat = $this->option('sparqlUrlFormat'); $this->queueName = $this->option('queueName'); @@ -41,6 +42,8 @@ public function handle() { $skippedWikis = 0; $processedWikis = 0; foreach ($wikis as $wiki) { + $this->apiUrl = $mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace + try { $entities = $this->getEntitiesForWiki($wiki); $sparqlUrl = $this->getSparqlUrl($wiki); diff --git a/tests/Commands/RebuildQueryserviceDataTest.php b/tests/Commands/RebuildQueryserviceDataTest.php index aad23ed02..3345e5782 100644 --- a/tests/Commands/RebuildQueryserviceDataTest.php +++ b/tests/Commands/RebuildQueryserviceDataTest.php @@ -4,6 +4,7 @@ use App\Constants\MediawikiNamespace; use App\Jobs\SpawnQueryserviceUpdaterJob; +use App\Services\MediaWikiHostResolver; use App\QueryserviceNamespace; use App\Wiki; use App\WikiSetting; @@ -16,11 +17,22 @@ class RebuildQueryserviceDataTest extends TestCase { use DatabaseTransactions; + private $mwBackendHost; + protected function setUp(): void { parent::setUp(); Wiki::query()->delete(); WikiSetting::query()->delete(); QueryserviceNamespace::query()->delete(); + + $this->mwBackendHost = 'mediawiki.localhost'; + + $mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class); + $mockMwHostResolver->method('getBackendHostForDomain')->willReturn( + $this->mwBackendHost + ); + + $this->app->instance(MediaWikiHostResolver::class, $mockMwHostResolver); } protected function tearDown(): void { @@ -55,7 +67,7 @@ public function testWikiWithLexemes() { ]); Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -73,7 +85,7 @@ public function testWikiWithLexemes() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ 'continue' => [ 'apcontinue' => 'Q6', ], @@ -102,7 +114,7 @@ public function testWikiWithLexemes() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -124,7 +136,7 @@ public function testWikiWithLexemes() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -185,7 +197,7 @@ public function testWikiNoLexemes() { ]); Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -203,7 +215,7 @@ public function testWikiNoLexemes() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -229,7 +241,7 @@ public function testWikiNoLexemes() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ 'error' => 'Lexemes not enabled for this wiki', ], 400), ]); @@ -261,7 +273,7 @@ public function testFailure() { ]); Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ [ @@ -279,10 +291,10 @@ public function testFailure() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'error' => 'THE DINOSAURS ESCAPED!', ], 500), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ 'error' => 'Lexemes not enabled for this wiki', ], 400), ]); @@ -301,17 +313,17 @@ public function testEmptyWiki() { ]); Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([ 'error' => 'Lexemes not enabled for this wiki', ], 400), ]); From 90cea35ecbfde006a7c617a7952b9b61d4f7263c Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 15:26:48 +0100 Subject: [PATCH 40/45] run pint fix --- app/Console/Commands/RebuildQueryserviceData.php | 2 +- app/Jobs/CirrusSearch/CirrusSearchJob.php | 2 +- app/Jobs/PollForMediaWikiJobsJob.php | 2 +- app/Jobs/SiteStatsUpdateJob.php | 2 +- app/Jobs/UpdateWikiSiteStatsJob.php | 2 +- app/Jobs/WikiEntityImportJob.php | 3 +-- tests/Commands/RebuildQueryserviceDataTest.php | 2 +- tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php | 2 +- tests/Jobs/CirrusSearch/ForceSearchIndexTest.php | 2 +- tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php | 2 +- tests/Jobs/PollForMediaWikiJobsJobTest.php | 2 +- tests/Jobs/SiteStatsUpdateJobTest.php | 6 +++++- tests/Jobs/UpdateWikiSiteStatsJobTest.php | 2 +- tests/Jobs/WikiEntityImportJobTest.php | 3 ++- 14 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php index adee741e5..8286950e4 100644 --- a/app/Console/Commands/RebuildQueryserviceData.php +++ b/app/Console/Commands/RebuildQueryserviceData.php @@ -4,8 +4,8 @@ use App\Constants\MediawikiNamespace; use App\Jobs\SpawnQueryserviceUpdaterJob; -use App\Services\MediaWikiHostResolver; use App\QueryserviceNamespace; +use App\Services\MediaWikiHostResolver; use App\Traits; use App\Wiki; use App\WikiSetting; diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php index 5fce41be6..ce6d6bad6 100644 --- a/app/Jobs/CirrusSearch/CirrusSearchJob.php +++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php @@ -4,9 +4,9 @@ use App\Http\Curl\HttpRequest; use App\Jobs\Job; +use App\Services\MediaWikiHostResolver; use App\Wiki; use App\WikiSetting; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\ShouldBeUnique; abstract class CirrusSearchJob extends Job implements ShouldBeUnique { diff --git a/app/Jobs/PollForMediaWikiJobsJob.php b/app/Jobs/PollForMediaWikiJobsJob.php index e34e7b5d6..60d8d1e1b 100644 --- a/app/Jobs/PollForMediaWikiJobsJob.php +++ b/app/Jobs/PollForMediaWikiJobsJob.php @@ -2,8 +2,8 @@ namespace App\Jobs; -use App\Wiki; use App\Services\MediaWikiHostResolver; +use App\Wiki; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Http; diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php index de8efe967..d16afcddf 100644 --- a/app/Jobs/SiteStatsUpdateJob.php +++ b/app/Jobs/SiteStatsUpdateJob.php @@ -3,8 +3,8 @@ namespace App\Jobs; use App\Http\Curl\HttpRequest; -use App\Wiki; use App\Services\MediaWikiHostResolver; +use App\Wiki; use Illuminate\Bus\Batchable; use Illuminate\Support\Facades\Log; diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index a22aa24db..f2453dbe7 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -2,9 +2,9 @@ namespace App\Jobs; +use App\Services\MediaWikiHostResolver; use App\Wiki; use App\WikiSiteStats; -use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index 95a20aef2..441f8d690 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -2,10 +2,10 @@ namespace App\Jobs; +use App\Services\MediaWikiHostResolver; use App\Wiki; use App\WikiEntityImport; use App\WikiEntityImportStatus; -use App\Services\MediaWikiHostResolver; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -15,7 +15,6 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\App; use Maclof\Kubernetes\Client; use Maclof\Kubernetes\Models\Job as KubernetesJob; diff --git a/tests/Commands/RebuildQueryserviceDataTest.php b/tests/Commands/RebuildQueryserviceDataTest.php index 3345e5782..07387a22d 100644 --- a/tests/Commands/RebuildQueryserviceDataTest.php +++ b/tests/Commands/RebuildQueryserviceDataTest.php @@ -4,8 +4,8 @@ use App\Constants\MediawikiNamespace; use App\Jobs\SpawnQueryserviceUpdaterJob; -use App\Services\MediaWikiHostResolver; use App\QueryserviceNamespace; +use App\Services\MediaWikiHostResolver; use App\Wiki; use App\WikiSetting; use Illuminate\Foundation\Testing\DatabaseTransactions; diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php index 90596e3ed..c87d02b19 100644 --- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php +++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php @@ -5,12 +5,12 @@ use App\Http\Curl\CurlRequest; use App\Http\Curl\HttpRequest; use App\Jobs\CirrusSearch\ElasticSearchIndexInit; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; use App\WikiManager; use App\WikiSetting; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; diff --git a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php index 218a501ac..c20b36cda 100644 --- a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php +++ b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php @@ -4,12 +4,12 @@ use App\Http\Curl\HttpRequest; use App\Jobs\CirrusSearch\ForceSearchIndex; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; use App\WikiManager; use App\WikiSetting; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; diff --git a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php index 2be9ecce0..1e7845c7d 100644 --- a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php +++ b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php @@ -5,12 +5,12 @@ use App\Http\Curl\HttpRequest; use App\Jobs\CirrusSearch\ForceSearchIndex; use App\Jobs\CirrusSearch\QueueSearchIndexBatches; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiDb; use App\WikiManager; use App\WikiSetting; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Testing\DatabaseTransactions; diff --git a/tests/Jobs/PollForMediaWikiJobsJobTest.php b/tests/Jobs/PollForMediaWikiJobsJobTest.php index eb67d2836..ddd33cd68 100644 --- a/tests/Jobs/PollForMediaWikiJobsJobTest.php +++ b/tests/Jobs/PollForMediaWikiJobsJobTest.php @@ -4,8 +4,8 @@ use App\Jobs\PollForMediaWikiJobsJob; use App\Jobs\ProcessMediaWikiJobsJob; -use App\Wiki; use App\Services\MediaWikiHostResolver; +use App\Wiki; use Illuminate\Contracts\Queue\Job; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\RefreshDatabase; diff --git a/tests/Jobs/SiteStatsUpdateJobTest.php b/tests/Jobs/SiteStatsUpdateJobTest.php index 16620f56b..2851b4d19 100644 --- a/tests/Jobs/SiteStatsUpdateJobTest.php +++ b/tests/Jobs/SiteStatsUpdateJobTest.php @@ -4,10 +4,10 @@ use App\Http\Curl\HttpRequest; use App\Jobs\SiteStatsUpdateJob; +use App\Services\MediaWikiHostResolver; use App\User; use App\Wiki; use App\WikiManager; -use App\Services\MediaWikiHostResolver; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -16,9 +16,13 @@ class SiteStatsUpdateJobTest extends TestCase { use RefreshDatabase; private $user; + private $wiki; + private $manager; + private $mwBackendHost; + private $mockMwHostResolver; protected function setUp(): void { diff --git a/tests/Jobs/UpdateWikiSiteStatsJobTest.php b/tests/Jobs/UpdateWikiSiteStatsJobTest.php index 27eff73ca..fe32937d0 100644 --- a/tests/Jobs/UpdateWikiSiteStatsJobTest.php +++ b/tests/Jobs/UpdateWikiSiteStatsJobTest.php @@ -2,9 +2,9 @@ namespace Tests\Jobs; -use App\Wiki; use App\Jobs\UpdateWikiSiteStatsJob; use App\Services\MediaWikiHostResolver; +use App\Wiki; use Illuminate\Contracts\Queue\Job; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Client\Request; diff --git a/tests/Jobs/WikiEntityImportJobTest.php b/tests/Jobs/WikiEntityImportJobTest.php index 224144d0f..15c8aa6b5 100644 --- a/tests/Jobs/WikiEntityImportJobTest.php +++ b/tests/Jobs/WikiEntityImportJobTest.php @@ -3,10 +3,10 @@ namespace Tests\Jobs; use App\Jobs\WikiEntityImportJob; +use App\Services\MediaWikiHostResolver; use App\Wiki; use App\WikiEntityImport; use App\WikiEntityImportStatus; -use App\Services\MediaWikiHostResolver; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; @@ -21,6 +21,7 @@ class WikiEntityImportJobTest extends TestCase { use RefreshDatabase; private $mwBackendHost; + private $mockMwHostResolver; protected function setUp(): void { From 2f06fea6f1426817c48c49cea6d4c40549d07934 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 15:53:29 +0100 Subject: [PATCH 41/45] remove changes from #994 --- app/Services/MediaWikiHostResolver.php | 3 --- tests/Services/MediaWikiHostResolverTest.php | 9 --------- 2 files changed, 12 deletions(-) diff --git a/app/Services/MediaWikiHostResolver.php b/app/Services/MediaWikiHostResolver.php index f83b6e284..8c83f748a 100644 --- a/app/Services/MediaWikiHostResolver.php +++ b/app/Services/MediaWikiHostResolver.php @@ -37,9 +37,6 @@ public function getBackendHostForDomain(string $domain): string { public function getMwVersionForDomain(string $domain): string { $wiki = Wiki::where('domain', $domain)->first(); - if (!$wiki) { - throw new UnknownWikiDomainException("Unknown Wiki Domain '{$domain}'."); - } $dbVersion = $wiki->wikiDb->version; diff --git a/tests/Services/MediaWikiHostResolverTest.php b/tests/Services/MediaWikiHostResolverTest.php index d3dfe0023..053988e7c 100644 --- a/tests/Services/MediaWikiHostResolverTest.php +++ b/tests/Services/MediaWikiHostResolverTest.php @@ -44,13 +44,4 @@ public function testResolverThrowsIfUnableToFindHostInMap(): void { UnknownDBVersionException::class ); } - - public function testResolverThrowsIfUnableToFindWiki(): void { - $domain = (new Factory)->create()->unique()->text(30); - $resolver = new MediaWikiHostResolver; - $this->assertThrows( - fn () => $resolver->getBackendHostForDomain($domain), - UnknownWikiDomainException::class - ); - } } From e26dbe5e8239f3dd7a1fbf7c606e2bb469a5a5e2 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 7 Nov 2025 16:52:12 +0100 Subject: [PATCH 42/45] linting --- app/Services/MediaWikiHostResolver.php | 1 - tests/Services/MediaWikiHostResolverTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/Services/MediaWikiHostResolver.php b/app/Services/MediaWikiHostResolver.php index 8c83f748a..3a3a3af82 100644 --- a/app/Services/MediaWikiHostResolver.php +++ b/app/Services/MediaWikiHostResolver.php @@ -37,7 +37,6 @@ public function getBackendHostForDomain(string $domain): string { public function getMwVersionForDomain(string $domain): string { $wiki = Wiki::where('domain', $domain)->first(); - $dbVersion = $wiki->wikiDb->version; if (array_key_exists($dbVersion, self::DB_VERSION_TO_MW_VERSION)) { diff --git a/tests/Services/MediaWikiHostResolverTest.php b/tests/Services/MediaWikiHostResolverTest.php index 053988e7c..826c5f1f7 100644 --- a/tests/Services/MediaWikiHostResolverTest.php +++ b/tests/Services/MediaWikiHostResolverTest.php @@ -4,7 +4,6 @@ use App\Services\MediaWikiHostResolver; use App\Services\UnknownDBVersionException; -use App\Services\UnknownWikiDomainException; use App\Wiki; use App\WikiDb; use Faker\Factory; From a694288b65d59d5b416f7b20e2092d3c6a174505 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 11 Nov 2025 12:29:30 +0100 Subject: [PATCH 43/45] clean up usages of PLATFORM_MW_BACKEND_HOST in tests --- phpunit.xml | 1 - tests/Jobs/PlatformStatsSummaryJobTest.php | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 1b31238df..867f2ff2b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,6 @@ - diff --git a/tests/Jobs/PlatformStatsSummaryJobTest.php b/tests/Jobs/PlatformStatsSummaryJobTest.php index a1ee413db..4a954200f 100644 --- a/tests/Jobs/PlatformStatsSummaryJobTest.php +++ b/tests/Jobs/PlatformStatsSummaryJobTest.php @@ -122,7 +122,7 @@ public function testGroupings() { ]); // Generate some items/properties for testing, each wiki will have 3 props and 9 items Http::fake([ - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ ['title' => 'Property:P1', 'namespace' => MediawikiNamespace::property], @@ -131,7 +131,7 @@ public function testGroupings() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([ 'continue' => [ 'apcontinue' => 'Q6', ], @@ -145,7 +145,7 @@ public function testGroupings() { ], ], ], 200), - getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([ + $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([ 'query' => [ 'allpages' => [ ['title' => 'Item:Q6', 'namespace' => MediawikiNamespace::item], From 0e72b99a17a8e5f8bef1a8454bddac54769a2065 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 11 Nov 2025 19:21:03 +0100 Subject: [PATCH 44/45] fix rebase --- app/Services/MediaWikiHostResolver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Services/MediaWikiHostResolver.php b/app/Services/MediaWikiHostResolver.php index 3a3a3af82..f83b6e284 100644 --- a/app/Services/MediaWikiHostResolver.php +++ b/app/Services/MediaWikiHostResolver.php @@ -37,6 +37,10 @@ public function getBackendHostForDomain(string $domain): string { public function getMwVersionForDomain(string $domain): string { $wiki = Wiki::where('domain', $domain)->first(); + if (!$wiki) { + throw new UnknownWikiDomainException("Unknown Wiki Domain '{$domain}'."); + } + $dbVersion = $wiki->wikiDb->version; if (array_key_exists($dbVersion, self::DB_VERSION_TO_MW_VERSION)) { From e4bf0340f4a9531daeb7ae9dd56bc13c01c82625 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 11 Nov 2025 19:23:15 +0100 Subject: [PATCH 45/45] fix rebase part 2 --- tests/Services/MediaWikiHostResolverTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Services/MediaWikiHostResolverTest.php b/tests/Services/MediaWikiHostResolverTest.php index 826c5f1f7..d3dfe0023 100644 --- a/tests/Services/MediaWikiHostResolverTest.php +++ b/tests/Services/MediaWikiHostResolverTest.php @@ -4,6 +4,7 @@ use App\Services\MediaWikiHostResolver; use App\Services\UnknownDBVersionException; +use App\Services\UnknownWikiDomainException; use App\Wiki; use App\WikiDb; use Faker\Factory; @@ -43,4 +44,13 @@ public function testResolverThrowsIfUnableToFindHostInMap(): void { UnknownDBVersionException::class ); } + + public function testResolverThrowsIfUnableToFindWiki(): void { + $domain = (new Factory)->create()->unique()->text(30); + $resolver = new MediaWikiHostResolver; + $this->assertThrows( + fn () => $resolver->getBackendHostForDomain($domain), + UnknownWikiDomainException::class + ); + } }