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
Empty file removed .github/workflows/phpstan_test.yml
Empty file.
3 changes: 1 addition & 2 deletions .github/workflows/server_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: server tests
name: Server Test

on:
pull_request:
Expand Down Expand Up @@ -39,7 +39,6 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v5
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/weekly_maintenance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Weekly Maintenance

on:
schedule:
- cron: "0 22 * * 0"
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
weekly-maintenance:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
coverage: none
tools: composer

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Setup Mago
uses: nhedger/setup-mago@v1

- name: Run Mago analyze
run: composer mago:analyze

- name: Run Rector maintenance config
run: composer rector:maintenance

- name: Check for changes
id: changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Generate branch name
if: steps.changes.outputs.changed == 'true'
id: branch
run: |
echo "name=chore/weekly-maintenance-$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT"

- name: Commit changes
if: steps.changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "${{ steps.branch.outputs.name }}"
git add .
git commit -m "chore: apply weekly maintenance fixes"

- name: Push branch
if: steps.changes.outputs.changed == 'true'
run: |
git push origin "${{ steps.branch.outputs.name }}"

- name: Create pull request
if: steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v7
with:
branch: ${{ steps.branch.outputs.name }}
title: "chore: weekly maintenance fixes"
body: |
## Description
This PR contains weekly automated maintenance updates.

### Included
- Mago analysis executed
- Rector safe maintenance rules applied

