|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vivait\TenantBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Vivait\TenantBundle\Kernel\TenantKernel; |
|
12
|
|
|
use Vivait\TenantBundle\Model\Tenant; |
|
13
|
|
|
use Vivait\TenantBundle\Registry\TenantRegistry; |
|
14
|
|
|
|
|
15
|
|
|
class ListTenantsCommand extends ContainerAwareCommand |
|
16
|
|
|
{ |
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setName('vivait:tenants:list') |
|
21
|
|
|
->setDescription('Provides a list of tenants') |
|
22
|
|
|
->addOption( |
|
23
|
|
|
'null', |
|
24
|
|
|
'0', |
|
25
|
|
|
InputOption::VALUE_NONE, |
|
26
|
|
|
'Use a null character as a separator (instead of the newline character).' |
|
27
|
|
|
) |
|
28
|
|
|
->addOption( |
|
29
|
|
|
'force', |
|
30
|
|
|
'f', |
|
31
|
|
|
InputOption::VALUE_NONE, |
|
32
|
|
|
'Force a list of tenants, even if tenanting is disabled for the current environment' |
|
33
|
|
|
) |
|
34
|
|
|
; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
38
|
|
|
{ |
|
39
|
|
|
$null = $input->getOption('null'); |
|
40
|
|
|
$force = $input->getOption('force'); |
|
41
|
|
|
|
|
42
|
|
|
/** @var TenantKernel $kernel */ |
|
43
|
|
|
$kernel = $this->getContainer()->get('kernel'); |
|
44
|
|
|
|
|
45
|
|
|
if ($force || $kernel->enableTenanting) { |
|
46
|
|
|
/** @var TenantRegistry $registry */ |
|
47
|
|
|
$registry = $this->getContainer()->get('vivait_tenant.registry'); |
|
48
|
|
|
|
|
49
|
|
|
$separator = $null ? "\0" : "\n"; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($registry->getAll() as $tenant) { |
|
52
|
|
|
$output->write($tenant->getKey() . $separator); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|