forked from archtechx/tenancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.x] Don't use onDeleteCascade in the migrations (archtechx#883)
* removed `cascade` on delete for domains * removed only `onDelete` cascade * keep impersonation migrations unchanged * domains set null on delete * Update 2019_09_15_000020_create_domains_table.php * Added DeleteDomain Job while deleting tenant. * Update assets/TenancyServiceProvider.stub.php Co-authored-by: Samuel Štancl <[email protected]> * renamed class * Update DeleteDomains.php * onDelete restrict * revert nullable * removed `shouldQueue` interface * Update TenancyServiceProvider.stub.php * fetch and delete domains individually * Update DeleteDomains.php * tests for `DeleteDomains` job Co-authored-by: Samuel Štancl <[email protected]>
- Loading branch information
1 parent
4aec6bf
commit 627233d
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stancl\Tenancy\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Stancl\Tenancy\Contracts\TenantWithDatabase; | ||
use Stancl\Tenancy\Database\Models\Domain; | ||
use Stancl\Tenancy\Events\DatabaseDeleted; | ||
use Stancl\Tenancy\Events\DeletingDatabase; | ||
use Stancl\Tenancy\Events\DeletingDomain; | ||
use Stancl\Tenancy\Events\DomainDeleted; | ||
|
||
class DeleteDomains | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** @var TenantWithDatabase */ | ||
protected $tenant; | ||
|
||
public function __construct(TenantWithDatabase $tenant) | ||
{ | ||
$this->tenant = $tenant; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$this->tenant->domains->each->delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stancl\Tenancy\Tests; | ||
|
||
use Stancl\Tenancy\Database\Concerns\HasDomains; | ||
use Stancl\Tenancy\Jobs\DeleteDomains; | ||
|
||
class DeleteDomainsJobTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config(['tenancy.tenant_model' => DatabaseAndDomainTenant::class]); | ||
} | ||
|
||
/** @test */ | ||
public function job_delete_domains_successfully() | ||
{ | ||
$tenant = DatabaseAndDomainTenant::create(); | ||
|
||
$tenant->domains()->create([ | ||
'domain' => 'foo.localhost', | ||
]); | ||
$tenant->domains()->create([ | ||
'domain' => 'bar.localhost', | ||
]); | ||
|
||
$this->assertSame($tenant->domains()->count(), 2); | ||
|
||
(new DeleteDomains($tenant))->handle(); | ||
|
||
$this->assertSame($tenant->refresh()->domains()->count(), 0); | ||
} | ||
} | ||
|
||
class DatabaseAndDomainTenant extends Etc\Tenant | ||
{ | ||
use HasDomains; | ||
} |