Skip to content

Commit

Permalink
Add fix tree module (LycheeOrg#2351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Apr 6, 2024
1 parent aae1eb0 commit dc4aba9
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/Livewire/Components/Modules/Maintenance/FixTree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Livewire\Components\Modules\Maintenance;

use App\Models\Album;
use App\Models\Configs;
use App\Policies\SettingsPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use Livewire\Attributes\Locked;
use Livewire\Component;

/**
* Maybe the album tree is broken.
* We fix it here.
*/
class FixTree extends Component
{
#[Locked] public int|null $result = null;
#[Locked] public string $path = '';
#[Locked] public array $stats;
/**
* Rendering of the front-end.
*
* @return View
*/
public function render(): View
{
Gate::authorize(SettingsPolicy::CAN_UPDATE, Configs::class);

$query = Album::query();

$this->stats = $query->countErrors();

return view('livewire.modules.maintenance.fix-tree');
}

/**
* Clean the path from all files excluding $this->skip.
*
* @return void
*/
public function do(): void
{
Gate::authorize(SettingsPolicy::CAN_UPDATE, Configs::class);

$query = Album::query();
$this->result = $query->fixTree();
}

/**
* Check whether there are files to be removed.
* If not, we will not display the module to reduce complexity.
*
* @return bool
*/
public function getNoErrorsFoundProperty(): bool
{
return 0 === ($this->stats['oddness'] ?? 0) + ($this->stats['duplicates'] ?? 0) + ($this->stats['wrong_parent'] ?? 0) + ($this->stats['missing_parent'] ?? 0);
}
}
8 changes: 8 additions & 0 deletions lang/cz/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/de/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/el/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/en/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/es/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/fr/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Supprimer le contenu de <span class="font-mono">%s</span>',
'button' => 'Nettoyer',
],
'fix-tree' => [
'title' => 'Statistique d’arbres',
'Oddness' => 'Imparité',
'Duplicates' => 'Duplicata',
'Wrong parents' => 'Mauvais parents',
'Missing parents' => 'Parents manquants',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimisation de la base de donnée',
'description' => 'Si vous remarquez que votre installation est devenue lente, il est possible que votre base de donnée n’ai pas les index requis.',
Expand Down
8 changes: 8 additions & 0 deletions lang/hu/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/it/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/nl/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/no/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/pl/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/pt/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/ru/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/sk/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/sv/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/vi/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/zh_CN/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
8 changes: 8 additions & 0 deletions lang/zh_TW/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
'description' => 'Remove all contents from <span class="font-mono">%s</span>',
'button' => 'Clean',
],
'fix-tree' => [
'title' => 'Tree statistics',
'Oddness' => 'Oddness',
'Duplicates' => 'Duplicates',
'Wrong parents' => 'Wrong parents',
'Missing parents' => 'Missing parents',
'button' => 'Fix tree',
],
'optimize' => [
'title' => 'Optimize Database',
'description' => 'If you notice slowdown in your installation, it may be because your database does not
Expand Down
11 changes: 11 additions & 0 deletions resources/views/livewire/modules/maintenance/fix-tree.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<x-maintenance.card :disabled="$this->no_errors_found && $result === null">
<x-maintenance.h1>{{ __('maintenance.fix-tree.title') }}</x-maintenance.h1>
<x-maintenance.p class=" !text-left">
{{ __('maintenance.fix-tree.Oddness') }}: {{ $stats['oddness'] }}<br/>
{{ __('maintenance.fix-tree.Duplicates') }}: {{ $stats['duplicates'] }}<br/>
{{ __('maintenance.fix-tree.Wrong parents') }}: {{ $stats['wrong_parent'] }}<br/>
{{ __('maintenance.fix-tree.Missing parents') }}: {{ $stats['missing_parent'] }}<br/>
</x-maintenance.p>
<x-maintenance.button wire:click="do">{{ __('maintenance.fix-tree.button') }}</x-maintenance.button>
<x-maintenance.loading />
</x-maintenance.card>
1 change: 1 addition & 0 deletions resources/views/livewire/pages/maintenance.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<livewire:modules.maintenance.cleaning :path="config('filesystems.disks.extract-jobs.root')" />
<livewire:modules.maintenance.cleaning :path="config('filesystems.disks.image-jobs.root')" />
<livewire:modules.maintenance.cleaning :path="config('filesystems.disks.livewire-upload.root')" />
<livewire:modules.maintenance.fix-tree />
</div>
</div>
</div>
Expand Down

0 comments on commit dc4aba9

Please sign in to comment.