-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module to fix the missing file sizes from size variants (#2354)
- Loading branch information
Showing
21 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
app/Livewire/Components/Modules/Maintenance/MissingFileSizes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Components\Modules\Maintenance; | ||
|
||
use App\Livewire\Traits\Notify; | ||
use App\Models\Configs; | ||
use App\Models\SizeVariant; | ||
use App\Policies\SettingsPolicy; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
/** | ||
* We may be missing some file sizes because of generation problems, | ||
* transfer of files, or other. | ||
* This module aims to solve this issue. | ||
*/ | ||
class MissingFileSizes extends Component | ||
{ | ||
use Notify; | ||
|
||
/** | ||
* Mount depending of the path. | ||
* | ||
* @return void | ||
*/ | ||
public function mount(): void | ||
{ | ||
Gate::authorize(SettingsPolicy::CAN_UPDATE, Configs::class); | ||
} | ||
|
||
/** | ||
* Rendering of the front-end. | ||
* | ||
* @return View | ||
*/ | ||
public function render(): View | ||
{ | ||
Gate::authorize(SettingsPolicy::CAN_UPDATE, Configs::class); | ||
|
||
return view('livewire.modules.maintenance.fill-filesize-sizevariants'); | ||
} | ||
|
||
/** | ||
* Fetch the file size of existing size variants when the data is not in the DB | ||
* Process by chunks of 500. | ||
* | ||
* @return void | ||
*/ | ||
public function do(): void | ||
{ | ||
Gate::authorize(SettingsPolicy::CAN_UPDATE, Configs::class); | ||
|
||
$variants_query = SizeVariant::query() | ||
->where('filesize', '=', 0) | ||
// TODO: remove s3 support here. | ||
->orderBy('id'); | ||
// Internally, only holds $limit entries at once | ||
$variants = $variants_query->lazyById(500); | ||
|
||
$generated = 0; | ||
|
||
foreach ($variants as $variant) { | ||
$variantFile = $variant->getFile(); | ||
if ($variantFile->exists()) { | ||
$variant->filesize = $variantFile->getFilesize(); | ||
if (!$variant->save()) { | ||
Log::error('Failed to update filesize for ' . $variantFile->getRelativePath() . '.'); | ||
} else { | ||
$generated++; | ||
} | ||
} else { | ||
Log::error('No file found at ' . $variantFile->getRelativePath() . '.'); | ||
} | ||
} | ||
|
||
$this->notify(sprintf(__('maintenance.fill-filesize-sizevariants.success'), $generated)); | ||
} | ||
|
||
/** | ||
* Check how many images needs to be created. | ||
* | ||
* @return int | ||
*/ | ||
public function getNumberOfMissingSizeProperty(): int | ||
{ | ||
return SizeVariant::query() | ||
->where('filesize', '=', 0) | ||
// TODO: remove s3 support here. | ||
->count(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
resources/views/livewire/modules/maintenance/fill-filesize-sizevariants.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<x-maintenance.card :disabled="$this->number_of_missing_size <= 0"> | ||
<x-maintenance.h1>{{ __('maintenance.fill-filesize-sizevariants.title') }}</x-maintenance.h1> | ||
<x-maintenance.p>{!! sprintf(__('maintenance.fill-filesize-sizevariants.description'), $this->number_of_missing_size) !!}</x-maintenance.p> | ||
<x-maintenance.button wire:click="do">{{ __('maintenance.fill-filesize-sizevariants.button') }}</x-maintenance.button> | ||
<x-maintenance.loading /> | ||
</x-maintenance.card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters