Allow artworks to have one primary category and extra secondaries.
Keep artwork_category as membership, store a deterministic primary_category_id, and let upload plus studio pick up to five additional same-type categories without changing canonical URLs.
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Models\Group;
|
||||
use App\Jobs\IndexArtworkJob;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use App\Services\Artworks\ArtworkCategoryService;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -23,6 +24,7 @@ class GroupArtworkReviewService
|
||||
private readonly GroupHistoryService $history,
|
||||
private readonly NotificationService $notifications,
|
||||
private readonly GroupMembershipService $memberships,
|
||||
private readonly ArtworkCategoryService $artworkCategories,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -108,6 +110,10 @@ class GroupArtworkReviewService
|
||||
'group_reviewed_at' => now(),
|
||||
'group_review_notes' => $notes,
|
||||
'is_approved' => true,
|
||||
'approval_source' => 'moderator',
|
||||
'moderated_at' => now(),
|
||||
'moderated_by' => $actor->id,
|
||||
'moderation_note' => $notes,
|
||||
'artwork_status' => 'published',
|
||||
'published_at' => now(),
|
||||
'publish_at' => null,
|
||||
@@ -363,9 +369,20 @@ class GroupArtworkReviewService
|
||||
$artwork->uploaded_by_user_id = $artwork->uploaded_by_user_id ?: (int) $actor->id;
|
||||
$artwork->primary_author_user_id = $artwork->primary_author_user_id ?: (int) $actor->id;
|
||||
|
||||
$categoryId = isset($validated['category']) ? (int) $validated['category'] : null;
|
||||
if ($categoryId > 0 && Category::query()->where('id', $categoryId)->exists()) {
|
||||
$artwork->categories()->sync([$categoryId]);
|
||||
$categoryId = isset($validated['primary_category_id'])
|
||||
? (int) $validated['primary_category_id']
|
||||
: (isset($validated['category']) ? (int) $validated['category'] : null);
|
||||
$secondaryCategoryIds = array_key_exists('secondary_category_ids', $validated)
|
||||
? array_values(array_map('intval', (array) $validated['secondary_category_ids']))
|
||||
: [];
|
||||
if ($categoryId > 0) {
|
||||
$this->artworkCategories->sync(
|
||||
$artwork,
|
||||
$categoryId,
|
||||
$secondaryCategoryIds,
|
||||
'user',
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('tags', $validated) && is_array($validated['tags'])) {
|
||||
@@ -395,4 +412,4 @@ class GroupArtworkReviewService
|
||||
{
|
||||
IndexArtworkJob::dispatch((int) $artwork->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user