1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 15:54:03 +00:00

-ing event behavior

This commit is contained in:
Samuel Štancl 2020-05-21 17:55:48 +02:00
parent c40dba4e02
commit 33d6fd82da
9 changed files with 120 additions and 6 deletions

View file

@ -12,6 +12,7 @@ use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseMigrated;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Events\MigratingDatabase;
class Migrate extends MigrateCommand
{
@ -59,6 +60,8 @@ class Migrate extends MigrateCommand
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant['id']}");
event(new MigratingDatabase($tenant));
// Migrate
parent::handle();

View file

@ -10,6 +10,7 @@ use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseSeeded;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Events\SeedingDatabase;
class Seed extends SeedCommand
{
@ -58,6 +59,8 @@ class Seed extends SeedCommand
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant['id']}");
event(new SeedingDatabase($tenant));
// Seed
parent::handle();

View file

@ -0,0 +1,6 @@
<?php
namespace Stancl\Tenancy\Events;
class CreatingDatabase extends Contracts\TenantEvent
{}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class MigratingDatabase extends Contracts\TenantEvent
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stancl\Tenancy\Events;
class SeedingDatabase extends Contracts\TenantEvent
{
}

View file

@ -13,6 +13,7 @@ use Illuminate\Queue\SerializesModels;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\CreatingDatabase;
use Stancl\Tenancy\Events\DatabaseCreated;
class CreateDatabase implements ShouldQueue
@ -29,6 +30,8 @@ class CreateDatabase implements ShouldQueue
public function handle(DatabaseManager $databaseManager)
{
event(new CreatingDatabase($this->tenant));
if ($this->tenant->getInternal('create_database') !== false) {
$databaseManager->ensureTenantCanBeCreated($this->tenant);
$this->tenant->database()->makeCredentials();

View file

@ -16,7 +16,7 @@ class Tenancy
public $tenant;
/** @var callable|null */
public static $getBootstrappers = null;
public $getBootstrappersUsing = null;
/** @var bool */
public $initialized = false;
@ -55,11 +55,12 @@ class Tenancy
public function getBootstrappers(): array
{
// If no callback for getting bootstrappers is set, we just return all of them.
$resolve = static::$getBootstrappers ?? function (Tenant $tenant) {
return array_map('app', config('tenancy.bootstrappers'));
$resolve = $this->getBootstrappersUsing ?? function (Tenant $tenant) {
return config('tenancy.bootstrappers');
};
return $resolve($this->tenant);
// Here We instantiate the bootstrappers and return them.
return array_map('app', $resolve($this->tenant));
}
public function query(): Builder