4
4
5
5
use BobV \EntityHistoryBundle \Configuration \HistoryConfiguration ;
6
6
use Doctrine \Common \EventSubscriber ;
7
+ use Doctrine \DBAL \Connection ;
8
+ use Doctrine \DBAL \DBALException ;
9
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
7
10
use Doctrine \DBAL \Types \Type ;
11
+ use Doctrine \ORM \EntityManager ;
8
12
use Doctrine \ORM \Event \LifecycleEventArgs ;
9
13
use Doctrine \ORM \Event \OnFlushEventArgs ;
10
14
use Doctrine \ORM \Events ;
15
+ use Doctrine \ORM \Mapping \AnsiQuoteStrategy ;
11
16
use Doctrine \ORM \Mapping \ClassMetadata ;
17
+ use Doctrine \ORM \Mapping \DefaultQuoteStrategy ;
18
+ use Doctrine \ORM \UnitOfWork ;
12
19
13
20
/**
14
21
* Class LogHistorySubscriber
@@ -28,23 +35,23 @@ class LogHistorySubscriber implements EventSubscriber
28
35
*/
29
36
private $ config ;
30
37
/**
31
- * @var \Doctrine\DBAL\ Connection
38
+ * @var Connection
32
39
*/
33
40
private $ conn ;
34
41
/**
35
- * @var \Doctrine\ORM\ EntityManager
42
+ * @var EntityManager
36
43
*/
37
44
private $ em ;
38
45
/**
39
46
* @var array
40
47
*/
41
48
private $ insertRevisionSQL = array ();
42
49
/**
43
- * @var \Doctrine\DBAL\Platforms\ AbstractPlatform
50
+ * @var AbstractPlatform
44
51
*/
45
52
private $ platform ;
46
53
/**
47
- * @var \Doctrine\ORM\ UnitOfWork
54
+ * @var UnitOfWork
48
55
*/
49
56
private $ uow ;
50
57
@@ -100,6 +107,9 @@ public function postPersist(LifecycleEventArgs $eventArgs)
100
107
$ this ->saveRevisionEntityData ($ class , $ this ->getOriginalEntityData ($ entity ), 'INS ' );
101
108
}
102
109
110
+ /**
111
+ * @param LifecycleEventArgs $eventArgs
112
+ */
103
113
public function postUpdate (LifecycleEventArgs $ eventArgs )
104
114
{
105
115
// onFlush was executed before, everything already initialized
@@ -114,6 +124,12 @@ public function postUpdate(LifecycleEventArgs $eventArgs)
114
124
$ this ->saveRevisionEntityData ($ class , $ entityData , 'UPD ' );
115
125
}
116
126
127
+ /**
128
+ * @param ClassMetadata $class
129
+ *
130
+ * @return string
131
+ * @throws DBALException
132
+ */
117
133
private function getInsertRevisionSQL ($ class )
118
134
{
119
135
if (!isset ($ this ->insertRevisionSQL [$ class ->name ])) {
@@ -145,7 +161,7 @@ private function getInsertRevisionSQL($class)
145
161
$ placeholders [] = (!empty ($ class ->fieldMappings [$ field ]['requireSQLConversion ' ]))
146
162
? $ type ->convertToDatabaseValueSQL ('? ' , $ this ->platform )
147
163
: '? ' ;
148
- $ sql .= ', ' . $ class -> getQuotedColumnName ( $ field , $ this ->platform );
164
+ $ sql .= ', ' . $ this -> em -> getConfiguration ()-> getQuoteStrategy ()-> getColumnName ( $ field, $ class , $ this ->platform );
149
165
}
150
166
151
167
$ sql .= ") VALUES ( " . implode (", " , $ placeholders ) . ") " ;
@@ -230,8 +246,8 @@ private function saveRevisionEntityData($class, $entityData, $revType)
230
246
231
247
foreach ($ class ->associationMappings AS $ field => $ assoc ) {
232
248
if (($ assoc ['type ' ] & ClassMetadata::TO_ONE ) > 0 && $ assoc ['isOwningSide ' ]) {
233
- $ targetClass = $ this ->em ->getClassMetadata ($ assoc ['targetEntity ' ]);
234
249
250
+ $ relatedId = NULL ;
235
251
if ($ entityData [$ field ] !== NULL ) {
236
252
$ relatedId = $ this ->uow ->getEntityIdentifier ($ entityData [$ field ]);
237
253
}
0 commit comments