Skip to content

Commit eada312

Browse files
committed
fix PlatformStatsSummaryJob
1 parent 13fa7e4 commit eada312

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

app/Jobs/PlatformStatsSummaryJob.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Constants\MediawikiNamespace;
66
use App\Helper\MWTimestampHelper;
7+
use App\Services\MediaWikiHostResolver;
78
use App\Traits;
89
use App\User;
910
use App\Wiki;
@@ -39,6 +40,8 @@ class PlatformStatsSummaryJob extends Job {
3940

4041
private $platformSummaryStatsVersion = 'v1';
4142

43+
private MediaWikiHostResolver $mwHostResolver;
44+
4245
public function __construct() {
4346
$this->inactiveThreshold = Config::get('wbstack.platform_summary_inactive_threshold');
4447
$this->creationRateRanges = Config::get('wbstack.platform_summary_creation_rate_ranges');
@@ -76,6 +79,7 @@ public function prepareStats(array $allStats, $wikis): array {
7679
$currentTime = CarbonImmutable::now();
7780

7881
foreach ($wikis as $wiki) {
82+
$this->apiUrl = $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace
7983

8084
if (!is_null($wiki->deleted_at)) {
8185
$deletedWikis[] = $wiki;
@@ -163,7 +167,8 @@ public function prepareStats(array $allStats, $wikis): array {
163167
];
164168
}
165169

166-
public function handle(DatabaseManager $manager): void {
170+
public function handle(DatabaseManager $manager, MediaWikiHostResolver $mwHostResolver): void {
171+
$this->mwHostResolver = $mwHostResolver;
167172
$wikis = Wiki::withTrashed()->with('wikidb')->get();
168173

169174
$conn = $manager->connection('mysql');

tests/Jobs/PlatformStatsSummaryJobTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Helper\MWTimestampHelper;
77
use App\Jobs\PlatformStatsSummaryJob;
88
use App\Jobs\ProvisionWikiDbJob;
9+
use App\Services\MediaWikiHostResolver;
910
use App\User;
1011
use App\Wiki;
1112
use App\WikiDb;
@@ -31,13 +32,24 @@ class PlatformStatsSummaryJobTest extends TestCase {
3132

3233
private $db_name = 'some_cool_db_name';
3334

35+
private $mwBackendHost;
36+
37+
private $mockMwHostResolver;
38+
3439
protected function setUp(): void {
3540
parent::setUp();
3641
for ($n = 0; $n < $this->numWikis; $n++) {
3742
DB::connection('mysql')->getPdo()->exec("DROP DATABASE IF EXISTS {$this->db_name}{$n};");
3843
}
3944
$this->wikis = [];
4045
$this->users = [];
46+
47+
$this->mwBackendHost = 'mediawiki.localhost';
48+
49+
$this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
50+
$this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
51+
$this->mwBackendHost
52+
);
4153
}
4254

4355
protected function tearDown(): void {
@@ -57,7 +69,7 @@ private function seedWikis() {
5769
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
5870

5971
$job = new ProvisionWikiDbJob($this->db_prefix . $n, $this->db_name . $n, null);
60-
$job->handle($manager);
72+
$job->handle($manager, $this->mockMwHostResolver);
6173

6274
$wikiDb = WikiDb::whereName($this->db_name . $n)->first();
6375
$wikiDb->update(['wiki_id' => $wiki->id]);
@@ -80,7 +92,7 @@ public function testQueryGetsStats() {
8092
$job = new PlatformStatsSummaryJob;
8193
$job->setJob($mockJob);
8294

83-
$job->handle($manager);
95+
$job->handle($manager, $this->mockMwHostResolver);
8496
}
8597

8698
public function testGroupings() {

0 commit comments

Comments
 (0)