Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for number of sizevariants without sizes. #2252

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions app/Actions/Diagnostics/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Actions\Diagnostics\Pipes\Checks\AppUrlMatchCheck;
use App\Actions\Diagnostics\Pipes\Checks\BasicPermissionCheck;
use App\Actions\Diagnostics\Pipes\Checks\ConfigSanityCheck;
use App\Actions\Diagnostics\Pipes\Checks\CountSizeVariantsCheck;
use App\Actions\Diagnostics\Pipes\Checks\DBIntegrityCheck;
use App\Actions\Diagnostics\Pipes\Checks\DBSupportCheck;
use App\Actions\Diagnostics\Pipes\Checks\ForeignKeyListInfo;
Expand Down Expand Up @@ -42,6 +43,7 @@ class Errors
ForeignKeyListInfo::class,
DBIntegrityCheck::class,
SmallMediumExistsCheck::class,
CountSizeVariantsCheck::class,
];

/**
Expand Down
36 changes: 36 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/CountSizeVariantsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Actions\Diagnostics\Pipes\Checks;

use App\Contracts\DiagnosticPipe;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

/**
* This checks the Database integrity.
* More precisely if there are any pictures without an original.
*
* Such cases will crash the front-end.
ildyria marked this conversation as resolved.
Show resolved Hide resolved
*/
class CountSizeVariantsCheck implements DiagnosticPipe
{
/**
* {@inheritDoc}
*/
public function handle(array &$data, \Closure $next): array
{
if (!Schema::hasTable('size_variants')) {
return $next($data);
}

$num = DB::table('size_variants')->where('size_variants.filesize', '=', 0)->count();
if ($num > 0) {
// @codeCoverageIgnoreStart
$data[] = sprintf('Info: Found %d small images without filesizes.', $num);
$data[] = sprintf(' You can use `php artisan lychee:variant_filesize %d` to compute them.', $num);
// @codeCoverageIgnoreEnd
}

return $next($data);
}
}
Loading