You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! We have a multitenancy app which runs a backup every day. After updating from v8 to v9 we remarked that config is always loaded from config.php file from disk. This way we can't configure dynamically the config options according to each tenant. This is our code for changing the config dynamically which is working in v8, but not in v9:
<?php
namespace App\Tasks;
use Spatie\Multitenancy\Contracts\IsTenant;
use Spatie\Multitenancy\Tasks\SwitchTenantTask;
class SwitchBackupDatabaseTask implements SwitchTenantTask
{
public function __construct(protected ?array $originalBackupDatabase = null, protected ?string $originalBackupFilenamePrefix = null)
{
$this->originalBackupDatabase ??= config('backup.backup.source.databases');
$this->originalBackupFilenamePrefix ??= config('backup.backup.destination.filename_prefix');
}
public function makeCurrent(IsTenant $tenant): void
{
config()->set('backup.backup.source.databases', ['tenant']);
config()->set('backup.backup.destination.filename_prefix', $tenant->database . '-');
}
public function forgetCurrent(): void
{
config()->set('backup.backup.source.databases', $this->originalBackupDatabase);
config()->set('backup.backup.destination.filename_prefix', $this->originalBackupFilenamePrefix);
}
}
The text was updated successfully, but these errors were encountered:
Then in the schedule, pass in the database(s) that need backing up:
protectedfunctionschedule(Schedule$schedule): void
{
$schedule->command('backup:run', [
'--only-db',
'--db-name' => [
'tenant_1'// can be generated dynamically
],
])
->dailyAt('13:00');
$schedule->command('monitor:check-uptime')->everyMinute();
}
This isn't super practical, and is a bit prone to error.
I've attempted to extend the BackupCommand class, passing in my own Config instance, but it always seems to revert to the original config from the backup config file.
I'm probably just misunderstanding the flow, but I can't seem to crack how to set the config dynamically.
Hi! We have a multitenancy app which runs a backup every day. After updating from v8 to v9 we remarked that config is always loaded from config.php file from disk. This way we can't configure dynamically the config options according to each tenant. This is our code for changing the config dynamically which is working in v8, but not in v9:
The text was updated successfully, but these errors were encountered: