/** * {@inheritdoc} */ public function remove($group, array $options = []) { if (!$group instanceof GroupInterface) { throw new \InvalidArgumentException(sprintf('Expects an "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\GroupInterface', ClassUtils::getClass($group))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $this->eventDispatcher->dispatch(GroupEvents::PRE_REMOVE, new GenericEvent($group)); $this->objectManager->remove($group); if (true === $options['flush']) { $this->objectManager->flush(); } }
/** * {@inheritdoc} */ public function remove($object, array $options = []) { if (!$object instanceof $this->removedClass) { throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', $this->removedClass, ClassUtils::getClass($object))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $this->objectManager->remove($object); if (true === $options['flush'] && true === $options['flush_only_object']) { $this->objectManager->flush($object); } elseif (true === $options['flush']) { $this->objectManager->flush(); } }
/** * {@inheritdoc} */ public function remove($attribute, array $options = []) { if (!$attribute instanceof AttributeInterface) { throw new \InvalidArgumentException(sprintf('Expects an "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\AttributeInterface', ClassUtils::getClass($attribute))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $this->eventDispatcher->dispatch(AttributeEvents::PRE_REMOVE, new GenericEvent($attribute)); $this->removeFromProductTemplate($attribute); $this->objectManager->remove($attribute); if (true === $options['flush']) { $this->objectManager->flush(); } $this->eventDispatcher->dispatch(AttributeEvents::POST_REMOVE, new GenericEvent($attribute)); }
/** * {@inheritdoc} */ public function remove($object, array $options = []) { if (!$object instanceof $this->removedClass) { throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', $this->removedClass, ClassUtils::getClass($object))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $objectId = $object->getId(); $this->eventDispatcher->dispatch(StorageEvents::PRE_REMOVE, new RemoveEvent($object, $objectId, $options)); $this->objectManager->remove($object); if (true === $options['flush']) { $this->objectManager->flush(); } $this->eventDispatcher->dispatch(StorageEvents::POST_REMOVE, new RemoveEvent($object, $objectId, $options)); }
/** * {@inheritdoc} */ public function remove($product, array $options = []) { if (!$product instanceof ProductInterface) { throw new \InvalidArgumentException(sprintf('Expects an "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\ProductInterface', ClassUtils::getClass($product))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $productId = $product->getId(); $this->eventDispatcher->dispatch(ProductEvents::PRE_REMOVE, new RemoveEvent($product, $productId)); $this->objectManager->remove($product); if (true === $options['flush']) { $this->objectManager->flush(); } $this->eventDispatcher->dispatch(ProductEvents::POST_REMOVE, new RemoveEvent($product, $productId)); }
/** * {@inheritdoc} */ public function remove($channel, array $options = []) { if (!$channel instanceof ChannelInterface) { throw new \InvalidArgumentException(sprintf('Expects an "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\ChannelInterface', ClassUtils::getClass($channel))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $this->eventDispatcher->dispatch(ChannelEvents::PRE_REMOVE, new GenericEvent($channel)); $this->objectManager->remove($channel); if (isset($options['flush_only_object']) && true === $options['flush_only_object']) { $this->objectManager->flush($channel); } elseif (true === $options['flush']) { $this->objectManager->flush(); } }
/** * {@inheritdoc} */ public function remove($category, array $options = []) { if (!$category instanceof CategoryInterface) { throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\CategoryInterface', ClassUtils::getClass($category))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY; $this->eventDispatcher->dispatch($eventName, new GenericEvent($category)); foreach ($category->getProducts() as $product) { $product->removeCategory($category); } $this->objectManager->remove($category); if (true === $options['flush']) { $this->objectManager->flush(); } }
/** * {@inheritdoc} */ public function remove($category, array $options = []) { if (!$category instanceof CategoryInterface) { throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\CategoryInterface', ClassUtils::getClass($category))); } $options = $this->optionsResolver->resolveRemoveOptions($options); $categoryId = $category->getId(); $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY; $this->eventDispatcher->dispatch($eventName, new RemoveEvent($category, $categoryId)); $productsToUpdate = []; foreach ($category->getProducts() as $product) { $product->removeCategory($category); $productsToUpdate[] = $product; } $this->objectManager->remove($category); if (true === $options['flush']) { $this->objectManager->flush(); } if (count($productsToUpdate) > 0) { $this->productSaver->saveAll($productsToUpdate, ['flush' => $options['flush'], 'recalculate' => false, 'schedule' => false]); } $eventName = $category->isRoot() ? CategoryEvents::POST_REMOVE_TREE : CategoryEvents::POST_REMOVE_CATEGORY; $this->eventDispatcher->dispatch($eventName, new RemoveEvent($category, $categoryId)); }