Completed
Pull Request — develop (#161)
by Wachter
22:54 queued 09:56
created

ArticleInitializer::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 11
cp 0.9091
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
crap 2.003
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ArticleBundle\Document\Initializer;
13
14
use Sulu\Bundle\DocumentManagerBundle\Initializer\InitializerInterface;
15
use Sulu\Component\DocumentManager\NodeManager;
16
use Sulu\Component\DocumentManager\PathBuilder;
17
use Sulu\Component\PHPCR\SessionManager\SessionManagerInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Initializes custom-url nodes.
22
 */
23
class ArticleInitializer implements InitializerInterface
24
{
25
    /**
26
     * @var NodeManager
27
     */
28
    private $nodeManager;
29
30
    /**
31
     * @var PathBuilder
32
     */
33
    private $pathBuilder;
34
35
    /**
36
     * @var SessionManagerInterface
37
     */
38
    private $sessionManager;
39
40 1
    public function __construct(
41
        NodeManager $nodeManager,
42
        PathBuilder $pathBuilder,
43
        SessionManagerInterface $sessionManager
44
    ) {
45 1
        $this->nodeManager = $nodeManager;
46 1
        $this->pathBuilder = $pathBuilder;
47 1
        $this->sessionManager = $sessionManager;
48 1
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function initialize(OutputInterface $output, $purge = false)
54
    {
55 1
        $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager();
0 ignored issues
show
Deprecated Code introduced by
The method Sulu\Component\PHPCR\Ses...Interface::getSession() has been deprecated with message: Use the doctrine_phpcr service to retrieve the session

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
56 1
        $nodeTypeManager->registerNodeType(new ArticleNodeType(), true);
57 1
        $nodeTypeManager->registerNodeType(new ArticlePageNodeType(), true);
58
59 1
        $articlesPath = $this->pathBuilder->build(['%base%', '%articles%']);
60 1
        if (true === $this->nodeManager->has($articlesPath)) {
61
            $output->writeln(sprintf('  [ ] <info>Articles path:</info>: %s ', $articlesPath));
62
        } else {
63 1
            $output->writeln(sprintf('  [+] <info>Articles path:</info>: %s ', $articlesPath));
64 1
            $this->nodeManager->createPath($articlesPath);
65 1
            $this->nodeManager->save();
66
        }
67 1
    }
68
}
69