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

fix complaints in Diagnostics when no migrations has been run #1990

Merged
merged 3 commits into from
Aug 24, 2023
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
5 changes: 5 additions & 0 deletions app/Actions/Diagnostics/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Exceptions\Internal\QueryBuilderException;
use App\Models\Configs;
use Illuminate\Support\Facades\Schema;

class Configuration
{
Expand All @@ -17,6 +18,10 @@ class Configuration
*/
public function get(): array
{
if (!Schema::hasTable('configs')) {
return ['Error: migration has not been run yet.'];
}

// Load settings
$settings = Configs::query()
->where('confidentiality', '<=', 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Contracts\DiagnosticPipe;
use App\Models\User;
use Illuminate\Support\Facades\Schema;

class AdminUserExistsCheck implements DiagnosticPipe
{
Expand All @@ -12,11 +13,15 @@ class AdminUserExistsCheck implements DiagnosticPipe
*/
public function handle(array &$data, \Closure $next): array
{
if (!Schema::hasTable('users')) {
return $next($data);
}

$numberOfAdmin = User::query()->where('may_administrate', '=', true)->count();
if ($numberOfAdmin === 0) {
$data[] = 'Error: User Admin not found in database. Please run: "php lychee:create_user {username} {password}"';
}

return $next($data);
}
}
}
5 changes: 5 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/ConfigSanityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Contracts\DiagnosticPipe;
use App\Models\Configs;
use Illuminate\Support\Facades\Schema;

/**
* Small checks on the content of the config database.
Expand All @@ -18,6 +19,10 @@ class ConfigSanityCheck implements DiagnosticPipe
*/
public function handle(array &$data, \Closure $next): array
{
if (!Schema::hasTable('configs')) {
return $next($data);
}

// Load settings
$this->settings = Configs::get();

Expand Down
5 changes: 5 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/DBIntegrityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\DiagnosticPipe;
use App\Models\Photo;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

/**
* This checks the Database integrity.
Expand All @@ -19,6 +20,10 @@ class DBIntegrityCheck implements DiagnosticPipe
*/
public function handle(array &$data, \Closure $next): array
{
if (!Schema::hasTable('size_variants') || !Schema::hasTable('photos')) {
return $next($data);
}

$subJoin = DB::table('size_variants')->where('size_variants.type', '=', 0);
$photos = Photo::query()
->with(['album'])
Expand Down
5 changes: 5 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/ImageOptCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\DiagnosticPipe;
use App\Facades\Helpers;
use App\Models\Configs;
use Illuminate\Support\Facades\Schema;
use function Safe\exec;
use Spatie\ImageOptimizer\Optimizers\Cwebp;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
Expand All @@ -23,6 +24,10 @@ class ImageOptCheck implements DiagnosticPipe
*/
public function handle(array &$data, \Closure $next): array
{
if (!Schema::hasTable('configs')) {
return $next($data);
}

$tools = [];
$tools[] = new Cwebp();
$tools[] = new Gifsicle();
Expand Down
4 changes: 4 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/UpdatableCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Metadata\Versions\GitHubVersion;
use App\Metadata\Versions\InstalledVersion;
use App\Models\Configs;
use Illuminate\Support\Facades\Schema;
use function Safe\exec;

/**
Expand Down Expand Up @@ -64,6 +65,9 @@ public static function assertUpdatability(): void
return;
// @codeCoverageIgnoreEnd
}
if (!Schema::hasTable('configs')) {
throw new ConfigurationException('Migration is not run');
ildyria marked this conversation as resolved.
Show resolved Hide resolved
}

if (!Configs::getValueAsBool('allow_online_git_pull')) {
throw new ConfigurationException('Online updates are disabled by configuration');
Expand Down
5 changes: 5 additions & 0 deletions app/Metadata/Versions/InstalledVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Exceptions\ConfigurationKeyMissingException;
use App\Models\Configs;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;

/**
* InstalledVersion contains the following info:
Expand Down Expand Up @@ -61,6 +62,10 @@ public function isDev(): bool
*/
public function getVersion(): Version
{
if (!Schema::hasTable('configs')) {
return Version::createFromInt(10000);
}

return Version::createFromInt(Configs::getValueAsInt('version'));
}
}
3 changes: 1 addition & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public function boot()
$lang = Configs::getValueAsString('lang');
app()->setLocale($lang);
} catch (\Throwable $e) {
/** log and ignore.
/** Ignore.
* This is necessary so that we can continue:
* - if Configs table do not exists (no install),
* - if the value does not exists in configs (no install),.
*/
logger($e);
}

/**
Expand Down