1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Fixtures Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\FixturesBundle\DataFixtures\PHPCR; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\DataFixtures\FixtureInterface; |
18
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
20
|
|
|
use SWP\Bundle\FixturesBundle\AbstractFixture; |
21
|
|
|
use SWP\Bundle\CoreBundle\Document\Organization; |
22
|
|
|
use SWP\Bundle\CoreBundle\Document\Tenant; |
23
|
|
|
use SWP\Component\MultiTenancy\Model\OrganizationInterface; |
24
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
25
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
26
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
27
|
|
|
|
28
|
|
|
class LoadTenantsData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function load(ObjectManager $manager) |
34
|
|
|
{ |
35
|
|
|
$env = $this->getEnvironment(); |
36
|
|
|
|
37
|
|
|
$organization1 = new Organization(); |
38
|
|
|
$organization1->setName(OrganizationInterface::DEFAULT_NAME); |
39
|
|
|
$organization1->setCode('123456'); |
40
|
|
|
$organization1->setParentDocument($manager->find(null, '/swp')); |
41
|
|
|
$manager->persist($organization1); |
42
|
|
|
|
43
|
|
|
$organization2 = new Organization(); |
44
|
|
|
$organization2->setName('Organization2'); |
45
|
|
|
$organization2->setCode('654321'); |
46
|
|
|
$organization2->setParentDocument($manager->find(null, '/swp')); |
47
|
|
|
$manager->persist($organization2); |
48
|
|
|
$manager->flush(); |
49
|
|
|
|
50
|
|
|
$tenant1 = new Tenant(); |
51
|
|
|
$tenant1->setName('Default tenant'); |
52
|
|
|
$tenant1->setSubdomain('default'); |
53
|
|
|
$tenant1->setThemeName($env === 'test' ? 'swp/test-theme' : 'swp/default-theme'); |
54
|
|
|
$tenant1->setCode('123abc'); |
55
|
|
|
$tenant1->setOrganization($organization1); |
56
|
|
|
$manager->persist($tenant1); |
57
|
|
|
|
58
|
|
|
$tenant2 = new Tenant(); |
59
|
|
|
$tenant2->setName('Client1 tenant'); |
60
|
|
|
$tenant2->setSubdomain('client1'); |
61
|
|
|
$tenant2->setThemeName($env === 'test' ? 'swp/test-theme' : 'swp/default-theme'); |
62
|
|
|
$tenant2->setCode('456def'); |
63
|
|
|
$tenant2->setOrganization($organization2); |
64
|
|
|
$manager->persist($tenant2); |
65
|
|
|
$manager->flush(); |
66
|
|
|
|
67
|
|
|
$this->initBasePaths($env); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function initBasePaths($env) |
71
|
|
|
{ |
72
|
|
|
$kernel = $this->container->get('kernel'); |
73
|
|
|
$application = new Application($kernel); |
74
|
|
|
$application->setAutoExit(false); |
75
|
|
|
|
76
|
|
|
$input = new ArrayInput(array( |
77
|
|
|
'command' => 'doctrine:phpcr:repository:init', |
78
|
|
|
'--env' => $env, |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
$application->run($input, new NullOutput()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function getOrder() |
88
|
|
|
{ |
89
|
|
|
return 0; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|