File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 3333 "doctrine/dbal" : " ^3.6.0" ,
3434 "spatie/valuestore" : " ^1.2.5" ,
3535 "pestphp/pest" : " ^3.0" ,
36- "larastan/larastan" : " ^3.0"
36+ "larastan/larastan" : " ^3.0" ,
37+ "league/flysystem-path-prefixing" : " ^3.0"
3738 },
3839 "autoload" : {
3940 "psr-4" : {
Original file line number Diff line number Diff line change @@ -114,7 +114,18 @@ protected function assetHelper(string|false $suffix): void
114114
115115 protected function forgetDisks (): void
116116 {
117- Storage::forgetDisk ($ this ->app ['config ' ]['tenancy.filesystem.disks ' ]);
117+ $ tenantDisks = $ this ->app ['config ' ]['tenancy.filesystem.disks ' ];
118+ $ scopedDisks = [];
119+
120+ foreach ($ this ->app ['config ' ]['filesystems.disks ' ] as $ name => $ disk ) {
121+ if (isset ($ disk ['driver ' ], $ disk ['disk ' ])
122+ && $ disk ['driver ' ] === 'scoped '
123+ && in_array ($ disk ['disk ' ], $ tenantDisks , true )) {
124+ $ scopedDisks [] = $ name ;
125+ }
126+ }
127+
128+ Storage::forgetDisk (array_merge ($ tenantDisks , $ scopedDisks ));
118129 }
119130
120131 protected function diskRoot (string $ disk , Tenant |false $ tenant ): void
Original file line number Diff line number Diff line change 221221 expect (is_dir ($ centralStoragePath . "/tenant {$ tenant ->id }/framework/cache " ))->toBeFalse ();
222222 }
223223})->with ([true , false ]);
224+
225+ test ('scoped disks are scoped per tenant ' , function () {
226+ config ([
227+ 'tenancy.bootstrappers ' => [
228+ FilesystemTenancyBootstrapper::class,
229+ ],
230+ 'filesystems.disks.scoped_disk ' => [
231+ 'driver ' => 'scoped ' ,
232+ 'disk ' => 'public ' ,
233+ 'prefix ' => 'scoped_disk_prefix ' ,
234+ ],
235+ ]);
236+
237+ $ tenant = Tenant::create ();
238+
239+ Storage::disk ('scoped_disk ' )->put ('foo.txt ' , 'central ' );
240+ expect (Storage::disk ('scoped_disk ' )->get ('foo.txt ' ))->toBe ('central ' );
241+ expect (file_get_contents (storage_path () . "/app/public/scoped_disk_prefix/foo.txt " ))->toBe ('central ' );
242+
243+ tenancy ()->initialize ($ tenant );
244+
245+ expect (Storage::disk ('scoped_disk ' )->get ('foo.txt ' ))->toBe (null );
246+ Storage::disk ('scoped_disk ' )->put ('foo.txt ' , 'tenant ' );
247+ expect (file_get_contents (storage_path () . "/app/public/scoped_disk_prefix/foo.txt " ))->toBe ('tenant ' );
248+ expect (Storage::disk ('scoped_disk ' )->get ('foo.txt ' ))->toBe ('tenant ' );
249+
250+ tenancy ()->end ();
251+
252+ expect (Storage::disk ('scoped_disk ' )->get ('foo.txt ' ))->toBe ('central ' );
253+ Storage::disk ('scoped_disk ' )->put ('foo.txt ' , 'central2 ' );
254+ expect (Storage::disk ('scoped_disk ' )->get ('foo.txt ' ))->toBe ('central2 ' );
255+
256+ expect (file_get_contents (storage_path () . "/app/public/scoped_disk_prefix/foo.txt " ))->toBe ('central2 ' );
257+ expect (file_get_contents (storage_path () . "/tenant {$ tenant ->id }/app/public/scoped_disk_prefix/foo.txt " ))->toBe ('tenant ' );
258+ });
259+
You can’t perform that action at this time.
0 commit comments