mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 01:14:04 +00:00
44 lines
1 KiB
PHP
44 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Traits;
|
|
|
|
use Stancl\Tenancy\Tenant;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
trait TenantAwareCommand
|
|
{
|
|
/** @return int */
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$tenants = $this->getTenants();
|
|
|
|
if (count($tenants) === 1) {
|
|
return $tenants[0]->run(function () {
|
|
return $this->laravel->call([$this, 'handle']);
|
|
});
|
|
}
|
|
|
|
$exitCode = 0;
|
|
foreach ($tenants as $tenant) {
|
|
$result = (int) $tenant->run(function () {
|
|
return $this->laravel->call([$this, 'handle']);
|
|
});
|
|
|
|
if ($result !== 0) {
|
|
$exitCode = $result;
|
|
}
|
|
}
|
|
|
|
return $exitCode;
|
|
}
|
|
|
|
/**
|
|
* Get an array of tenants for which the command should be executed.
|
|
*
|
|
* @return Tenant[]
|
|
*/
|
|
abstract protected function getTenants(): array;
|
|
}
|