12
12
use Doctrine \DBAL \Types \Type ;
13
13
use Doctrine \ORM \EntityManager ;
14
14
use Doctrine \ORM \Mapping \ClassMetadata ;
15
- use Doctrine \ORM \Mapping \ClassMetadataInfo ;
16
15
use Doctrine \ORM \PersistentCollection ;
17
16
use Doctrine \ORM \Persisters \Entity \EntityPersister ;
17
+ use RuntimeException ;
18
18
19
19
/**
20
20
* Based on the work of
@@ -80,23 +80,23 @@ public function findRevisionsByCriteria(string $className, array $criteria): His
80
80
81
81
// Check if the given criteria are indeed available in the object
82
82
// and create the actual where query
83
- $ whereSql = "" ;
83
+ $ whereSql = '' ;
84
84
foreach ($ criteria as $ criterium => $ data ) {
85
85
if ($ whereSql ) {
86
- $ whereSql .= " AND " ;
86
+ $ whereSql .= ' AND ' ;
87
87
}
88
88
if ($ metadata ->hasField ($ criterium )) {
89
- $ whereSql .= " h. " . $ metadata ->getFieldMapping ($ criterium )['columnName ' ] . " = ? " ;
89
+ $ whereSql .= ' h. ' . $ metadata ->getFieldMapping ($ criterium )['columnName ' ] . ' = ? ' ;
90
90
} else if ($ metadata ->hasAssociation ($ criterium )) {
91
- $ whereSql .= " h. " . $ metadata ->getAssociationMapping ($ criterium )['joinColumns ' ][0 ]['name ' ] . " = ? " ;
91
+ $ whereSql .= ' h. ' . $ metadata ->getAssociationMapping ($ criterium )['joinColumns ' ][0 ]['name ' ] . ' = ? ' ;
92
92
} else {
93
93
throw new IncorrectCriteriaException ($ criterium , $ className );
94
94
}
95
95
}
96
96
97
97
// Create the query with the where statement
98
98
$ tableName = $ this ->config ->getTableName ($ metadata ->getTableName ());
99
- $ query = 'SELECT * FROM ' . $ tableName . ' h WHERE ' . $ whereSql . " ORDER BY h.id DESC " ;
99
+ $ query = 'SELECT * FROM ' . $ tableName . ' h WHERE ' . $ whereSql . ' ORDER BY h.id DESC ' ;
100
100
101
101
// Execute query
102
102
$ revisions = $ this ->em ->getConnection ()->fetchAllAssociative ($ query , array_values ($ criteria ));
@@ -131,7 +131,7 @@ public function restoreObject(string $className, &$dbObject, HistoryRevision $re
131
131
if ($ oldValue != $ newValue ) {
132
132
$ metadata ->setFieldValue ($ dbObject , $ associationName , $ newValue );
133
133
$ uow ->propertyChanged ($ dbObject , $ associationName , $ oldValue , $ newValue );
134
- $ changeset [$ associationName ] = array ( $ oldValue , $ newValue) ;
134
+ $ changeset [$ associationName ] = [ $ oldValue , $ newValue] ;
135
135
}
136
136
}
137
137
@@ -143,15 +143,15 @@ public function restoreObject(string $className, &$dbObject, HistoryRevision $re
143
143
$ oldValue = $ metadata ->getFieldValue ($ dbObject , $ this ->config ->getDeletedAtField ());
144
144
$ metadata ->setFieldValue ($ dbObject , $ this ->config ->getDeletedAtField (), null );
145
145
$ uow ->propertyChanged ($ dbObject , $ this ->config ->getDeletedAtField (), $ oldValue , null );
146
- $ changeset [$ this ->config ->getDeletedAtField ()] = array ( $ oldValue , null ) ;
146
+ $ changeset [$ this ->config ->getDeletedAtField ()] = [ $ oldValue , null ] ;
147
147
}
148
148
149
149
// Check if there is a deletedBy field configured which we can clear
150
150
if (null !== ($ deletedByField = $ this ->config ->getDeletedByField ())) {
151
151
$ oldValue = $ metadata ->getFieldValue ($ dbObject , $ this ->config ->getDeletedByField ());
152
152
$ metadata ->setFieldValue ($ dbObject , $ this ->config ->getDeletedByField (), null );
153
153
$ uow ->propertyChanged ($ dbObject , $ this ->config ->getDeletedByField (), $ oldValue , null );
154
- $ changeset [$ this ->config ->getDeletedByField ()] = array ( $ oldValue , null ) ;
154
+ $ changeset [$ this ->config ->getDeletedByField ()] = [ $ oldValue , null ] ;
155
155
}
156
156
}
157
157
@@ -201,7 +201,6 @@ private function getMetadata(string $className): false|ClassMetadata {
201
201
* Simplified and stolen code from UnitOfWork::createEntity.
202
202
*/
203
203
private function createEntity (string $ className , array $ data , $ revision ): object {
204
- /** @var ClassMetadataInfo|ClassMetadata $class */
205
204
$ class = $ this ->em ->getClassMetadata ($ className );
206
205
//lookup revisioned entity cache
207
206
$ keyParts = [];
@@ -215,22 +214,22 @@ private function createEntity(string $className, array $data, $revision): object
215
214
216
215
if (!$ class ->isInheritanceTypeNone ()) {
217
216
if (!isset ($ data [$ class ->discriminatorColumn ['name ' ]])) {
218
- throw new \ RuntimeException ('Expecting discriminator value in data set. ' );
217
+ throw new RuntimeException ('Expecting discriminator value in data set. ' );
219
218
}
220
219
$ discriminator = $ data [$ class ->discriminatorColumn ['name ' ]];
221
220
if (!isset ($ class ->discriminatorMap [$ discriminator ])) {
222
- throw new \ RuntimeException ("No mapping found for [ {$ discriminator }]. " );
221
+ throw new RuntimeException ("No mapping found for [ {$ discriminator }]. " );
223
222
}
224
223
if ($ class ->discriminatorValue ) {
225
224
$ entity = $ this ->em ->getClassMetadata ($ class ->discriminatorMap [$ discriminator ])->newInstance ();
226
225
} else {
227
226
//a complex case when ToOne binding is against AbstractEntity having no discriminator
228
- $ pk = array () ;
227
+ $ pk = [] ;
229
228
foreach ($ class ->identifier as $ field ) {
230
229
$ pk [$ class ->getColumnName ($ field )] = $ data [$ field ];
231
230
}
232
231
// return $this->find($class->discriminatorMap[$discriminator], $pk, $revision);
233
- throw new \ RuntimeException ("This is not supported " );
232
+ throw new RuntimeException ("This is not supported " );
234
233
}
235
234
} else {
236
235
$ entity = $ class ->newInstance ();
@@ -249,9 +248,8 @@ private function createEntity(string $className, array $data, $revision): object
249
248
if (isset ($ hints ['fetched ' ][$ className ][$ field ])) {
250
249
continue ;
251
250
}
252
- /** @var ClassMetadataInfo|ClassMetadata $targetClass */
253
251
$ targetClass = $ this ->em ->getClassMetadata ($ assoc ['targetEntity ' ]);
254
- if ($ assoc ['type ' ] & ClassMetadataInfo ::TO_ONE ) {
252
+ if ($ assoc ['type ' ] & ClassMetadata ::TO_ONE ) {
255
253
if ($ assoc ['isOwningSide ' ]) {
256
254
$ associatedId = array ();
257
255
foreach ($ assoc ['targetToSourceKeyColumns ' ] as $ targetColumn => $ srcColumn ) {
@@ -272,7 +270,7 @@ private function createEntity(string $className, array $data, $revision): object
272
270
$ class ->reflFields [$ field ]->setValue ($ entity , $ this ->getEntityPersister ($ assoc ['targetEntity ' ])
273
271
->loadOneToOneEntity ($ assoc , $ entity ));
274
272
}
275
- } elseif ($ assoc ['type ' ] & ClassMetadataInfo ::ONE_TO_MANY ) {
273
+ } elseif ($ assoc ['type ' ] & ClassMetadata ::ONE_TO_MANY ) {
276
274
$ collection = new PersistentCollection ($ this ->em , $ targetClass , new ArrayCollection ());
277
275
$ this ->getEntityPersister ($ assoc ['targetEntity ' ])
278
276
->loadOneToManyCollection ($ assoc , $ entity , $ collection );
0 commit comments