Skip to content

Commit de216e2

Browse files
committed
add tags to hydrated data
1 parent fab7484 commit de216e2

9 files changed

Lines changed: 43 additions & 4 deletions

File tree

app/Actions/Albums/Flow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function getQuery(Album|null $base, bool $with_relations): AlbumBuilder
110110

111111
$base_query = Album::query();
112112
if ($with_relations) {
113-
$base_query->with(['cover', 'cover.size_variants', 'statistics', 'photos', 'photos.statistics', 'photos.size_variants', 'photos.palette']);
113+
$base_query->with(['cover', 'cover.size_variants', 'statistics', 'photos', 'photos.statistics', 'photos.size_variants', 'photos.palette', 'photos.tags']);
114114
}
115115

116116
// Only join what we need for ordering.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Contracts\PhotoCreate\SharedPipe;
1212
use App\DTO\PhotoCreate\DuplicateDTO;
1313
use App\DTO\PhotoCreate\StandaloneDTO;
14+
use App\Models\Tag;
1415

1516
/**
1617
* Hydrates meta-info of the media file from the
@@ -38,8 +39,7 @@ public function handle(DuplicateDTO|StandaloneDTO $state, \Closure $next): Dupli
3839
$state->photo->description = $state->exif_info->description;
3940
}
4041
if (count($state->photo->tags) === 0) {
41-
// TODO FIX ME.
42-
// $state->photo->tags = $state->exif_info->tags;
42+
$state->tags = Tag::from($state->exif_info->tags);
4343
}
4444
if ($state->photo->type === null) {
4545
$state->photo->type = $state->exif_info->type;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Save implements PhotoPipe
1919
public function handle(PhotoDTO $state, \Closure $next): PhotoDTO
2020
{
2121
$state->getPhoto()->save();
22+
$state->getPhoto()->tags()->sync($state->getTags()->pluck('id')->all());
2223

2324
return $next($state);
2425
}

app/Contracts/PhotoCreate/PhotoDTO.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
namespace App\Contracts\PhotoCreate;
1010

1111
use App\Models\Photo;
12+
use App\Models\Tag;
13+
use Illuminate\Support\Collection;
1214

1315
interface PhotoDTO
1416
{
1517
public function getPhoto(): Photo;
18+
19+
/**
20+
* @return Collection<int,Tag>
21+
*/
22+
public function getTags(): Collection;
1623
}

app/DTO/PhotoCreate/DuplicateDTO.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Contracts\PhotoCreate\PhotoDTO;
1313
use App\Metadata\Extractor;
1414
use App\Models\Photo;
15+
use Illuminate\Support\Collection;
1516

1617
/**
1718
* DTO used when dealing with duplicates.
@@ -21,6 +22,8 @@ class DuplicateDTO implements PhotoDTO
2122
{
2223
public bool $has_been_resynced;
2324

25+
public Collection $tags;
26+
2427
public function __construct(
2528
public readonly bool $shall_resync_metadata,
2629
public readonly bool $shall_skip_duplicates,
@@ -39,6 +42,7 @@ public function __construct(
3942
// During initial steps if duplicate is found, it will be placed here.
4043
public Photo $photo,
4144
) {
45+
$this->tags = $this->photo->tags;
4246
}
4347

4448
public static function ofInit(InitDTO $init_dto): DuplicateDTO
@@ -59,6 +63,11 @@ public function getPhoto(): Photo
5963
return $this->photo;
6064
}
6165

66+
public function getTags(): Collection
67+
{
68+
return $this->tags;
69+
}
70+
6271
public function setHasBeenResync(bool $val): void
6372
{
6473
$this->has_been_resynced = $val;

app/DTO/PhotoCreate/PhotoPartnerDTO.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Contracts\Image\StreamStats;
1212
use App\Contracts\PhotoCreate\PhotoDTO;
1313
use App\Models\Photo;
14+
use Illuminate\Support\Collection;
1415

1516
class PhotoPartnerDTO implements PhotoDTO
1617
{
@@ -27,4 +28,9 @@ public function getPhoto(): Photo
2728
{
2829
return $this->photo;
2930
}
31+
32+
public function getTags(): Collection
33+
{
34+
return $this->photo->tags;
35+
}
3036
}

app/DTO/PhotoCreate/StandaloneDTO.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use App\Image\Files\TemporaryLocalFile;
1919
use App\Metadata\Extractor;
2020
use App\Models\Photo;
21+
use Illuminate\Support\Collection;
2122

2223
class StandaloneDTO implements PhotoDTO
2324
{
@@ -27,6 +28,7 @@ class StandaloneDTO implements PhotoDTO
2728
public FlysystemFile $target_file;
2829
public StreamStats|null $stream_stat;
2930
public FlysystemFile|null $backup_file = null;
31+
public Collection $tags;
3032

3133
public function __construct(
3234
// The resulting photo
@@ -44,6 +46,7 @@ public function __construct(
4446
public readonly bool $shall_import_via_symlink,
4547
public readonly bool $shall_delete_imported,
4648
) {
49+
$this->tags = new Collection();
4750
}
4851

4952
public static function ofInit(InitDTO $init_dto): StandaloneDTO
@@ -64,4 +67,9 @@ public function getPhoto(): Photo
6467
{
6568
return $this->photo;
6669
}
70+
71+
public function getTags(): Collection
72+
{
73+
return $this->tags;
74+
}
6775
}

app/DTO/PhotoCreate/VideoPartnerDTO.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Contracts\PhotoCreate\PhotoDTO;
1313
use App\Image\Files\BaseMediaFile;
1414
use App\Models\Photo;
15+
use Illuminate\Support\Collection;
1516

1617
class VideoPartnerDTO implements PhotoDTO
1718
{
@@ -32,6 +33,11 @@ public function getPhoto(): Photo
3233
return $this->photo;
3334
}
3435

36+
public function getTags(): Collection
37+
{
38+
return $this->photo->tags;
39+
}
40+
3541
public static function ofInit(InitDTO $init_dto): VideoPartnerDTO
3642
{
3743
return new VideoPartnerDTO(

app/Image/Handlers/GoogleMotionPictureHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class GoogleMotionPictureHandler extends VideoHandler
5151
*/
5252
public function __destruct()
5353
{
54-
$this->working_copy->delete();
54+
if (isset($this->working_copy)) {
55+
$this->working_copy->delete();
56+
}
5557
}
5658

5759
/**

0 commit comments

Comments
 (0)