Skip to content

Commit

Permalink
Merge pull request #151 from pimcore/segment_assignment_transaction
Browse files Browse the repository at this point in the history
SegmentAssigner Query Execution
  • Loading branch information
brusch authored Feb 13, 2020
2 parents 3be7586 + ccd9a35 commit c5e5de0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/SegmentAssignment/SegmentAssigner/SegmentAssigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,27 @@ public function removeElementById(string $elementId, string $type): bool

try {
$deletePattern = 'DELETE FROM %s WHERE `elementId` = :elementId AND `elementType` = :elementType; ';

$statement = sprintf($deletePattern, $this->getSegmentAssignmentTable()) .
sprintf($deletePattern, $this->getSegmentAssignmentQueueTable()) .
sprintf($deletePattern, $this->getSegmentAssignmentIndexTable());
$tables = [
$this->getSegmentAssignmentTable(),
$this->getSegmentAssignmentQueueTable(),
$this->getSegmentAssignmentIndexTable(),
];

if (!$tActive) {
// start a new transaction
$db->beginTransaction();
}

$this->getDb()->executeQuery($statement,
[
'elementId' => $elementId,
'elementType' => $type
]
);
foreach ($tables as $table) {
$statement = sprintf($deletePattern, $table);

$this->getDb()->executeQuery($statement,
[
'elementId' => $elementId,
'elementType' => $type
]
);
}

if (!$tActive) {
$db->commit();
Expand Down

0 comments on commit c5e5de0

Please sign in to comment.