From cb69ddfa674472b709e677b10861246f0dfa2ac8 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 3 Oct 2018 06:44:35 -0700 Subject: [PATCH] Cleanup --- src/services/Matrix.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/Matrix.php b/src/services/Matrix.php index 932996910f8..e50def5c192 100644 --- a/src/services/Matrix.php +++ b/src/services/Matrix.php @@ -633,6 +633,8 @@ public function saveField(MatrixField $field, ElementInterface $owner) $blocks = $query->all(); } + $elementsService = Craft::$app->getElements(); + $transaction = Craft::$app->getDb()->beginTransaction(); try { // If this is a preexisting element, make sure that the blocks for this field/owner respect the field's translation setting @@ -647,7 +649,6 @@ public function saveField(MatrixField $field, ElementInterface $owner) $newQuery->ownerId = $owner->id; if (!$newQuery->exists()) { // Duplicate the blocks for the new owner - $elementsService = Craft::$app->getElements(); foreach ($blocks as $block) { $elementsService->duplicateElement($block, [ 'ownerId' => $owner->id, @@ -667,7 +668,7 @@ public function saveField(MatrixField $field, ElementInterface $owner) $block->ownerSiteId = ($field->localizeBlocks ? $owner->siteId : null); $block->propagating = $owner->propagating; - Craft::$app->getElements()->saveElement($block, false, $propagate); + $elementsService->saveElement($block, false, $propagate); $blockIds[] = $block->id;