) {
}
+ public function runBookAutoSortForAllWithSet(SortSet $set): void
+ {
+ $set->books()->chunk(50, function ($books) {
+ foreach ($books as $book) {
+ $this->runBookAutoSort($book);
+ }
+ });
+ }
+
/**
* Runs the auto-sort for a book if the book has a sort set applied to it.
* This does not consider permissions since the sort operations are centrally
return view('settings.sort-sets.edit', ['set' => $set]);
}
- public function update(string $id, Request $request)
+ public function update(string $id, Request $request, BookSorter $bookSorter)
{
$this->validate($request, [
'name' => ['required', 'string', 'min:1', 'max:200'],
$set->name = $request->input('name');
$set->setOperations($operations);
+ $changedSequence = $set->isDirty('sequence');
$set->save();
$this->logActivity(ActivityType::SORT_SET_UPDATE, $set);
+ if ($changedSequence) {
+ $bookSorter->runBookAutoSortForAllWithSet($set);
+ }
+
return redirect('/settings/sorting');
}
- public function destroy(string $id)
+ public function destroy(string $id, Request $request)
{
$set = SortSet::query()->findOrFail($id);
-
- if ($set->books()->count() > 0) {
- $this->showErrorNotification(trans('settings.sort_set_delete_fail_books'));
- return redirect($set->getUrl());
+ $confirmed = $request->input('confirm') === 'true';
+ $booksAssigned = $set->books()->count();
+ $warnings = [];
+
+ if ($booksAssigned > 0) {
+ if ($confirmed) {
+ $set->books()->update(['sort_set_id' => null]);
+ } else {
+ $warnings[] = trans('settings.sort_set_delete_warn_books', ['count' => $booksAssigned]);
+ }
}
$defaultBookSortSetting = intval(setting('sorting-book-default', '0'));
if ($defaultBookSortSetting === intval($id)) {
- $this->showErrorNotification(trans('settings.sort_set_delete_fail_default'));
- return redirect($set->getUrl());
+ if ($confirmed) {
+ setting()->remove('sorting-book-default');
+ } else {
+ $warnings[] = trans('settings.sort_set_delete_warn_default');
+ }
+ }
+
+ if (count($warnings) > 0) {
+ return redirect($set->getUrl() . '#delete')->withErrors(['delete' => $warnings]);
}
$set->delete();
'sort_set_create' => 'Create Sort Set',
'sort_set_edit' => 'Edit Sort Set',
'sort_set_delete' => 'Delete Sort Set',
- 'sort_set_delete_desc' => 'Remove this sort set from the system. Deletion will only go ahead if the sort is not in active use.',
- 'sort_set_delete_fail_books' => 'Unable to delete this sort set since it has books assigned.',
- 'sort_set_delete_fail_default' => 'Unable to delete this sort set since it\'s used as the default book sort.',
+ 'sort_set_delete_desc' => 'Remove this sort set from the system. Books using this sort will revert to manual sorting.',
+ 'sort_set_delete_warn_books' => 'This sort set is currently used on :count book(s). Are you sure you want to delete this?',
+ 'sort_set_delete_warn_default' => 'This sort set is currently used as the default for books. Are you sure you want to delete this?',
'sort_set_details' => 'Sort Set Details',
'sort_set_details_desc' => 'Set a name for this sort set, which will appear in lists when users are selecting a sort.',
'sort_set_operations' => 'Sort Operations',
@extends('settings.layout')
@php
- $sortSets = \BookStack\Sorting\SortSet::query()->orderBy('name', 'asc')->get();
+ $sortSets = \BookStack\Sorting\SortSet::query()
+ ->withCount('books')
+ ->orderBy('name', 'asc')
+ ->get();
@endphp
@section('card')
</form>
</div>
- <div class="card content-wrap auto-height">
+ <div id="delete" class="card content-wrap auto-height">
<div class="flex-container-row items-center gap-l">
- <div>
+ <div class="mb-m">
<h2 class="list-heading">{{ trans('settings.sort_set_delete') }}</h2>
- <p class="text-muted">{{ trans('settings.sort_set_delete_desc') }}</p>
+ <p class="text-muted mb-xs">{{ trans('settings.sort_set_delete_desc') }}</p>
+ @if($errors->has('delete'))
+ @foreach($errors->get('delete') as $error)
+ <p class="text-neg mb-xs">{{ $error }}</p>
+ @endforeach
+ @endif
</div>
<div class="flex">
<form action="{{ $set->getUrl() }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
+
+ @if($errors->has('delete'))
+ <input type="hidden" name="confirm" value="true">
+ @endif
+
<div class="text-right">
<button type="submit" class="button outline">{{ trans('common.delete') }}</button>
</div>
-<div class="item-list-row flex-container-row py-xs items-center">
- <div class="py-xs px-m flex-2">
+<div class="item-list-row flex-container-row py-xs px-m gap-m items-center">
+ <div class="py-xs flex">
<a href="{{ $set->getUrl() }}">{{ $set->name }}</a>
</div>
- <div class="px-m text-small text-muted">
+ <div class="px-m text-small text-muted ml-auto">
{{ implode(', ', array_map(fn ($op) => $op->getLabel(), $set->getOperations())) }}
</div>
+ <div>
+ <span title="{{ trans('entities.tags_assigned_books') }}"
+ class="flex fill-area min-width-xxs bold text-right text-book"><span class="opacity-60">@icon('book')</span>{{ $set->books_count ?? 0 }}</span>
+ </div>
</div>
\ No newline at end of file