## Notes
Please review the changes carefully before merging.
commit-message: "chore: apply weekly maintenance fixes"
base: main
delete-branch: false
2 changes: 1 addition & 1 deletion src/app/Common/Pagination/PaginationViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
public function toArray(): array
{
$items = [];
if ($this->viewModelCollection) {
if ($this->viewModelCollection instanceof \App\Packages\Features\QueryUseCases\ViewModel\WorldHeritageViewModelCollection) {
$items = $this->viewModelCollection->toArray();
} else {
$dtoCollection = $this->pagination->getCollection();
Expand Down
6 changes: 4 additions & 2 deletions src/app/Console/Commands/BackfillStateParties.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function handle(): int
->filter(fn($c) => strlen($c) === 2)
->values();

if ($codes->isEmpty()) continue;
if ($codes->isEmpty()) {
continue;
}

$valid = Country::whereIn('state_party_code', $codes)->pluck('state_party_code')->all();
$missing = array_diff($codes->all(), $valid);
if ($missing) {
if ($missing !== []) {
Log::warning("Unknown codes for site {$site->id}: ".implode(',', $missing));
}

Expand Down
8 changes: 6 additions & 2 deletions src/app/Console/Commands/BuildWorldHeritageLocalDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public function handle(): int
'--site-judgements-out' => $siteJudgementsOut,
'--exceptions-out' => $exceptionsOut,
];
if ($pretty) $splitArgs['--pretty'] = true;
if ($clean) $splitArgs['--clean'] = true;
if ($pretty) {
$splitArgs['--pretty'] = true;
}
if ($clean) {
$splitArgs['--clean'] = true;
}
$this->mustRun('world-heritage:split-json', $splitArgs);

$this->info('Running: import-countries-split');
Expand Down
76 changes: 57 additions & 19 deletions src/app/Console/Commands/DumpUnescoWorldHeritageJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ private function dumpAll(string $baseUrl, int $limit, int $max, string $outPath,
$this->info('Fetching All records (no country refine).');

$first = $this->fetch($baseUrl, null, 1, 0);
if ($first === null) return ['ok' => false, 'results' => [], 'results_raw' => []];
if ($first === null) {
return ['ok' => false, 'results' => [], 'results_raw' => []];
}

$total = (int) ($first['total_count'] ?? 0);
if ($total <= 0) {
Expand All @@ -143,22 +145,32 @@ private function dumpAll(string $baseUrl, int $limit, int $max, string $outPath,
$resultsRawAll = [];

while (true) {
if ($max > 0 && $fetched >= $max) break;
if ($max > 0 && $fetched >= $max) {
break;
}

$resp = $this->fetch($baseUrl, null, $limit, $offset);
if ($resp === null) return ['ok' => false, 'results' => [], 'results_raw' => []];
if ($resp === null) {
return ['ok' => false, 'results' => [], 'results_raw' => []];
}

$results = $resp['results'] ?? null;
if (!is_array($results) || $results === []) break;
if (!is_array($results) || $results === []) {
break;
}

foreach ($results as $row) {
if (!is_array($row)) continue;
if (!is_array($row)) {
continue;
}

$resultsRawAll[] = $row;
$resultsAll[] = $this->normalizeRow($row);

$fetched++;
if ($max > 0 && $fetched >= $max) break 2;
if ($max > 0 && $fetched >= $max) {
break 2;
}
}

$offset += count($results);
Expand Down Expand Up @@ -220,7 +232,9 @@ private function dumpOneCountry(
}

$first = $this->fetch($baseUrl, $country, 1, 0);
if ($first === null) return 1;
if ($first === null) {
return 1;
}

$total = (int) ($first['total_count'] ?? 0);
if ($total <= 0) {
Expand All @@ -235,21 +249,31 @@ private function dumpOneCountry(
$resultsAll = [];

while (true) {
if ($max > 0 && $fetched >= $max) break;
if ($max > 0 && $fetched >= $max) {
break;
}

$resp = $this->fetch($baseUrl, $country, $limit, $offset);
if ($resp === null) return 1;
if ($resp === null) {
return 1;
}

$results = $resp['results'] ?? null;
if (!is_array($results) || $results === []) break;
if (!is_array($results) || $results === []) {
break;
}

foreach ($results as $row) {
if (!is_array($row)) continue;
if (!is_array($row)) {
continue;
}

$resultsAll[] = $this->normalizeRow($row);
$fetched++;

if ($max > 0 && $fetched >= $max) break 2;
if ($max > 0 && $fetched >= $max) {
break 2;
}
}

$offset += count($results);
Expand Down Expand Up @@ -300,11 +324,15 @@ private function generateCountriesFileFromResults(array $resultsAll, string $out

foreach ($resultsAll as $row) {
$states = $row['states_names'] ?? null;
if (!is_array($states)) continue;
if (!is_array($states)) {
continue;
}

foreach ($states as $name) {
$name = trim((string) $name);
if ($name === '') continue;
if ($name === '') {
continue;
}
$set[$name] = true;
}
}
Expand Down Expand Up @@ -470,9 +498,13 @@ private function buildCriteriaFromDumpRow(array $row): array
{
$raw = $row['criteria_txt'] ?? null;

if (!is_string($raw)) return [];
if (!is_string($raw)) {
return [];
}
$raw = trim($raw);
if ($raw === '') return [];
if ($raw === '') {
return [];
}

preg_match_all('/\(\s*([ivxlcdm]+)\s*\)/i', $raw, $m1);
$vals = $m1[1] ?? [];
Expand All @@ -482,15 +514,21 @@ private function buildCriteriaFromDumpRow(array $row): array
$vals = $m2[1] ?? [];
}

if (!is_array($vals) || $vals === []) return [];
if (!is_array($vals) || $vals === []) {
return [];
}

$out = [];
$seen = [];

foreach ($vals as $v) {
$v = strtolower(trim((string) $v));
if ($v === '') continue;
if (!preg_match('/^[ivxlcdm]+$/', $v)) continue;
if ($v === '') {
continue;
}
if (!preg_match('/^[ivxlcdm]+$/', $v)) {
continue;
}

if (!isset($seen[$v])) {
$seen[$v] = true;
Expand Down
6 changes: 4 additions & 2 deletions src/app/Console/Commands/ImportCountriesFromSplitFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function handle(): int
$batch = [];

foreach ($rows as $row) {
if ($max > 0 && $imported >= $max) break;
if ($max > 0 && $imported >= $max) {
break;
}
if (!is_array($row)) { $skipped++; continue; }

$code = strtoupper(trim((string) ($row['state_party_code'] ?? '')));
Expand Down Expand Up @@ -89,7 +91,7 @@ public function handle(): int
}
}

if ($batch) {
if ($batch !== []) {
$imported += $this->flush($batch, $dryRun);
}

Expand Down
20 changes: 14 additions & 6 deletions src/app/Console/Commands/ImportSiteStatePartiesFromSplitFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ public function handle(): int
$now = Carbon::now();

foreach ($rows as $row) {
if ($max > 0 && $imported >= $max) break;
if ($max > 0 && $imported >= $max) {
break;
}
if (!is_array($row)) { $skipped++; continue; }

$siteId = $row['world_heritage_site_id'] ?? null;
$code = strtoupper(trim((string) ($row['state_party_code'] ?? '')));

if (!(is_int($siteId) || (is_string($siteId) && is_numeric($siteId)))) {
if (!is_int($siteId) && !(is_string($siteId) && is_numeric($siteId))) {
$skipped++;
if ($strict) {
$this->error("Strict: missing/invalid world_heritage_site_id: " . json_encode($row, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
Expand Down Expand Up @@ -111,7 +113,7 @@ public function handle(): int
}
}

if ($batch) {
if ($batch !== []) {
$imported += $this->flush($batch, $dryRun);
}

Expand All @@ -121,7 +123,9 @@ public function handle(): int

private function flush(array $rows, bool $dryRun): int
{
if ($dryRun) return count($rows);
if ($dryRun) {
return count($rows);
}

DB::table('site_state_parties')->upsert(
$rows,
Expand All @@ -134,14 +138,18 @@ private function flush(array $rows, bool $dryRun): int

private function toNullableInt(mixed $v): ?int
{
if ($v === null || $v === '') return null;
if ($v === null || $v === '') {
return null;
}
return is_numeric($v) ? (int) $v : null;
}

private function resolvePath(string $path): string
{
$path = trim($path);
if ($path === '') return $path;
if ($path === '') {
return $path;
}

if (str_starts_with($path, '/') || preg_match('/^[A-Za-z]:\\\\/', $path) === 1) {
return $path;
Expand Down
Loading