Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions app/Http/Controllers/Backend/WikiDbVersionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
}

Expand Down
13 changes: 3 additions & 10 deletions app/Services/MediaWikiHostResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +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.
// keep in sync with App\Http\Controllers\Backend\WikiDbVersionController
/** @var array<string, string> 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
Expand Down Expand Up @@ -54,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}'.");
}
Expand Down
9 changes: 9 additions & 0 deletions config/mw-db-version-map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// TODO: Read from outside of this codebase so that MW updates do not require code changes here.
$versionMap = [
'mw1.39-wbs1' => '139',
'mw1.43-wbs1' => '143',
];

return $versionMap;
Comment on lines +4 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking nitpick]: no need for a variable?

Suggested change
$versionMap = [
'mw1.39-wbs1' => '139',
'mw1.43-wbs1' => '143',
];
return $versionMap;
return [
'mw1.39-wbs1' => '139',
'mw1.43-wbs1' => '143',
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we might benefit from it when we will add code to read this from somewhere elseTM in the future (or when we want to figure out how that could work & look like)

Loading