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

LoadHomepagesData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 48
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 20 2
A createHomepages() 0 13 2
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\ContentBundle\Doctrine\ODM\PHPCR\Route;
21
use SWP\Bundle\ContentBundle\Model\RouteInterface;
22
use SWP\Bundle\FixturesBundle\AbstractFixture;
23
use SWP\Bundle\CoreBundle\Document\Tenant;
24
25
class LoadHomepagesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function load(ObjectManager $manager)
31
    {
32
        $tenants = [
33
            $manager->find(Tenant::class, '/swp/123456/123abc'),
34
            $manager->find(Tenant::class, '/swp/654321/456def'),
35
        ];
36
37
        $this->createHomepages($manager, $tenants);
38
39
        foreach ($tenants as $site) {
40
            $page = $manager->find(
41
                Route::class,
42
                $site->getId().'/routes/homepage'
43
            );
44
45
            $site->setHomepage($page);
46
        }
47
48
        $manager->flush();
49
    }
50
51
    private function createHomepages(ObjectManager $manager, array $tenants)
52
    {
53
        foreach ($tenants as $site) {
54
            $route = new Route();
55
            $route->setParentDocument($manager->find(null, $site->getId().'/routes'));
56
            $route->setName('homepage');
57
            $route->setType(RouteInterface::TYPE_CONTENT);
58
59
            $manager->persist($route);
60
        }
61
62
        $manager->flush();
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getOrder()
69
    {
70
        return 6;
71
    }
72
}
73