Unverified Commit 5c5183d3 authored by Sebastian Castro's avatar Sebastian Castro
Browse files

Fix removing element from nonDuplicates and potentialDuplicates when deleting them

parent ed614196
......@@ -123,4 +123,7 @@ db.Element.find({'data.image': {$exists: true}}).forEach(function(e) {
e.images = images;
delete e.data.image;
db.Element.save(e);
});
\ No newline at end of file
});
db.Element.updateMany({'nonDuplicates.$id': "KBL"}, { $unset: { 'nonDuplicates': ''} })
......@@ -219,8 +219,25 @@ class ElementAdminBulkController extends Controller
}
// Perform remove
$selectedModelQuery->remove()->getQuery()->execute();
$modelManager = $this->admin->getModelManager();
try {
$modelManager->batchDelete($this->admin->getClass(), $selectedModelQuery);
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_batch_delete_success', [], 'SonataAdminBundle')
);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash(
'sonata_flash_error',
$this->trans('flash_batch_delete_error', [], 'SonataAdminBundle')
);
}
// $selectedModelQuery->findAndRemove()->getQuery()->execute();
$this->dm->createQueryBuilder(UserInteractionContribution::class)->field('element.id')->in($elementIds)->remove()->getQuery()->execute();
$this->dm->flush();
return new RedirectResponse($this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()]));
......
......@@ -48,8 +48,8 @@ class DatabaseIntegrityWatcher
} elseif ($document instanceof Webhook) {
$webhook = $document;
$contributions = $dm->createQueryBuilder('App\Document\UserInteractionContribution')
->field('webhookPosts.webhook.$id')->equals($webhook->getId())
->getQuery()->execute();
->field('webhookPosts.webhook.$id')->equals($webhook->getId())
->getQuery()->execute();
foreach ($contributions as $contrib) {
$contrib->getElement()->setPreventJsonUpdate(true);
......@@ -59,6 +59,16 @@ class DatabaseIntegrityWatcher
}
}
}
} elseif ($document instanceof Element) {
// remove dependance from nonDuplicates and potentialDuplicates
$qb = $dm->createQueryBuilder('App\Document\Element');
$qb->addOr($qb->expr()->field('nonDuplicates.$id')->equals($document->getId()));
$qb->addOr($qb->expr()->field('potentialDuplicates.$id')->equals($document->getId()));
$dependantElements = $qb->getQuery()->execute();
foreach ($dependantElements as $element) {
$element->removeNonDuplicate($document);
$element->removePotentialDuplicate($document);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment