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
4 changes: 2 additions & 2 deletions app/Jobs/PlatformStatsSummaryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public function prepareStats(array $allStats, $wikis): array {
$currentTime = CarbonImmutable::now();

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

if (!is_null($wiki->deleted_at)) {
$deletedWikis[] = $wiki;

continue;
}

$this->apiUrl = $this->mwHostResolver->getBackendUrlForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace

// add items and properties counts of the wiki to the corresponded arrays
try {
$nextItemCount = count($this->fetchPagesInNamespace($wiki->domain, MediawikiNamespace::item));
Expand Down
49 changes: 49 additions & 0 deletions tests/Jobs/PlatformStatsSummaryJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,55 @@ public function testGroupings() {
);
}

public function testSkipDeletedWikisBeforeResolvingBackendUrl() {
$deletedWiki = Wiki::factory()->create(['deleted_at' => CarbonImmutable::yesterday(), 'domain' => 'deleted.cloud']);
WikiDb::factory()->for($deletedWiki)->create(['name' => 'deleted_db']);

$activeWiki = Wiki::factory()->create(['deleted_at' => null, 'domain' => 'active.cloud']);
WikiDb::factory()->for($activeWiki)->create(['name' => 'active_db']);

$this->mockMwHostResolver
->expects($this->once())
->method('getBackendUrlForDomain')
->with('active.cloud')
->willReturn($this->mwBackendHost);

$job = new PlatformStatsSummaryJob();
// This is a hack to override the `private` `PlatformStatsSummaryJob::mwHostResolver` property.
// See https://www.php.net/manual/en/closure.call.php for more details on how this works.
// TODO: figure out how to stub the `DatabaseManager` correctly and/or refactor the Job so that
// we can more easily inject dependencies in the tests.
(function ($resolver): void {
$this->mwHostResolver = $resolver;
})->call($job, $this->mockMwHostResolver);

$groups = $job->prepareStats([
[
'wiki' => 'active.cloud',
'edits' => 1,
'pages' => 1,
'users' => 1,
'active_users' => 1,
'lastEdit' => MWTimestampHelper::getMWTimestampFromCarbon(CarbonImmutable::now()),
'first100UsingOauth' => '0',
'platform_summary_version' => 'v1',
],
[
'wiki' => 'deleted.cloud',
'edits' => 1,
'pages' => 1,
'users' => 1,
'active_users' => 1,
'lastEdit' => MWTimestampHelper::getMWTimestampFromCarbon(CarbonImmutable::now()),
'first100UsingOauth' => '0',
'platform_summary_version' => 'v1',
],
], [$deletedWiki, $activeWiki]);

$this->assertSame(1, $groups['deleted']);
$this->assertSame(1, $groups['edited_last_90_days']);
}

public function testCreationStats() {
$this->markTestSkipped('Pollutes the deleted wiki list');
$mockJob = $this->createMock(Job::class);
Expand Down
Loading