Skip to content

Commit e8a542e

Browse files
authored
Merge branch 'main' into update-mediawiki-1.43
2 parents a9dacf2 + 57a8d41 commit e8a542e

8 files changed

Lines changed: 126 additions & 7 deletions

File tree

.github/workflows/docker.build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Set up helmfile
2727
uses: helmfile/helmfile-action@v1.9.1
2828
- name: Cache Docker layers
29-
uses: actions/cache@v4.0.2
29+
uses: actions/cache@v4
3030
with:
3131
path: /tmp/.buildx-cache
3232
key: ${{ runner.os }}-buildx-${{ github.sha }}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# api
22

3+
## 10x.18.6 - 11 March 2025
4+
- Map domain to database version using backend route
5+
6+
## 10x.18.5 - 28 February 2025
7+
- Fix bug on wiki metrics recoding
8+
9+
## 10x.18.4 - 19 February 2025
10+
- Fix job definition in UpdateWikiDailyMetricJob class
11+
- Update actions/cache in github workflow to version 4 to pass CI
312

413
## 10x.18.3 - 10 February 2025
514
- Added new table wiki_daily_metrics
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Backend;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Wiki;
7+
use Illuminate\Http\Request;
8+
9+
class IngressController extends Controller
10+
{
11+
public function getWikiVersionForDomain(Request $request): \Illuminate\Http\Response
12+
{
13+
$domain = $request->query('domain');
14+
$version = Wiki::where('domain', $domain)
15+
->whereNull('deleted_at')
16+
->leftJoin('wiki_dbs', 'wiki_id', '=', 'wikis.id')
17+
->pluck('version')
18+
->first();
19+
20+
if (is_null($version)) {
21+
abort(401);
22+
}
23+
return response('1')->header('x-version', $version);
24+
}
25+
}

app/Jobs/UpdateWikiDailyMetricJob.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
use App\Wiki;
66
use \App\Metrics\App\WikiMetrics;
7+
use Illuminate\Contracts\Queue\ShouldBeUnique;
78
use Illuminate\Contracts\Queue\ShouldQueue;
89
use Illuminate\Foundation\Bus\Dispatchable;
910

1011
//This job is for the daily measurements of metrics per wikibases.
1112
//This is to help in understanding the purpose of active wikis.
12-
class UpdateWikiDailyMetricJob implements ShouldQueue
13+
class UpdateWikiDailyMetricJob extends Job implements ShouldBeUnique
1314
{
1415
use Dispatchable;
15-
public int $timeout = 3600;
16+
public $timeout = 3600;
1617

1718
/**
1819
* Execute the job.

app/Metrics/App/WikiMetrics.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public function saveMetrics(Wiki $wiki): void
1616
$isDeleted = (bool)$wiki->deleted_at;
1717
if ($oldRecord) {
1818
if ($oldRecord->is_deleted) {
19-
\Log::info("WikiMetrics is deleted, no new record for WikiMetrics ID {$wiki->id}.");
19+
\Log::info("Wiki is deleted, no new record for WikiMetrics ID {$wiki->id}.");
2020
return;
2121
}
22-
if ($oldRecord->pages === $todayPageCount) {
23-
\Log::info("Page count unchanged for WikiMetrics ID {$wiki->id}, no new record added.");
24-
return;
22+
if (!$isDeleted) {
23+
if ($oldRecord->pages === $todayPageCount) {
24+
\Log::info("Page count unchanged for WikiMetrics ID {$wiki->id}, no new record added.");
25+
return;
26+
}
2527
}
2628
}
2729
WikiDailyMetrics::create([

routes/backend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ function () {
1414
}
1515
);
1616

17+
$router->group(['prefix' => 'ingress'], function () use ($router) {
18+
// GET
19+
$router->get('getWikiVersionForDomain', ['uses' => 'IngressController@getWikiVersionForDomain']);
20+
});
21+
1722
$router->group(['prefix' => 'wiki'], function () use ($router) {
1823
$router->get('getWikiForDomain', ['uses' => 'WikiController@getWikiForDomain']);
1924
$router->patch('updateEntityImport', ['uses' => '\App\Http\Controllers\WikiEntityImportController@update']);

tests/Metrics/WikiMetricsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,32 @@ public function testDoesNotAddDuplicateRecordsWithOnlyDateChange()
4949
'date' => Carbon::today()->toDateString()
5050
]);
5151
}
52+
53+
public function testAddRecordsWikiIsDeleted()
54+
{
55+
$wiki = Wiki::factory()->create([
56+
'domain' => 'thisfake.wikibase.cloud'
57+
]);
58+
//Insert an old metric value for a wiki
59+
WikiDailyMetrics::create([
60+
'id' => $wiki->id. '_'. Carbon::yesterday()->toDateString(),
61+
'wiki_id' => $wiki->id,
62+
'date' => Carbon::yesterday()->toDateString(),
63+
'pages' => 0,
64+
'is_deleted' => 1
65+
]);
66+
//delete the wiki
67+
$wiki->delete();
68+
$wiki->save();
69+
70+
(new WikiMetrics())->saveMetrics($wiki);
71+
72+
//Assert No new record was created for today
73+
$this->assertDatabaseMissing('wiki_daily_metrics', [
74+
'wiki_id' => $wiki->id,
75+
'is_deleted' => 1,
76+
'date' => now()->toDateString()
77+
]);
78+
}
5279
}
5380

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Tests\Routes\Ingress;
4+
5+
use Tests\TestCase;
6+
use App\Wiki;
7+
use App\WikiDb;
8+
use Illuminate\Foundation\Testing\RefreshDatabase;
9+
10+
class GetWikiVersionForDomainTest extends TestCase
11+
{
12+
protected $route = '/backend/ingress/getWikiVersionForDomain';
13+
14+
use RefreshDatabase;
15+
16+
public function tearDown(): void
17+
{
18+
Wiki::query()->delete();
19+
parent::tearDown();
20+
}
21+
22+
private function createWiki(string $domain, string $version) {
23+
$wiki = Wiki::factory()->create(['domain' => $domain]);
24+
WikiDb::create([
25+
'name' => $domain,
26+
'user' => 'someUser',
27+
'password' => 'somePassword',
28+
'version' => $version,
29+
'prefix' => 'somePrefix',
30+
'wiki_id' => $wiki->id
31+
]);
32+
}
33+
34+
public function testNotFound()
35+
{
36+
$this->createWiki('found.wikibase.cloud', 'someVersion');
37+
$this->json('GET', $this->route . '?domain=notfound.wikibase.cloud')->assertStatus(401);
38+
}
39+
40+
public function testFoundVersion()
41+
{
42+
$version = 'someVersion';
43+
$this->createWiki('found.wikibase.cloud', $version);
44+
$this->createWiki('other.wikibase.cloud', 'otherVersion');
45+
$this->json('GET', $this->route . '?domain=found.wikibase.cloud')
46+
->assertStatus(200)
47+
->assertHeader('x-version', $version)
48+
->assertContent('1');
49+
}
50+
}

0 commit comments

Comments
 (0)