-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMediaWikiHostResolver.php
More file actions
51 lines (40 loc) · 1.81 KB
/
MediaWikiHostResolver.php
File metadata and controls
51 lines (40 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace App\Services;
use App\Wiki;
use Exception;
/**
* Exception thrown when a database version is not recognized in MediaWikiHostResolver.
*/
class UnknownDBVersionException extends Exception {}
/**
* Exception thrown when a wiki is not found by domain in MediaWikiHostResolver.
*/
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<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',
];
// https://phabricator.wikimedia.org/T409530
// This service could have other methods in future, e.g. getBackendHostForWiki()
// public function getBackendHostForWiki(Wiki $wiki): string {
// return $this->getBackendHostForDomain($wiki->domain);
// }
public function getBackendHostForDomain(string $domain): string {
// TODO: Move 'backend.default.svc.cluster.local' to an env variable (e.g. PLATFORM_MW_BACKEND_HOST_SUFFIX) for flexibility.
return sprintf('mediawiki-%s-app-backend.default.svc.cluster.local', $this->getMwVersionForDomain($domain));
}
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)) {
return self::DB_VERSION_TO_MW_VERSION[$dbVersion];
}
throw new UnknownDBVersionException("Unknown DB version '{$dbVersion}' for domain '{$domain}'.");
}
}