Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

LoadTenantsData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 64
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 36 3
A initBasePaths() 0 13 1
A getOrder() 0 4 1
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