mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:34:04 +00:00
Merge branches 'storage-url-conflict-resolution' and 'master' of https://github.com/archtechx/tenancy into storage-url-conflict-resolution
This commit is contained in:
commit
99bb28a16b
3 changed files with 39 additions and 5 deletions
|
|
@ -47,6 +47,8 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
])->send(function (Events\DeletingTenant $event) {
|
])->send(function (Events\DeletingTenant $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(false),
|
})->shouldBeQueued(false),
|
||||||
|
|
||||||
|
// Listeners\DeleteTenantStorage::class,
|
||||||
],
|
],
|
||||||
Events\TenantDeleted::class => [
|
Events\TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
|
|
|
||||||
16
src/Listeners/DeleteTenantStorage.php
Normal file
16
src/Listeners/DeleteTenantStorage.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Stancl\Tenancy\Events\DeletingTenant;
|
||||||
|
|
||||||
|
class DeleteTenantStorage
|
||||||
|
{
|
||||||
|
public function handle(DeletingTenant $event): void
|
||||||
|
{
|
||||||
|
File::deleteDirectory($event->tenant->run(fn () => storage_path()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,13 +2,10 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests;
|
|
||||||
|
|
||||||
use ReflectionObject;
|
|
||||||
use ReflectionProperty;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\JobPipeline\JobPipeline;
|
use Stancl\JobPipeline\JobPipeline;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
@ -18,11 +15,13 @@ use Stancl\Tenancy\Events\TenancyEnded;
|
||||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||||
use Stancl\Tenancy\Events\TenantCreated;
|
use Stancl\Tenancy\Events\TenantCreated;
|
||||||
use Stancl\Tenancy\Events\TenantDeleted;
|
use Stancl\Tenancy\Events\TenantDeleted;
|
||||||
|
use Stancl\Tenancy\Events\DeletingTenant;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
|
use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
|
||||||
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
|
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
|
use Stancl\Tenancy\Listeners\DeleteTenantStorage;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
|
||||||
|
|
@ -191,7 +190,7 @@ test('filesystem data is separated', function () {
|
||||||
expect($new_storage_path)->toEqual($expected_storage_path);
|
expect($new_storage_path)->toEqual($expected_storage_path);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('local storage public urls are generated correctly', function() {
|
test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function () {
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [
|
'tenancy.bootstrappers' => [
|
||||||
FilesystemTenancyBootstrapper::class,
|
FilesystemTenancyBootstrapper::class,
|
||||||
|
|
@ -310,6 +309,23 @@ test('create and delete storage symlinks jobs work', function() {
|
||||||
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
|
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('local storage public urls are generated correctly', function() {
|
||||||
|
Event::listen(DeletingTenant::class, DeleteTenantStorage::class);
|
||||||
|
|
||||||
|
tenancy()->initialize(Tenant::create());
|
||||||
|
$tenantStoragePath = storage_path();
|
||||||
|
|
||||||
|
Storage::fake('test');
|
||||||
|
|
||||||
|
expect(File::isDirectory($tenantStoragePath))->toBeTrue();
|
||||||
|
|
||||||
|
Storage::put('test.txt', 'testing file');
|
||||||
|
|
||||||
|
tenant()->delete();
|
||||||
|
|
||||||
|
expect(File::isDirectory($tenantStoragePath))->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
function getDiskPrefix(string $disk): string
|
function getDiskPrefix(string $disk): string
|
||||||
{
|
{
|
||||||
/** @var FilesystemAdapter $disk */
|
/** @var FilesystemAdapter $disk */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue