-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathStatisticsIntegrityCheck.php
More file actions
58 lines (48 loc) · 1.6 KB
/
StatisticsIntegrityCheck.php
File metadata and controls
58 lines (48 loc) · 1.6 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
52
53
54
55
56
57
58
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace App\Actions\Diagnostics\Pipes\Checks;
use App\Contracts\DiagnosticPipe;
use App\DTO\DiagnosticData;
use App\Http\Resources\Diagnostics\StatisticsCheckResource;
use App\Models\Configs;
use Illuminate\Support\Facades\DB;
/**
* Check whether or not there are photos or albums without statistics.
*/
class StatisticsIntegrityCheck implements DiagnosticPipe
{
/**
* {@inheritDoc}
*/
public function handle(array &$data, \Closure $next): array
{
$check = $this->get();
if ($check->missing_albums > 0) {
$data[] = DiagnosticData::warn(sprintf('There are %d albums without statistics.', $check->missing_albums), self::class,
['Go to the maintenance page to fix this.']);
}
if ($check->missing_albums > 0) {
$data[] = DiagnosticData::warn(sprintf('There are %d photos without statistics.', $check->missing_photos), self::class,
['Go to the maintenance page to fix this.']);
}
return $next($data);
}
public function get(): StatisticsCheckResource
{
// Just skip the check, we don't care.
if (!Configs::getValueAsBool('metrics_enabled')) {
return new StatisticsCheckResource(0, 0);
}
$num_albums = DB::table('base_albums')->leftJoin('statistics', 'base_albums.id', '=', 'statistics.album_id')
->whereNull('statistics.id')
->count();
$num_photos = DB::table('photos')->leftJoin('statistics', 'photos.id', '=', 'statistics.photo_id')
->whereNull('statistics.id')
->count();
return new StatisticsCheckResource($num_albums, $num_photos);
}
}