Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Page/PageStorage/Gateway/LegacyStorage.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Page\PageStorage\Gateway;
8
9 use eZ\Publish\Core\Base\Exceptions\NotFoundException;
10 use eZ\Publish\Core\FieldType\Page\PageStorage\Gateway;
11 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
12 use eZ\Publish\Core\FieldType\Page\Parts\Block;
13 use eZ\Publish\Core\FieldType\Page\Parts\Item;
14 use PDO;
15 use DateTime;
16 use eZ\Publish\Core\Persistence\Database\SelectQuery;
17
21 class LegacyStorage extends Gateway
22 {
24 protected $dbHandler;
25
26 public function __construct(DatabaseHandler $dbHandler)
27 {
28 @trigger_error(
29 sprintf('%s is deprecated, use %s instead', self::class, DoctrineStorage::class),
30 E_USER_DEPRECATED
31 );
32 $this->dbHandler = $dbHandler;
33 }
34
40 protected function getConnection()
41 {
42 return $this->dbHandler;
43 }
44
52 public function getValidBlockItems(Block $block)
53 {
54 $dbHandler = $this->getConnection();
55 $q = $dbHandler->createSelectQuery();
56 $q
57 ->select('object_id, ezm_pool.node_id, ezm_pool.priority, ts_publication, ts_visible, rotation_until, moved_to')
58 ->from($dbHandler->quoteTable('ezm_pool'))
59 ->innerJoin(
60 $dbHandler->quoteTable('ezcontentobject_tree'),
61 $q->expr->eq('ezcontentobject_tree.node_id', 'ezm_pool.node_id')
62 )
63 ->where(
64 $q->expr->eq('block_id', $q->bindValue($block->id)),
65 $q->expr->gt('ts_visible', $q->bindValue(0, null, PDO::PARAM_INT)),
66 $q->expr->eq('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
67 )
68 ->orderBy('priority', SelectQuery::DESC);
69
70 $stmt = $q->prepare();
71 $stmt->execute();
72 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
73 $items = [];
74 foreach ($rows as $row) {
75 $items[] = $this->buildBlockItem(
76 $row + [
77 'block_id' => $block->id,
78 'ts_hidden' => 0,
79 ]
80 );
81 }
82
83 return $items;
84 }
85
94 public function getLastValidBlockItem(Block $block)
95 {
96 $dbHandler = $this->getConnection();
97 $q = $dbHandler->createSelectQuery();
98 $q
99 ->select('object_id, node_id, priority, ts_publication, ts_visible, rotation_until, moved_to')
100 ->from($dbHandler->quoteTable('ezm_pool'))
101 ->where(
102 $q->expr->eq('block_id', $q->bindValue($block->id)),
103 $q->expr->gt('ts_visible', $q->bindValue(0, null, PDO::PARAM_INT)),
104 $q->expr->eq('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
105 )
106 ->orderBy('ts_visible', SelectQuery::DESC)
107 ->limit(1);
108
109 $stmt = $q->prepare();
110 $stmt->execute();
111 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
112 if (empty($rows)) {
113 return;
114 }
115
116 return $this->buildBlockItem(
117 $rows[0] + [
118 'block_id' => $block->id,
119 'ts_hidden' => 0,
120 ]
121 );
122 }
123
131 public function getWaitingBlockItems(Block $block)
132 {
133 $dbHandler = $this->getConnection();
134 $q = $dbHandler->createSelectQuery();
135 $q
136 ->select('object_id, node_id, priority, ts_publication, rotation_until, moved_to')
137 ->from($dbHandler->quoteTable('ezm_pool'))
138 ->where(
139 $q->expr->eq('block_id', $q->bindValue($block->id)),
140 $q->expr->eq('ts_visible', $q->bindValue(0, null, PDO::PARAM_INT)),
141 $q->expr->eq('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
142 )
143 ->orderBy('ts_publication')
144 ->orderBy('priority');
145
146 $stmt = $q->prepare();
147 $stmt->execute();
148 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
149 $items = [];
150 foreach ($rows as $row) {
151 $items[] = $this->buildBlockItem(
152 $row + [
153 'block_id' => $block->id,
154 'ts_visible' => 0,
155 'ts_hidden' => 0,
156 ]
157 );
158 }
159
160 return $items;
161 }
162
170 public function getArchivedBlockItems(Block $block)
171 {
172 $dbHandler = $this->getConnection();
173 $q = $dbHandler->createSelectQuery();
174 $q
175 ->select('object_id, node_id, priority, ts_publication, ts_visible, ts_hidden, rotation_until, moved_to')
176 ->from($dbHandler->quoteTable('ezm_pool'))
177 ->where(
178 $q->expr->eq('block_id', $q->bindValue($block->id)),
179 $q->expr->gt('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
180 )
181 ->orderBy('ts_hidden');
182
183 $stmt = $q->prepare();
184 $stmt->execute();
185 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
186 $items = [];
187 foreach ($rows as $row) {
188 $items[] = $this->buildBlockItem(
189 $row + [
190 'block_id' => $block->id,
191 ]
192 );
193 }
194
195 return $items;
196 }
197
208 public function getContentIdByBlockId($id)
209 {
210 $dbHandler = $this->getConnection();
211 $query = $dbHandler->createSelectQuery();
212 $query
213 ->select($dbHandler->quoteColumn('contentobject_id'))
214 ->from($dbHandler->quoteTable('ezcontentobject_tree'))
215 ->innerJoin(
216 $dbHandler->quoteTable('ezm_block'),
217 $query->expr->eq(
218 $dbHandler->quoteColumn('node_id', 'ezm_block'),
219 $dbHandler->quoteColumn('node_id', 'ezcontentobject_tree')
220 )
221 )
222 ->where(
223 $query->expr->eq(
224 $dbHandler->quoteColumn('id', 'ezm_block'),
225 $query->bindValue($id, null, PDO::PARAM_STR)
226 )
227 );
228
229 $stmt = $query->prepare();
230 $stmt->execute();
231
232 $contentId = $stmt->fetchColumn();
233
234 if ($contentId === false) {
235 throw new NotFoundException('Block', $id);
236 }
237
238 return $contentId;
239 }
240
248 protected function buildBlockItem(array $row)
249 {
250 return new Item(
251 [
252 'blockId' => $row['block_id'],
253 'contentId' => (int)$row['object_id'],
254 'locationId' => (int)$row['node_id'],
255 'priority' => (int)$row['priority'],
256 'publicationDate' => new DateTime("@{$row['ts_publication']}"),
257 'visibilityDate' => $row['ts_visible'] ? new DateTime("@{$row['ts_visible']}") : null,
258 'hiddenDate' => $row['ts_hidden'] ? new DateTime("@{$row['ts_hidden']}") : null,
259 'rotationUntilDate' => $row['rotation_until'] ? new DateTime("@{$row['rotation_until']}") : null,
260 'movedTo' => $row['moved_to'],
261 ]
262 );
263 }
264 }
eZ\Publish\Core\Base\Exceptions\NotFoundException
Not Found Exception implementation.
Definition: Core/Base/Exceptions/NotFoundException.php:21
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage
Definition: Page/PageStorage/Gateway/LegacyStorage.php:22
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\__construct
__construct(DatabaseHandler $dbHandler)
Definition: Page/PageStorage/Gateway/LegacyStorage.php:26
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\buildBlockItem
buildBlockItem(array $row)
Builds a Page\Parts\Item object from a row returned from ezm_pool table.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:248
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getLastValidBlockItem
getLastValidBlockItem(Block $block)
Returns the block item having a highest visible date, for given block.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:94
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getConnection
getConnection()
Returns the active connection.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:40
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getArchivedBlockItems
getArchivedBlockItems(Block $block)
Returns archived items (that were previously displayed), for a given block.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:170
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getContentIdByBlockId
getContentIdByBlockId($id)
Returns Content id for the given Block $id, or false if Block could not be found.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:208
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getWaitingBlockItems
getWaitingBlockItems(Block $block)
Returns queued items (the next to be displayed), for a given block.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:131
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\$dbHandler
$dbHandler
Definition: Page/PageStorage/Gateway/LegacyStorage.php:24
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\LegacyStorage\getValidBlockItems
getValidBlockItems(Block $block)
Returns valid items (that are to be displayed), for a given block.
Definition: Page/PageStorage/Gateway/LegacyStorage.php:52
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Main abstract storage gateway for Page field type.
Definition: FieldType/Page/PageStorage/Gateway.php:16
eZ\Publish\Core\FieldType\Page\Parts\Block
Definition: FieldType/Page/Parts/Block.php:22
eZ\Publish\Core\FieldType\Page\Parts\Item
Definition: Item.php:24
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
eZ\Publish\Core\Persistence\Database\SelectQuery\DESC
const DESC
Definition: SelectQuery.php:18
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.