Any modifications to the entity will be ignored; the persisted state (ID, relationships) of the entity will be
deleted.
If a new entity is passed to this function, any persisted entity with matching ID & class will be deleted. No
error will be raised if a persisted entity is not matched.
/** * @dataProvider entityManagerDataProvider * @param EntityManager $em */ public function testRefs(EntityManager $em) { $members = $em->getDriver()->getMultiValueIndex($em->getKeyScheme()->getEntityRefKey('leaf', 'leaf1')); $this->assertCount(0, $members); $leaf = (new Leaf())->setId('leaf1'); $owner = (new Owner())->setId('owner1')->setLeaf([$leaf]); $em->persist($leaf)->persist($owner)->flush(); $members = $em->getDriver()->getMultiValueIndex($em->getKeyScheme()->getEntityRefKey('leaf', 'leaf1')); $this->assertCount(1, $members); $ref = new Ref(Owner::class, 'owner1', 'leaf'); $this->assertEquals((string) $ref, $members[0]); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(1, $leaves); $em->refresh($owner); $em->refresh($leaf); $leaf->setPublished(false); $em->persist($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(0, $leaves); $leaf->setPublished(true); $em->persist($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(1, $leaves); $em->delete($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(0, $leaves); }
/** * Destroys a session. * * If the session does not exist this function will return true anyway. * * @param string $sessionId Session ID, see http://php.net/function.session-id * @return bool true on success, false on failure */ public function destroy($sessionId) { /** @var SessionInterface $session */ $session = new $this->session_class(); $session->setId($sessionId); $this->entity_manager->delete($session)->flush(); return true; }
/** * Deletes all items in the pool. * * @return PoolInterface */ public function clear() { $items = $this->em->sortedQuery(new SortedTableQuery($this->entity_class, 'key'), false, false); $index = 0; $items->rewind(); while ($items->valid()) { try { $item = $items->current(); $this->em->delete($item); if (++$index % 100 == 0) { $this->em->flush(); } } catch (NotFoundException $e) { // Assume item expired, skip } $items->next(); } $this->em->flush(); return $this; }