Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions app/Actions/Album/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
use App\Models\BaseAlbumImpl;
use App\Models\Statistics;
use App\Models\TagAlbum;
use App\SmartAlbums\UnsortedAlbum;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Support\Facades\Auth;
use Safe\Exceptions\ArrayException;

/**
Expand Down Expand Up @@ -73,18 +71,6 @@ class Delete
public function do(array $album_ids): FileDeleter
{
try {
$unsorted_photo_ids = [];

// Among the smart albums, the unsorted album is special,
// because it provides deletion of photos
if (in_array(UnsortedAlbum::ID, $album_ids, true)) {
$query = UnsortedAlbum::getInstance()->photos();
if (Auth::user()?->may_administrate !== true) {
$query->where('owner_id', '=', Auth::id() ?? throw new UnauthenticatedException());
}
$unsorted_photo_ids = $query->pluck('id')->all();
}

// Only regular albums are owners of photos, so we only need to
// find all photos in those and their descendants
// Only load necessary attributes for tree; in particular avoid
Expand All @@ -111,7 +97,7 @@ public function do(array $album_ids): FileDeleter

// Delete the photos from DB and obtain the list of files which need
// to be deleted later
$file_deleter = (new PhotoDelete())->do($unsorted_photo_ids, $recursive_album_ids);
$file_deleter = (new PhotoDelete())->do([], null, $recursive_album_ids);
$file_deleter->addFiles($recursive_album_tracks, StorageDiskType::LOCAL->value);

// Remove the sub-forest spanned by the regular albums
Expand Down
29 changes: 24 additions & 5 deletions app/Actions/Album/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

namespace App\Actions\Album;

use App\Constants\PhotoAlbum as PA;
use App\Exceptions\Internal\QueryBuilderException;
use App\Exceptions\ModelDBException;
use App\Models\Album;
use App\Models\Photo;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class Merge
{
Expand All @@ -27,10 +28,28 @@ class Merge
*/
public function do(Album $target_album, Collection $albums): void
{
// Merge photos of source albums into target
Photo::query()
->whereIn('album_id', $albums->pluck('id'))
->update(['album_id' => $target_album->id]);
$origin_ids = $albums->pluck('id')->all();

// Select all photos ids of the source albums
$photos_ids = DB::table(PA::PHOTO_ALBUM)
->whereIn(PA::ALBUM_ID, $origin_ids)
->pluck(PA::PHOTO_ID)->all();

// Delete the existing links at destination (avoid duplicates key contraint)
DB::table(PA::PHOTO_ALBUM)
->whereIn(PA::PHOTO_ID, $photos_ids)
->where(PA::ALBUM_ID, '=', $target_album->id)
->delete();

// Insert the new links
DB::table(PA::PHOTO_ALBUM)
->insert(array_map(fn (string $id) => ['photo_id' => $id, 'album_id' => $target_album->id], $photos_ids));

// Delete the existing links from the origins
DB::table(PA::PHOTO_ALBUM)
->whereIn(PA::PHOTO_ID, $photos_ids)
->whereIn(PA::ALBUM_ID, $origin_ids)
->delete();

// Merge sub-albums of source albums into target
/** @var Album $album */
Expand Down
6 changes: 3 additions & 3 deletions app/Actions/Album/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Enum\SizeVariantType;
use App\Http\Resources\Collections\PositionDataResource;
use App\Models\Album;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class PositionData
Expand All @@ -25,7 +25,7 @@ public function get(AbstractAlbum $album, bool $include_sub_albums = false): Pos

$photo_relation
->with([
'album' => function (BelongsTo $b): void {
'albums' => function (BelongsToMany $b): void {
// The album is required for photos to properly
// determine access and visibility rights; but we
// don't need to determine the cover and thumbnail for
Expand All @@ -46,6 +46,6 @@ public function get(AbstractAlbum $album, bool $include_sub_albums = false): Pos
->whereNotNull('latitude')
->whereNotNull('longitude');

return new PositionDataResource($album->get_id(), $album->get_title(), $photo_relation->get(), $album instanceof Album ? $album->track_url : null);
return new PositionDataResource($album, $photo_relation->get(), $album instanceof Album ? $album->track_url : null);
}
}
5 changes: 3 additions & 2 deletions app/Actions/Albums/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function do(): PositionDataResource
$photo_query = $this->photo_query_policy->applySearchabilityFilter(
query: Photo::query()
->with([
'album' => function ($b): void {
// TODO: FIX ME.
'albums' => function ($b): void {
// The album is required for photos to properly
// determine access and visibility rights; but we
// don't need to determine the cover and thumbnail for
Expand All @@ -62,6 +63,6 @@ public function do(): PositionDataResource
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_map')
);

return new PositionDataResource(null, null, $photo_query->get(), null);
return new PositionDataResource(null, $photo_query->get(), null);
}
}
6 changes: 3 additions & 3 deletions app/Actions/Diagnostics/Pipes/Checks/DBIntegrityCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function handle(array &$data, \Closure $next): array

$sub_join = DB::table('size_variants')->where('size_variants.type', '=', 0);
$photos = Photo::query()
->with(['album'])
->select(['photos.id', 'title', 'album_id'])
->with(['albums'])
->select(['photos.id', 'title'])
->joinSub($sub_join, 'size_variants', 'size_variants.photo_id', '=', 'photos.id', 'left')
->whereNull('size_variants.id')
->get();

foreach ($photos as $photo) {
$data[] = DiagnosticData::error('Photo without Original found -- ' . $photo->title . ' in ' . ($photo->album?->title ?? __('gallery.smart_album.unsorted')), self::class);
$data[] = DiagnosticData::error('Photo without Original found -- ' . $photo->title . ' in ' . ($photo->albums?->first()?->title ?? __('gallery.smart_album.unsorted')), self::class);
}

return $next($data);
Expand Down
9 changes: 5 additions & 4 deletions app/Actions/Photo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ private function handleDuplicate(InitDTO $init_dto): Photo
$pipes[] = Duplicate\SaveIfDirty::class;
}
$pipes[] = Duplicate\ThrowSkipDuplicate::class;
$pipes[] = Duplicate\ReplicateAsPhoto::class;
$pipes[] = Shared\SetStarred::class;
$pipes[] = Shared\SetParentAndOwnership::class;
$pipes[] = Shared\Save::class;
$pipes[] = Shared\SetParent::class;
$pipes[] = Shared\SaveStatistics::class;
$pipes[] = Shared\NotifyAlbums::class;

Expand All @@ -167,14 +166,15 @@ private function handleStandalone(InitDTO $init_dto): Photo
Standalone\InitNamingStrategy::class,
Shared\HydrateMetadata::class,
Shared\SetStarred::class,
Shared\SetParentAndOwnership::class,
Shared\SetOwnership::class,
Standalone\SetOriginalChecksum::class,
Standalone\FetchSourceImage::class,
Standalone\ExtractGoogleMotionPictures::class,
Standalone\PlacePhoto::class,
Standalone\PlaceGoogleMotionVideo::class,
Standalone\SetChecksum::class,
Shared\Save::class,
Shared\SetParent::class,
Shared\SaveStatistics::class,
Standalone\CreateOriginalSizeVariant::class,
Standalone\CreateSizeVariants::class,
Expand Down Expand Up @@ -257,14 +257,15 @@ private function handlePhotoLivePartner(InitDTO $init_dto): Photo
Standalone\InitNamingStrategy::class,
Shared\HydrateMetadata::class,
Shared\SetStarred::class,
Shared\SetParentAndOwnership::class,
Shared\SetOwnership::class,
Standalone\SetOriginalChecksum::class,
Standalone\FetchSourceImage::class,
Standalone\ExtractGoogleMotionPictures::class,
Standalone\PlacePhoto::class,
Standalone\PlaceGoogleMotionVideo::class,
Standalone\SetChecksum::class,
Shared\Save::class,
Shared\SetParent::class,
Standalone\CreateOriginalSizeVariant::class,
Standalone\CreateSizeVariants::class,
Standalone\EncodePlaceholder::class,
Expand Down
Loading