From c09aa02a7842073585b4b0699ae71411d8708abb Mon Sep 17 00:00:00 2001 From: John Flatness Date: Thu, 21 Dec 2023 18:07:35 -0500 Subject: [PATCH] Use direct query for updating media positions Repository usage was causing incorrect duplicate insert attempts from Doctrine. --- src/Job/Import.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Job/Import.php b/src/Job/Import.php index 14bfca5..185fc77 100644 --- a/src/Job/Import.php +++ b/src/Job/Import.php @@ -607,14 +607,16 @@ protected function reorderMedias(array $resources) } // Update positions of the updated media. - $entityManager = $services->get('Omeka\EntityManager'); - $mediaRepository = $entityManager->getRepository(\Omeka\Entity\Media::class); - $medias = $mediaRepository->findById(array_keys($mediaRanks)); - foreach ($medias as $media) { - $rank = $mediaRanks[$media->getId()]; - $media->setPosition($rank); + $conn->beginTransaction(); + try { + $updateQuery = 'UPDATE media SET position = ? WHERE id = ?'; + foreach ($mediaRanks as $id => $rank) { + $conn->executeQuery($updateQuery, [$rank, $id], ['integer', 'integer']); + } + $conn->commit(); + } catch (\Exception $e) { + $conn->rollBack(); } - $entityManager->flush(); } /**