File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use Illuminate \Http \Request ;
88
99class WikiDbVersionController extends Controller {
10- // keep in sync with App\Services\MediaWikiHostResolver
11- private const DB_VERSION_TO_MW_VERSION = [
12- 'mw1.39-wbs1 ' => '139 ' ,
13- 'mw1.43-wbs1 ' => '143 ' ,
14- ];
15-
1610 public function updateWikiDbVersion (Request $ request ): \Illuminate \Http \JsonResponse {
1711 $ validated = $ request ->validate ([
1812 'domain ' => 'required|string ' ,
@@ -29,7 +23,7 @@ public function updateWikiDbVersion(Request $request): \Illuminate\Http\JsonResp
2923 return response ()->json (['error ' => "No wiki found with domain: ' {$ domain }' " ], 404 );
3024 }
3125
32- if (!array_key_exists ($ targetDbVersion , self :: DB_VERSION_TO_MW_VERSION )) {
26+ if (!array_key_exists ($ targetDbVersion , config ( ' mw-db-version-map ' ) )) {
3327 return response ()->json (['error ' => "Invalid database version string: ' {$ targetDbVersion }' " ], 400 );
3428 }
3529
Original file line number Diff line number Diff line change @@ -16,14 +16,6 @@ class UnknownDBVersionException extends Exception {}
1616class UnknownWikiDomainException extends Exception {}
1717
1818class MediaWikiHostResolver {
19- // TODO: Move this mapping to a config file so that MW updates do not require code changes here.
20- // keep in sync with App\Http\Controllers\Backend\WikiDbVersionController
21- /** @var array<string, string> Map of DB version strings to MediaWiki version strings */
22- private const DB_VERSION_TO_MW_VERSION = [
23- 'mw1.39-wbs1 ' => '139 ' ,
24- 'mw1.43-wbs1 ' => '143 ' ,
25- ];
26-
2719 /**
2820 * @throws UnknownDBVersionException
2921 * @throws UnknownWikiDomainException
@@ -54,8 +46,9 @@ private function getMwVersionForDomain(string $domain): string {
5446
5547 $ dbVersion = $ wiki ->wikiDb ->version ;
5648
57- if (array_key_exists ($ dbVersion , self ::DB_VERSION_TO_MW_VERSION )) {
58- return self ::DB_VERSION_TO_MW_VERSION [$ dbVersion ];
49+ $ versionMap = config ('mw-db-version-map ' );
50+ if (array_key_exists ($ dbVersion , $ versionMap )) {
51+ return $ versionMap [$ dbVersion ];
5952 }
6053 throw new UnknownDBVersionException ("Unknown DB version ' {$ dbVersion }' for domain ' {$ domain }'. " );
6154 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // TODO: Read from outside of this codebase so that MW updates do not require code changes here.
4+ $ versionMap = [
5+ 'mw1.39-wbs1 ' => '139 ' ,
6+ 'mw1.43-wbs1 ' => '143 ' ,
7+ ];
8+
9+ return $ versionMap ;
You can’t perform that action at this time.
0 commit comments