mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:04:03 +00:00
pass $tenant to async actions
This commit is contained in:
parent
a17e5bcc41
commit
15e8285ab6
1 changed files with 13 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||||
|
|
@ -140,7 +141,7 @@ class DatabaseManager
|
||||||
* Create a database for a tenant.
|
* Create a database for a tenant.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
* @param Tenant $tenant
|
||||||
* @param \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating
|
* @param ShouldQueue[]|callable[] $afterCreating
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createDatabase(Tenant $tenant, array $afterCreating = [])
|
public function createDatabase(Tenant $tenant, array $afterCreating = [])
|
||||||
|
|
@ -149,7 +150,17 @@ class DatabaseManager
|
||||||
$manager = $this->getTenantDatabaseManager($tenant);
|
$manager = $this->getTenantDatabaseManager($tenant);
|
||||||
|
|
||||||
if ($this->app['config']['tenancy.queue_database_creation'] ?? false) {
|
if ($this->app['config']['tenancy.queue_database_creation'] ?? false) {
|
||||||
// todo the chain does not get $tenant
|
$chain = [];
|
||||||
|
foreach ($afterCreating as $item) {
|
||||||
|
if (is_callable($item)) {
|
||||||
|
$chain[] = $item($tenant); // Callables are called and given $tenant
|
||||||
|
} elseif (is_string($item) && class_exists($item)) {
|
||||||
|
$chain[] = new $item($tenant); // Classes are instantiated and given $tenant
|
||||||
|
} elseif ($item instanceof ShouldQueue) {
|
||||||
|
$chain[] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QueuedTenantDatabaseCreator::withChain($afterCreating)->dispatch($manager, $database);
|
QueuedTenantDatabaseCreator::withChain($afterCreating)->dispatch($manager, $database);
|
||||||
} else {
|
} else {
|
||||||
$manager->createDatabase($database);
|
$manager->createDatabase($database);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue