mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
parent
f1e1a745b0
commit
4e82d93350
@ -14,8 +14,8 @@ class CleanupImages extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'bookstack:cleanup-images
|
protected $signature = 'bookstack:cleanup-images
|
||||||
{--a|all : Include images that are used in page revisions}
|
{--a|all : Also delete images that are only used in old revisions}
|
||||||
{--f|force : Actually run the deletions}
|
{--f|force : Actually run the deletions, Defaults to a dry-run}
|
||||||
';
|
';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,22 +304,19 @@ class ImageService
|
|||||||
* Could be much improved to be more specific but kept it generic for now to be safe.
|
* Could be much improved to be more specific but kept it generic for now to be safe.
|
||||||
*
|
*
|
||||||
* Returns the path of the images that would be/have been deleted.
|
* Returns the path of the images that would be/have been deleted.
|
||||||
* @param bool $checkRevisions
|
|
||||||
* @param bool $dryRun
|
|
||||||
* @param array $types
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function deleteUnusedImages($checkRevisions = true, $dryRun = true, $types = ['gallery', 'drawio'])
|
public function deleteUnusedImages(bool $checkRevisions = true, bool $dryRun = true)
|
||||||
{
|
{
|
||||||
$types = array_intersect($types, ['gallery', 'drawio']);
|
$types = ['gallery', 'drawio'];
|
||||||
$deletedPaths = [];
|
$deletedPaths = [];
|
||||||
|
|
||||||
$this->image->newQuery()->whereIn('type', $types)
|
$this->image->newQuery()->whereIn('type', $types)
|
||||||
->chunk(1000, function ($images) use ($types, $checkRevisions, &$deletedPaths, $dryRun) {
|
->chunk(1000, function ($images) use ($checkRevisions, &$deletedPaths, $dryRun) {
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$searchQuery = '%' . basename($image->path) . '%';
|
$searchQuery = '%' . basename($image->path) . '%';
|
||||||
$inPage = DB::table('pages')
|
$inPage = DB::table('pages')
|
||||||
->where('html', 'like', $searchQuery)->count() > 0;
|
->where('html', 'like', $searchQuery)->count() > 0;
|
||||||
|
|
||||||
$inRevision = false;
|
$inRevision = false;
|
||||||
if ($checkRevisions) {
|
if ($checkRevisions) {
|
||||||
$inRevision = DB::table('page_revisions')
|
$inRevision = DB::table('page_revisions')
|
||||||
|
@ -68,7 +68,7 @@ return [
|
|||||||
'maint' => 'Maintenance',
|
'maint' => 'Maintenance',
|
||||||
'maint_image_cleanup' => 'Cleanup Images',
|
'maint_image_cleanup' => 'Cleanup Images',
|
||||||
'maint_image_cleanup_desc' => "Scans page & revision content to check which images and drawings are currently in use and which images are redundant. Ensure you create a full database and image backup before running this.",
|
'maint_image_cleanup_desc' => "Scans page & revision content to check which images and drawings are currently in use and which images are redundant. Ensure you create a full database and image backup before running this.",
|
||||||
'maint_image_cleanup_ignore_revisions' => 'Ignore images in revisions',
|
'maint_delete_images_only_in_revisions' => 'Also delete images that only exist in old page revisions',
|
||||||
'maint_image_cleanup_run' => 'Run Cleanup',
|
'maint_image_cleanup_run' => 'Run Cleanup',
|
||||||
'maint_image_cleanup_warning' => ':count potentially unused images were found. Are you sure you want to delete these images?',
|
'maint_image_cleanup_warning' => ':count potentially unused images were found. Are you sure you want to delete these images?',
|
||||||
'maint_image_cleanup_success' => ':count potentially unused images found and deleted!',
|
'maint_image_cleanup_success' => ':count potentially unused images found and deleted!',
|
||||||
|
@ -41,9 +41,9 @@
|
|||||||
<input type="hidden" name="ignore_revisions" value="{{ session()->getOldInput('ignore_revisions', 'false') }}">
|
<input type="hidden" name="ignore_revisions" value="{{ session()->getOldInput('ignore_revisions', 'false') }}">
|
||||||
<input type="hidden" name="confirm" value="true">
|
<input type="hidden" name="confirm" value="true">
|
||||||
@else
|
@else
|
||||||
<label>
|
<label class="flex-container-row">
|
||||||
<input type="checkbox" name="ignore_revisions" value="true">
|
<div class="mr-s"><input type="checkbox" name="ignore_revisions" value="true"></div>
|
||||||
{{ trans('settings.maint_image_cleanup_ignore_revisions') }}
|
<div>{{ trans('settings.maint_delete_images_only_in_revisions') }}</div>
|
||||||
</label>
|
</label>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user