File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use Illuminate \Queue \InteractsWithQueue ;
88use Illuminate \Queue \SerializesModels ;
99use Javaabu \Mediapicker \Contracts \Attachment ;
10- use Spatie \MediaLibrary \Conversions \ConversionCollection ;
11- use Spatie \MediaLibrary \Conversions \FileManipulator ;
12- use Spatie \MediaLibrary \MediaCollections \Models \Media ;
10+ use Javaabu \Mediapicker \Conversions \AttachmentConversionCollection ;
11+ use Javaabu \Mediapicker \Conversions \MediaManipulator ;
1312
1413class PerformAttachmentConversionsJob implements ShouldQueue
1514{
@@ -20,16 +19,16 @@ class PerformAttachmentConversionsJob implements ShouldQueue
2019 public $ deleteWhenMissingModels = true ;
2120
2221 public function __construct (
23- protected ConversionCollection $ conversions ,
22+ protected AttachmentConversionCollection $ conversions ,
2423 protected Attachment $ attachment ,
2524 protected bool $ onlyMissing = false ,
2625 ) {}
2726
28- public function handle (FileManipulator $ fileManipulator ): bool
27+ public function handle (MediaManipulator $ mediaManipulator ): bool
2928 {
30- $ fileManipulator -> performConversions (
29+ $ mediaManipulator -> performAttachmentConversions (
3130 $ this ->conversions ,
32- $ this ->media ,
31+ $ this ->attachment ,
3332 $ this ->onlyMissing
3433 );
3534
Original file line number Diff line number Diff line change 99use Illuminate \Support \Facades \View ;
1010use Javaabu \Helpers \HelpersServiceProvider ;
1111use Javaabu \Mediapicker \Models \Attachment ;
12+ use Javaabu \Mediapicker \Tests \TestSupport \Models \ModelWithConversions ;
1213use Javaabu \Mediapicker \Tests \TestSupport \Models \ModelWithSingleFile ;
1314use Javaabu \Mediapicker \Tests \TestSupport \Models \ModelWithUnacceptedFile ;
1415use Javaabu \Mediapicker \Tests \TestSupport \Models \ModelWithUnacceptedMimeType ;
@@ -106,6 +107,11 @@ protected function getModel(): Post
106107 return Post::factory ()->create ();
107108 }
108109
110+ protected function getModelWithConversions (): ModelWithConversions
111+ {
112+ return ModelWithConversions::factory ()->create ();
113+ }
114+
109115 protected function getModelWithUnacceptedFile (): ModelWithUnacceptedFile
110116 {
111117 return ModelWithUnacceptedFile::factory ()->create ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Javaabu \Mediapicker \Tests \TestSupport \Models ;
4+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Javaabu \Mediapicker \Concerns \InteractsWithAttachments ;
7+ use Javaabu \Mediapicker \Contracts \HasAttachments ;
8+ use Javaabu \Mediapicker \Tests \TestSupport \Factories \PostFactory ;
9+ use Spatie \MediaLibrary \MediaCollections \File ;
10+ use Spatie \MediaLibrary \MediaCollections \Models \Media ;
11+
12+ class ModelWithConversions extends Post
13+ {
14+ public function registerAttachmentConversions (?Media $ media = null )
15+ {
16+ $ this ->addAttachmentConversion ('test ' )
17+ ->width (100 )
18+ ->height (100 )
19+ ->crop (100 , 100 );
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -575,4 +575,20 @@ public function it_can_scope_query_with_attachments(): void
575575 $ result = Post::withAttachments ()->first ();
576576 $ this ->assertTrue ($ result ->relationLoaded ('attachments ' ));
577577 }
578+
579+ #[Test]
580+ public function it_can_generate_attachment_conversions (): void
581+ {
582+ $ model = $ this ->getModelWithConversions ();
583+
584+ $ media = $ this ->getMedia ();
585+
586+ $ attachment = $ model ->addAttachment ($ media )
587+ ->toAttachmentCollection ();
588+
589+ $ path = $ model ->getFirstAttachmentPath (conversionName: 'test ' );
590+
591+ $ this ->assertEquals ($ this ->getMediaDirectory ($ media ->getKey () . '/conversions/test-test.jpg ' ), $ path );
592+ $ this ->assertFileExists ($ path );
593+ }
578594}
You can’t perform that action at this time.
0 commit comments