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

MapLocation/MapLocationStorage/Gateway/LegacyStorage.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway;
8
9 use eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway;
10 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
11 use eZ\Publish\SPI\Persistence\Content\Field;
12 use eZ\Publish\SPI\Persistence\Content\VersionInfo;
13
17 class LegacyStorage extends Gateway
18 {
20 protected $dbHandler;
21
22 public function __construct(DatabaseHandler $dbHandler)
23 {
24 @trigger_error(
25 sprintf('%s is deprecated, use %s instead', self::class, DoctrineStorage::class),
26 E_USER_DEPRECATED
27 );
28 $this->dbHandler = $dbHandler;
29 }
30
36 protected function getConnection()
37 {
38 return $this->dbHandler;
39 }
40
52 public function storeFieldData(VersionInfo $versionInfo, Field $field)
53 {
54 if ($field->value->externalData === null) {
55 // Store empty value and return
56 $this->deleteFieldData($versionInfo, [$field->id]);
57 $field->value->data = [
58 'sortKey' => null,
59 'hasData' => false,
60 ];
61
62 return false;
63 }
64
65 if ($this->hasFieldData($field->id, $versionInfo->versionNo)) {
66 $this->updateFieldData($versionInfo, $field);
67 } else {
68 $this->storeNewFieldData($versionInfo, $field);
69 }
70
71 $field->value->data = [
72 'sortKey' => $field->value->externalData['address'],
73 'hasData' => true,
74 ];
75
76 return true;
77 }
78
87 protected function updateFieldData(VersionInfo $versionInfo, Field $field)
88 {
89 $connection = $this->getConnection();
90
91 $updateQuery = $connection->createUpdateQuery();
92 $updateQuery->update($connection->quoteTable('ezgmaplocation'))
93 ->set(
94 $connection->quoteColumn('latitude'),
95 $updateQuery->bindValue($field->value->externalData['latitude'])
96 )->set(
97 $connection->quoteColumn('longitude'),
98 $updateQuery->bindValue($field->value->externalData['longitude'])
99 )->set(
100 $connection->quoteColumn('address'),
101 $updateQuery->bindValue($field->value->externalData['address'])
102 )->where(
103 $updateQuery->expr->lAnd(
104 $updateQuery->expr->eq(
105 $connection->quoteColumn('contentobject_attribute_id'),
106 $updateQuery->bindValue($field->id, null, \PDO::PARAM_INT)
107 ),
108 $updateQuery->expr->eq(
109 $connection->quoteColumn('contentobject_version'),
110 $updateQuery->bindValue($versionInfo->versionNo, null, \PDO::PARAM_INT)
111 )
112 )
113 );
114
115 $updateQuery->prepare()->execute();
116 }
117
124 protected function storeNewFieldData(VersionInfo $versionInfo, Field $field)
125 {
126 $connection = $this->getConnection();
127
128 $insertQuery = $connection->createInsertQuery();
129 $insertQuery->insertInto($connection->quoteTable('ezgmaplocation'))
130 ->set(
131 $connection->quoteColumn('latitude'),
132 $insertQuery->bindValue($field->value->externalData['latitude'])
133 )->set(
134 $connection->quoteColumn('longitude'),
135 $insertQuery->bindValue($field->value->externalData['longitude'])
136 )->set(
137 $connection->quoteColumn('address'),
138 $insertQuery->bindValue($field->value->externalData['address'])
139 )->set(
140 $connection->quoteColumn('contentobject_attribute_id'),
141 $insertQuery->bindValue($field->id, null, \PDO::PARAM_INT)
142 )->set(
143 $connection->quoteColumn('contentobject_version'),
144 $insertQuery->bindValue($versionInfo->versionNo, null, \PDO::PARAM_INT)
145 );
146
147 $insertQuery->prepare()->execute();
148 }
149
158 public function getFieldData(VersionInfo $versionInfo, Field $field)
159 {
160 $field->value->externalData = $this->loadFieldData($field->id, $versionInfo->versionNo);
161 }
162
172 protected function loadFieldData($fieldId, $versionNo)
173 {
174 $connection = $this->getConnection();
175
176 $selectQuery = $connection->createSelectQuery();
177 $selectQuery->select(
178 $connection->quoteColumn('latitude'),
179 $connection->quoteColumn('longitude'),
180 $connection->quoteColumn('address')
181 )->from(
182 $connection->quoteTable('ezgmaplocation')
183 )->where(
184 $selectQuery->expr->lAnd(
185 $selectQuery->expr->eq(
186 $connection->quoteColumn('contentobject_attribute_id'),
187 $selectQuery->bindValue($fieldId, null, \PDO::PARAM_INT)
188 ),
189 $selectQuery->expr->eq(
190 $connection->quoteColumn('contentobject_version'),
191 $selectQuery->bindValue($versionNo, null, \PDO::PARAM_INT)
192 )
193 )
194 );
195
196 $statement = $selectQuery->prepare();
197 $statement->execute();
198
199 $rows = $statement->fetchAll(\PDO::FETCH_ASSOC);
200
201 if (!isset($rows[0])) {
202 return null;
203 }
204
205 // Cast coordinates as the DB can return them as strings
206 $rows[0]['latitude'] = (float)$rows[0]['latitude'];
207 $rows[0]['longitude'] = (float)$rows[0]['longitude'];
208
209 return $rows[0];
210 }
211
220 protected function hasFieldData($fieldId, $versionNo)
221 {
222 return $this->loadFieldData($fieldId, $versionNo) !== null;
223 }
224
231 public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds)
232 {
233 if (empty($fieldIds)) {
234 // Nothing to do
235 return;
236 }
237
238 $connection = $this->getConnection();
239
240 $deleteQuery = $connection->createDeleteQuery();
241 $deleteQuery->deleteFrom(
242 $connection->quoteTable('ezgmaplocation')
243 )->where(
244 $deleteQuery->expr->lAnd(
245 $deleteQuery->expr->in(
246 $connection->quoteColumn('contentobject_attribute_id'),
247 $fieldIds
248 ),
249 $deleteQuery->expr->eq(
250 $connection->quoteColumn('contentobject_version'),
251 $deleteQuery->bindValue($versionInfo->versionNo, null, \PDO::PARAM_INT)
252 )
253 )
254 );
255
256 $deleteQuery->prepare()->execute();
257 }
258 }
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:18
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\getConnection
getConnection()
Returns the active connection.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:36
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\deleteFieldData
deleteFieldData(VersionInfo $versionInfo, array $fieldIds)
Deletes the data for all given $fieldIds.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:231
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\loadFieldData
loadFieldData($fieldId, $versionNo)
Returns the data for the given $fieldId.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:172
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\hasFieldData
hasFieldData($fieldId, $versionNo)
Returns if field data exists for $fieldId.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:220
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\getFieldData
getFieldData(VersionInfo $versionInfo, Field $field)
Sets the loaded field data into $field->externalData.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:158
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\updateFieldData
updateFieldData(VersionInfo $versionInfo, Field $field)
Performs an update on the field data.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:87
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\storeNewFieldData
storeNewFieldData(VersionInfo $versionInfo, Field $field)
Stores new field data.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:124
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\__construct
__construct(DatabaseHandler $dbHandler)
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:22
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\storeFieldData
storeFieldData(VersionInfo $versionInfo, Field $field)
Stores the data stored in the given $field.
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:52
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway\LegacyStorage\$dbHandler
$dbHandler
Definition: MapLocation/MapLocationStorage/Gateway/LegacyStorage.php:20
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway
MapLocation Field Type external storage gateway.
Definition: FieldType/MapLocation/MapLocationStorage/Gateway.php:17
eZ\Publish\SPI\Persistence\Content\Field
Definition: SPI/Persistence/Content/Field.php:12
eZ\Publish\SPI\Persistence\Content\VersionInfo
This class holds version information data.
Definition: SPI/Persistence/Content/VersionInfo.php:15
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\FieldType\MapLocation\MapLocationStorage\Gateway
Definition: MapLocation/MapLocationStorage/Gateway/DoctrineStorage.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.