Skip to content

Commit d074bda

Browse files
authored
Merge 1.x into 2.x
2 parents a7d6fa8 + 206fa56 commit d074bda

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [1.17.0](https://github.com/sonata-project/EntityAuditBundle/compare/1.16.1...1.17.0) - 2024-04-13
6+
### Changed
7+
- [[#612](https://github.com/sonata-project/EntityAuditBundle/pull/612)] Multiple queries to tables have been replaced with a single one ([@SavageDays](https://github.com/SavageDays))
8+
59
## [1.16.1](https://github.com/sonata-project/EntityAuditBundle/compare/1.16.0...1.16.1) - 2024-01-22
610
### Fixed
711
- [[#599](https://github.com/sonata-project/EntityAuditBundle/pull/599)] Objects now no longer show as different when their values are the same. This restores some of the old behaviour of the EntityAuditBundle ([@befresh-mweimerskirch](https://github.com/befresh-mweimerskirch))

src/EventListener/LogRevisionsListener.php

+31-24
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
115115
continue;
116116
}
117117

118+
$sql = 'UPDATE '.$this->config->getTableName($meta).' ';
119+
$params = $types = [];
120+
118121
foreach ($updateData[$meta->table['name']] as $column => $value) {
119122
$field = $meta->getFieldName($column);
120123
$fieldName = $meta->getFieldForColumn($column);
@@ -128,13 +131,15 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
128131
}
129132
}
130133

131-
$sql = 'UPDATE '.$this->config->getTableName($meta).' '.
132-
'SET '.$field.' = '.$placeholder.' '.
133-
'WHERE '.$this->config->getRevisionFieldName().' = ? ';
134+
if ($column === array_key_first($updateData[$meta->table['name']])) {
135+
$sql .= 'SET ';
136+
} else {
137+
$sql = trim($sql).', ';
138+
}
134139

135-
$params = [$value, $this->getRevisionId($conn)];
140+
$sql .= $field.' = '.$placeholder.' ';
136141

137-
$types = [];
142+
$params[] = $value;
138143

139144
if (\array_key_exists($column, $meta->fieldNames)) {
140145
$types[] = $meta->getTypeOfField($fieldName);
@@ -161,29 +166,31 @@ public function postFlush(PostFlushEventArgs $eventArgs): void
161166

162167
$types[] = $type;
163168
}
169+
}
164170

165-
$types[] = $this->config->getRevisionIdFieldType();
166-
167-
foreach ($meta->identifier as $idField) {
168-
if (isset($meta->fieldMappings[$idField])) {
169-
$columnName = $meta->fieldMappings[$idField]['columnName'];
170-
$types[] = $meta->fieldMappings[$idField]['type'];
171-
} elseif (isset($meta->associationMappings[$idField]['joinColumns'])) {
172-
$columnName = $meta->associationMappings[$idField]['joinColumns'][0]['name'];
173-
$types[] = $meta->associationMappings[$idField]['type'];
174-
} else {
175-
throw new \RuntimeException('column name not found for'.$idField);
176-
}
177-
178-
$reflField = $meta->reflFields[$idField];
179-
\assert(null !== $reflField);
180-
$params[] = $reflField->getValue($entity);
181-
182-
$sql .= ' AND '.$columnName.' = ?';
171+
$sql .= 'WHERE '.$this->config->getRevisionFieldName().' = ? ';
172+
$params[] = $this->getRevisionId($conn);
173+
$types[] = $this->config->getRevisionIdFieldType();
174+
175+
foreach ($meta->identifier as $idField) {
176+
if (isset($meta->fieldMappings[$idField])) {
177+
$columnName = $meta->fieldMappings[$idField]['columnName'];
178+
$types[] = $meta->fieldMappings[$idField]['type'];
179+
} elseif (isset($meta->associationMappings[$idField]['joinColumns'])) {
180+
$columnName = $meta->associationMappings[$idField]['joinColumns'][0]['name'];
181+
$types[] = $meta->associationMappings[$idField]['type'];
182+
} else {
183+
throw new \RuntimeException('column name not found for'.$idField);
183184
}
184185

185-
$em->getConnection()->executeQuery($sql, $params, $types);
186+
$reflField = $meta->reflFields[$idField];
187+
\assert(null !== $reflField);
188+
$params[] = $reflField->getValue($entity);
189+
190+
$sql .= ' AND '.$columnName.' = ?';
186191
}
192+
193+
$em->getConnection()->executeQuery($sql, $params, $types);
187194
}
188195

189196
foreach ($this->deferredChangedManyToManyEntityRevisionsToPersist as $deferredChangedManyToManyEntityRevisionToPersist) {

0 commit comments

Comments
 (0)