Completed
Push — ezp-23733_disable_section_dele... ( a742c6...6e64a4 )
by
unknown
35:02
created

SectionHandler::roleAssignmentsUsingSectionCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * File containing the SectionHandler implementation.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Persistence\Cache;
12
13
use eZ\Publish\SPI\Persistence\Content\Section\Handler as SectionHandlerInterface;
14
15
/**
16
 * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
17
 *
18
 * @todo Consider loadAll & loadByIdentifier cache, however then loadAll() must be used
19
 *       by all (incl create) but update & delete to avoid doing several cache lookups.
20
 */
21
class SectionHandler extends AbstractHandler implements SectionHandlerInterface
22
{
23
    /**
24
     * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
25
     */
26 View Code Duplication
    public function create($name, $identifier)
27
    {
28
        $this->logger->logCall(__METHOD__, array('name' => $name, 'identifier' => $identifier));
29
        $section = $this->persistenceHandler->sectionHandler()->create($name, $identifier);
30
        $this->cache->getItem('section', $section->id)->set($section);
31
32
        return $section;
33
    }
34
35
    /**
36
     * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
37
     */
38 View Code Duplication
    public function update($id, $name, $identifier)
39
    {
40
        $this->logger->logCall(__METHOD__, array('section' => $id, 'name' => $name, 'identifier' => $identifier));
41
        $this->cache
42
            ->getItem('section', $id)
43
            ->set($section = $this->persistenceHandler->sectionHandler()->update($id, $name, $identifier));
44
45
        return $section;
46
    }
47
48
    /**
49
     * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
50
     */
51 View Code Duplication
    public function load($id)
52
    {
53
        $cache = $this->cache->getItem('section', $id);
54
        $section = $cache->get();
55
        if ($cache->isMiss()) {
56
            $this->logger->logCall(__METHOD__, array('section' => $id));
57
            $cache->set($section = $this->persistenceHandler->sectionHandler()->load($id));
58
        }
59
60
        return $section;
61
    }
62
63
    /**
64
     * Get all section data.
65
     *
66
     * @return \eZ\Publish\SPI\Persistence\Content\Section[]
67
     */
68
    public function loadAll()
69
    {
70
        $this->logger->logCall(__METHOD__);
71
72
        return $this->persistenceHandler->sectionHandler()->loadAll();
73
    }
74
75
    /**
76
     * Get section data by identifier.
77
     *
78
     * @param string $identifier
79
     *
80
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If section is not found
81
     *
82
     * @return \eZ\Publish\SPI\Persistence\Content\Section
83
     */
84
    public function loadByIdentifier($identifier)
85
    {
86
        $this->logger->logCall(__METHOD__, array('section' => $identifier));
87
88
        return $this->persistenceHandler->sectionHandler()->loadByIdentifier($identifier);
89
    }
90
91
    /**
92
     * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
93
     */
94
    public function delete($id)
95
    {
96
        $this->logger->logCall(__METHOD__, array('section' => $id));
97
        $return = $this->persistenceHandler->sectionHandler()->delete($id);
98
99
        $this->cache->clear('section', $id);
100
101
        return $return;
102
    }
103
104
    /**
105
     * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
106
     */
107
    public function assign($sectionId, $contentId)
108
    {
109
        $this->logger->logCall(__METHOD__, array('section' => $sectionId, 'content' => $contentId));
110
        $return = $this->persistenceHandler->sectionHandler()->assign($sectionId, $contentId);
111
112
        $this->cache->clear('content', $contentId);
113
        $this->cache->clear('content', 'info', $contentId);
114
        $this->cache->clear('content', 'info', 'remoteId');
115
116
        return $return;
117
    }
118
119
    /**
120
     * Number of content assignments a Section has.
121
     *
122
     * @param mixed $sectionId
123
     *
124
     * @return int
125
     */
126
    public function assignmentsCount($sectionId)
127
    {
128
        $this->logger->logCall(__METHOD__, array('section' => $sectionId));
129
130
        return $this->persistenceHandler->sectionHandler()->assignmentsCount($sectionId);
131
    }
132
133
    /**
134
     * Number of role policies using a Section in limitations.
135
     *
136
     * @param mixed $sectionId
137
     *
138
     * @return int
139
     */
140
    public function policiesCount($sectionId)
141
    {
142
        $this->logger->logCall(__METHOD__, array('section' => $sectionId));
143
144
        return $this->persistenceHandler->sectionHandler()->policiesCount($sectionId);
145
    }
146
147
    /**
148
     * @see eZ\Publish\SPI\Persistence\User\Handler::countRoleAssignmentsUsingSection
149
     */
150
    public function countRoleAssignmentsUsingSection($sectionId)
151
    {
152
        $this->logger->logCall(__METHOD__, array('section' => $sectionId));
153
154
        return $this->persistenceHandler->sectionHandler()->countRoleAssignmentsUsingSection($sectionId);
155
    }
156
}
157