mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 05:24:04 +00:00
vague first draft of v3. TenantModelTest is passing
This commit is contained in:
parent
c2c90ff755
commit
bd9aad229b
56 changed files with 803 additions and 1366 deletions
32
src/Jobs/CreateDatabase.php
Normal file
32
src/Jobs/CreateDatabase.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?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\Database\Models\Tenant;
|
||||
|
||||
class CreateDatabase implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if ($this->tenant->getAttribute('_tenancy_create_database') !== false) {
|
||||
$this->tenant->database()->manager()->createDatabase($this->tenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,31 +10,22 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
class QueuedTenantDatabaseDeleter implements ShouldQueue
|
||||
class DeleteDatabase implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var TenantDatabaseManager */
|
||||
protected $databaseManager;
|
||||
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(TenantDatabaseManager $databaseManager, Tenant $tenant)
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->databaseManager = $databaseManager;
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->databaseManager->deleteDatabase($this->tenant);
|
||||
$this->tenant->database()->manager()->deleteDatabase($this->tenant);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,22 +9,18 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
class QueuedTenantDatabaseCreator implements ShouldQueue
|
||||
class MigrateDatabase implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var TenantDatabaseManager */
|
||||
protected $databaseManager;
|
||||
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(TenantDatabaseManager $databaseManager, Tenant $tenant)
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->databaseManager = $databaseManager;
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +31,12 @@ class QueuedTenantDatabaseCreator implements ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->databaseManager->createDatabase($this->tenant);
|
||||
$migrationParameters = [
|
||||
// todo ...
|
||||
];
|
||||
|
||||
Artisan::call('tenants:migrate', [
|
||||
'--tenants' => [$this->tenant->id],
|
||||
] + $migrationParameters);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?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 Illuminate\Support\Facades\Artisan;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class QueuedTenantDatabaseMigrator implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var string */
|
||||
protected $tenantId;
|
||||
|
||||
/** @var array */
|
||||
protected $migrationParameters = [];
|
||||
|
||||
public function __construct(Tenant $tenant, $migrationParameters = [])
|
||||
{
|
||||
$this->tenantId = $tenant->id;
|
||||
$this->migrationParameters = $migrationParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Artisan::call('tenants:migrate', [
|
||||
'--tenants' => [$this->tenantId],
|
||||
] + $this->migrationParameters);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,18 +10,18 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
|
||||
class QueuedTenantDatabaseSeeder implements ShouldQueue
|
||||
class SeedDatabase implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var string */
|
||||
protected $tenantId;
|
||||
/** @var Tenant */
|
||||
protected $tenant;
|
||||
|
||||
public function __construct(Tenant $tenant)
|
||||
{
|
||||
$this->tenantId = $tenant->id;
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,7 +32,7 @@ class QueuedTenantDatabaseSeeder implements ShouldQueue
|
|||
public function handle()
|
||||
{
|
||||
Artisan::call('tenants:seed', [
|
||||
'--tenants' => [$this->tenantId],
|
||||
'--tenants' => [$this->tenant->id],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue