Skip to content

Commit cbc389b

Browse files
committed
more progress
1 parent 337c381 commit cbc389b

17 files changed

Lines changed: 125 additions & 62 deletions

File tree

app/Actions/Album/Merge.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use App\Exceptions\Internal\QueryBuilderException;
1313
use App\Exceptions\ModelDBException;
1414
use App\Models\Album;
15-
use App\Models\Photo;
1615
use Illuminate\Database\Eloquent\ModelNotFoundException;
1716
use Illuminate\Support\Collection;
1817
use Illuminate\Support\Facades\DB;
@@ -35,7 +34,7 @@ public function do(Album $target_album, Collection $albums): void
3534
$photos_ids = DB::table(PA::PHOTO_ALBUM)
3635
->whereIn(PA::ALBUM_ID, $origin_ids)
3736
->pluck(PA::PHOTO_ID)->all();
38-
37+
3938
// Delete the existing links at destination (avoid duplicates key contraint)
4039
DB::table(PA::PHOTO_ALBUM)
4140
->whereIn(PA::PHOTO_ID, $photos_ids)

app/Actions/Album/PositionData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function get(AbstractAlbum $album, bool $include_sub_albums = false): Pos
2525

2626
$photo_relation
2727
->with([
28-
'album' => function (BelongsTo $b): void {
28+
'albums' => function (BelongsTo $b): void {
2929
// The album is required for photos to properly
3030
// determine access and visibility rights; but we
3131
// don't need to determine the cover and thumbnail for

app/Actions/Albums/PositionData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function do(): PositionDataResource
3939
query: Photo::query()
4040
->with([
4141
// TODO: FIX ME.
42-
'album' => function ($b): void {
42+
'albums' => function ($b): void {
4343
// The album is required for photos to properly
4444
// determine access and visibility rights; but we
4545
// don't need to determine the cover and thumbnail for

app/Actions/Metrics/GetMetrics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function get(): Collection
2121
/** @var User $user */
2222
$user = Auth::user() ?? throw new UnauthorizedException();
2323

24-
return LiveMetrics::query()->with(['photo', 'photo.size_variants', 'album', 'album_impl', 'album.thumb'])
24+
return LiveMetrics::query()->with(['photo', 'photo.size_variants', 'albums', 'album_impl', 'album.thumb'])
2525
->join('photos', 'photos.id', '=', 'live_metrics.photo_id', 'left')
2626
->join('base_albums', 'base_albums.id', '=', 'live_metrics.album_id', 'left')
2727
->join('albums', 'albums.id', '=', 'live_metrics.album_id', 'left')

app/Actions/Photo/Create.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ private function handleDuplicate(InitDTO $init_dto): Photo
141141
$pipes[] = Duplicate\ThrowSkipDuplicate::class;
142142
$pipes[] = Duplicate\ReplicateAsPhoto::class;
143143
$pipes[] = Shared\SetStarred::class;
144-
$pipes[] = Shared\SetParentAndOwnership::class;
144+
$pipes[] = Shared\SetOwnership::class;
145145
$pipes[] = Shared\Save::class;
146+
$pipes[] = Shared\SetParent::class;
146147
$pipes[] = Shared\SaveStatistics::class;
147148
$pipes[] = Shared\NotifyAlbums::class;
148149

@@ -167,14 +168,15 @@ private function handleStandalone(InitDTO $init_dto): Photo
167168
Standalone\InitNamingStrategy::class,
168169
Shared\HydrateMetadata::class,
169170
Shared\SetStarred::class,
170-
Shared\SetParentAndOwnership::class,
171+
Shared\SetOwnership::class,
171172
Standalone\SetOriginalChecksum::class,
172173
Standalone\FetchSourceImage::class,
173174
Standalone\ExtractGoogleMotionPictures::class,
174175
Standalone\PlacePhoto::class,
175176
Standalone\PlaceGoogleMotionVideo::class,
176177
Standalone\SetChecksum::class,
177178
Shared\Save::class,
179+
Shared\SetParent::class,
178180
Shared\SaveStatistics::class,
179181
Standalone\CreateOriginalSizeVariant::class,
180182
Standalone\CreateSizeVariants::class,
@@ -257,14 +259,15 @@ private function handlePhotoLivePartner(InitDTO $init_dto): Photo
257259
Standalone\InitNamingStrategy::class,
258260
Shared\HydrateMetadata::class,
259261
Shared\SetStarred::class,
260-
Shared\SetParentAndOwnership::class,
262+
Shared\SetOwnership::class,
261263
Standalone\SetOriginalChecksum::class,
262264
Standalone\FetchSourceImage::class,
263265
Standalone\ExtractGoogleMotionPictures::class,
264266
Standalone\PlacePhoto::class,
265267
Standalone\PlaceGoogleMotionVideo::class,
266268
Standalone\SetChecksum::class,
267269
Shared\Save::class,
270+
Shared\SetParent::class,
268271
Standalone\CreateOriginalSizeVariant::class,
269272
Standalone\CreateSizeVariants::class,
270273
Standalone\EncodePlaceholder::class,

app/Actions/Photo/MoveOrDuplicate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class MoveOrDuplicate
1919
{
2020
/**
2121
* Move or Duplicates a set of photos.
22-
*
22+
*
2323
* If $from_album = $to_album, this is a duplication.
2424
* If $from_album != $to_album, this is a move.
2525
*
26-
* @param Collection<int,Photo> $photos the source photos
26+
* @param Collection<int,Photo> $photos the source photos
2727
* @param Album $from_album the origin album; `null` means root album
28-
* @param Album $to_album the destination album; `null` means root album
28+
* @param Album $to_album the destination album; `null` means root album
2929
*
3030
* @return void
3131
*/
@@ -50,7 +50,7 @@ public function do(Collection $photos, ?Album $from_album, ?Album $to_album): vo
5050
// Add the new links.
5151
DB::table(PA::PHOTO_ALBUM)->insert(array_map(fn (string $id) => ['photo_id' => $id, 'album_id' => $to_album->id], $photos_ids));
5252
}
53-
53+
5454
// In case of move, we need to remove the header_id of said photos.
5555
if ($from_album !== null && $from_album->id !== $to_album?->id) {
5656
Album::query()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Actions\Photo\Pipes\Shared;
10+
11+
use App\Contracts\PhotoCreate\SharedPipe;
12+
use App\DTO\PhotoCreate\DuplicateDTO;
13+
use App\DTO\PhotoCreate\StandaloneDTO;
14+
use App\Models\Album;
15+
16+
class SetOwnership implements SharedPipe
17+
{
18+
public function handle(DuplicateDTO|StandaloneDTO $state, \Closure $next): DuplicateDTO|StandaloneDTO
19+
{
20+
$state->photo->owner_id = $state->album instanceof Album ? $state->album->owner_id : $state->intended_owner_id;
21+
22+
return $next($state);
23+
}
24+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Actions\Photo\Pipes\Shared;
10+
11+
use App\Constants\PhotoAlbum as PA;
12+
use App\Contracts\PhotoCreate\SharedPipe;
13+
use App\DTO\PhotoCreate\DuplicateDTO;
14+
use App\DTO\PhotoCreate\StandaloneDTO;
15+
use App\Exceptions\Internal\LycheeLogicException;
16+
use App\Models\Album;
17+
use Illuminate\Support\Facades\DB;
18+
19+
/**
20+
* This MUST be called after a first save() otherwise we do not have a photo id.
21+
*/
22+
class SetParent implements SharedPipe
23+
{
24+
public function handle(DuplicateDTO|StandaloneDTO $state, \Closure $next): DuplicateDTO|StandaloneDTO
25+
{
26+
if ($state->album instanceof Album) {
27+
if ($state->photo->id === null) {
28+
throw new LycheeLogicException('Photo Id is null, cannot set a parent album.');
29+
}
30+
31+
// Avoid duplicates key constraint
32+
DB::table(PA::PHOTO_ALBUM)
33+
->where(PA::PHOTO_ID, '=', $state->photo->id)
34+
->where(PA::ALBUM_ID, '=', $state->album->id)
35+
->delete();
36+
37+
// Insert the new link
38+
DB::table(PA::PHOTO_ALBUM)
39+
->insert([
40+
'photo_id' => $state->photo->id,
41+
'album_id' => $state->album->id,
42+
]);
43+
44+
// Avoid unnecessary DB request, when we access the album of a
45+
// photo later (e.g. when a notification is sent).
46+
$state->photo->load('albums');
47+
}
48+
49+
return $next($state);
50+
}
51+
}

app/Actions/Photo/Pipes/Shared/SetParentAndOwnership.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/Actions/RSS/Generate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function do(): Collection
7777
/** @var Collection<int,Photo> $photos */
7878
$photos = $this->photo_query_policy
7979
->applySearchabilityFilter(
80-
query: Photo::query()->with(['album', 'owner', 'size_variants']),
80+
query: Photo::query()->with(['albums', 'owner', 'size_variants']),
8181
origin: null,
8282
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_rss')
8383
)

0 commit comments

Comments
 (0)