From 569bf0595ffc8ead25c5573ae04b6fcb8ceeb822 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 25 Nov 2025 07:49:16 +0100 Subject: [PATCH 1/2] move mw db version map to conf file --- app/Services/MediaWikiHostResolver.php | 12 +++--------- config/mw-db-version-map.php | 9 +++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 config/mw-db-version-map.php diff --git a/app/Services/MediaWikiHostResolver.php b/app/Services/MediaWikiHostResolver.php index a07e6f9a..c8e6454f 100644 --- a/app/Services/MediaWikiHostResolver.php +++ b/app/Services/MediaWikiHostResolver.php @@ -16,13 +16,6 @@ class UnknownDBVersionException extends Exception {} class UnknownWikiDomainException extends Exception {} class MediaWikiHostResolver { - // TODO: Move this mapping to a config file so that MW updates do not require code changes here. - /** @var array Map of DB version strings to MediaWiki version strings */ - private const DB_VERSION_TO_MW_VERSION = [ - 'mw1.39-wbs1' => '139', - 'mw1.43-wbs1' => '143', - ]; - /** * @throws UnknownDBVersionException * @throws UnknownWikiDomainException @@ -53,8 +46,9 @@ private function getMwVersionForDomain(string $domain): string { $dbVersion = $wiki->wikiDb->version; - if (array_key_exists($dbVersion, self::DB_VERSION_TO_MW_VERSION)) { - return self::DB_VERSION_TO_MW_VERSION[$dbVersion]; + $versionMap = config('mw-db-version-map'); + if (array_key_exists($dbVersion, $versionMap)) { + return $versionMap[$dbVersion]; } throw new UnknownDBVersionException("Unknown DB version '{$dbVersion}' for domain '{$domain}'."); } diff --git a/config/mw-db-version-map.php b/config/mw-db-version-map.php new file mode 100644 index 00000000..a6a26abd --- /dev/null +++ b/config/mw-db-version-map.php @@ -0,0 +1,9 @@ + '139', + 'mw1.43-wbs1' => '143', +]; + +return $versionMap; From 0d5d9c124bdf3832eb1feb7ed25b4898b33f40a6 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 25 Nov 2025 10:49:36 +0100 Subject: [PATCH 2/2] use config in WikiDbVersionController --- app/Http/Controllers/Backend/WikiDbVersionController.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/Http/Controllers/Backend/WikiDbVersionController.php b/app/Http/Controllers/Backend/WikiDbVersionController.php index 3ecf214b..537b840c 100644 --- a/app/Http/Controllers/Backend/WikiDbVersionController.php +++ b/app/Http/Controllers/Backend/WikiDbVersionController.php @@ -7,12 +7,6 @@ use Illuminate\Http\Request; class WikiDbVersionController extends Controller { - // keep in sync with App\Services\MediaWikiHostResolver - private const DB_VERSION_TO_MW_VERSION = [ - 'mw1.39-wbs1' => '139', - 'mw1.43-wbs1' => '143', - ]; - public function updateWikiDbVersion(Request $request): \Illuminate\Http\JsonResponse { $validated = $request->validate([ 'domain' => 'required|string', @@ -29,7 +23,7 @@ public function updateWikiDbVersion(Request $request): \Illuminate\Http\JsonResp return response()->json(['error' => "No wiki found with domain: '{$domain}'"], 404); } - if (!array_key_exists($targetDbVersion, self::DB_VERSION_TO_MW_VERSION)) { + if (!array_key_exists($targetDbVersion, config('mw-db-version-map'))) { return response()->json(['error' => "Invalid database version string: '{$targetDbVersion}'"], 400); }