Skip to content

Commit b611f23

Browse files
authored
Fix propagation not happening (#3933)
1 parent 856f372 commit b611f23

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use App\Contracts\PhotoCreate\PhotoDTO;
1212
use App\Contracts\PhotoCreate\PhotoPipe;
13-
use App\Events\PhotoSaved;
1413

1514
/**
1615
* Persist current Photo object into database.
@@ -22,9 +21,6 @@ public function handle(PhotoDTO $state, \Closure $next): PhotoDTO
2221
$state->getPhoto()->save();
2322
$state->getPhoto()->tags()->sync($state->getTags()->pluck('id')->all());
2423

25-
// Dispatch event for album stats recomputation
26-
PhotoSaved::dispatch($state->getPhoto()->id);
27-
2824
return $next($state);
2925
}
3026
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Contracts\PhotoCreate\SharedPipe;
1313
use App\DTO\PhotoCreate\DuplicateDTO;
1414
use App\DTO\PhotoCreate\StandaloneDTO;
15+
use App\Events\PhotoSaved;
1516
use App\Exceptions\Internal\LycheeLogicException;
1617
use App\Models\Album;
1718
use Illuminate\Support\Facades\DB;
@@ -44,6 +45,10 @@ public function handle(DuplicateDTO|StandaloneDTO $state, \Closure $next): Dupli
4445
// Avoid unnecessary DB request, when we access the album of a
4546
// photo later (e.g. when a notification is sent).
4647
$state->photo->load('albums');
48+
49+
// Dispatch event for album stats recomputation
50+
// This must be done after SetParent so the photo_album relationship exists
51+
PhotoSaved::dispatch($state->photo->id);
4752
}
4853

4954
return $next($state);

tests/ImageProcessing/Photo/PhotoAddTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
namespace Tests\ImageProcessing\Photo;
2020

21+
use App\Jobs\RecomputeAlbumSizeJob;
22+
use App\Jobs\RecomputeAlbumStatsJob;
23+
use Illuminate\Support\Facades\Queue;
2124
use Tests\Constants\TestConstants;
2225
use Tests\Feature_v2\Base\BaseApiWithDataTest;
2326

@@ -159,4 +162,32 @@ public function testGoogleMotionPicture(): void
159162
$response = $this->deleteJson('Photo', ['photo_ids' => [$id], 'from_id' => 'unsorted']);
160163
$this->assertNoContent($response);
161164
}
165+
166+
public function testPhotoUploadDispatchesJobs(): void
167+
{
168+
// Fake only the recompute jobs, not the ProcessImageJob
169+
// This allows the photo upload to complete while capturing the recompute job dispatches
170+
Queue::fake([
171+
RecomputeAlbumStatsJob::class,
172+
RecomputeAlbumSizeJob::class,
173+
]);
174+
175+
$this->catchFailureSilence = [];
176+
177+
// Upload a photo to an album
178+
$response = $this->actingAs($this->admin)->upload('Photo', filename: TestConstants::SAMPLE_FILE_NIGHT_IMAGE, album_id: $this->album1->id);
179+
$this->assertCreated($response);
180+
181+
// Assert that RecomputeAlbumStatsJob was dispatched for the album
182+
Queue::assertPushed(RecomputeAlbumStatsJob::class, function (RecomputeAlbumStatsJob $job) {
183+
return $job->album_id === $this->album1->id;
184+
});
185+
186+
// Assert that RecomputeAlbumSizeJob was dispatched for the album
187+
Queue::assertPushed(RecomputeAlbumSizeJob::class, function (RecomputeAlbumSizeJob $job) {
188+
return $job->album_id === $this->album1->id;
189+
});
190+
191+
$this->catchFailureSilence = ["App\Exceptions\MediaFileOperationException"];
192+
}
162193
}

0 commit comments

Comments
 (0)