/** * {@inheritDoc} * * No PHPCR node will be created yet, this only happens on flush. * * For translatable documents has to determine the locale: * * - If there is a non-empty Locale mapping that field value is used * - If the document was previously loaded from the DocumentManager it * has a non-empty Locale mapping * - Otherwise its a new document. The language chooser strategy is asked * for the default language and that is used to store. The field is * updated with the locale. * * @param object $document the document to persist * * @throws InvalidArgumentException if $document is not an object. */ public function persist($document) { if (!is_object($document)) { throw new InvalidArgumentException('Parameter $document needs to be an object, ' . gettype($document) . ' given'); } $this->errorIfClosed(); $this->unitOfWork->scheduleInsert($document); }
/** * {@inheritDoc} * * Persist creates the PHPCR node (but does not map the fields to properties * yet) and populates the @Node, @Nodename and @Id annotations too. This * means that if you use the raw phpcr session you will already see the * nodes in case you need to add children to them. * If you need a raw PHPCR session but do not need to see those newly * created nodes, it is advised to use a separate session. * * For translatable documents has to determine the locale: * * - If there is a non-empty @Locale that field value is used * - If the document was previously loaded from the DocumentManager it has a non-empty @Locale * - Otherwise its a new document. The language chooser strategy is asked for the default language and that is used to store. The field is updated with the locale. */ public function persist($document) { if (!is_object($document)) { throw new \InvalidArgumentException(gettype($document)); } $this->errorIfClosed(); $this->unitOfWork->scheduleInsert($document); }
public function testSchedules() { $user1 = new CmsUser(); $user1->username = '******'; $address = new CmsAddress(); $address->city = "Springfield"; $address->zip = "12354"; $address->country = "Germany"; $user1->address = $address; // getScheduledInserts $this->uow->scheduleInsert($user1); $this->uow->computeChangeSets(); $scheduledInserts = $this->uow->getScheduledInserts(); $this->assertCount(2, $scheduledInserts); $this->assertEquals($user1, current($scheduledInserts)); $this->assertEquals(32, strlen(key($scheduledInserts)), 'Size of key is 32 chars (oid)'); $user1->username = '******'; // getScheduledUpdates $this->uow->commit(); $this->uow->scheduleInsert($user1); $this->uow->computeChangeSets(); $scheduledUpdates = $this->uow->getScheduledUpdates(); $this->assertCount(1, $scheduledUpdates); $this->assertEquals($user1, current($scheduledUpdates)); $this->assertEquals(32, strlen(key($scheduledUpdates)), 'Size of key is 32 chars (oid)'); // getScheduledRemovals $this->uow->scheduleRemove($user1); $scheduledRemovals = $this->uow->getScheduledRemovals(); $this->assertCount(1, $scheduledRemovals); $this->assertEquals($user1, current($scheduledRemovals)); $this->assertEquals(32, strlen(key($scheduledRemovals)), 'Size of key is 32 chars (oid)'); // getScheduledMoves $this->uow->scheduleMove($user1, '/foobar'); $scheduledMoves = $this->uow->getScheduledMoves(); $this->assertCount(1, $scheduledMoves); $this->assertEquals(32, strlen(key($scheduledMoves)), 'Size of key is 32 chars (oid)'); $this->assertEquals(array($user1, '/foobar'), current($scheduledMoves)); }
/** * @covers Doctrine\ODM\PHPCR\UnitOfWork::scheduleRemove * @covers Doctrine\ODM\PHPCR\UnitOfWork::scheduleInsert * @covers Doctrine\ODM\PHPCR\UnitOfWork::doScheduleInsert */ public function testScheduleInsertCancelsScheduleRemove() { $object = new UoWUser(); $object->username = "******"; $object->id = '/somepath'; $this->uow->scheduleInsert($object); $this->uow->scheduleRemove($object); $method = new \ReflectionMethod($this->uow, 'getDocumentState'); $method->setAccessible(true); $state = $method->invoke($this->uow, $object); $method->setAccessible(false); $this->assertEquals(UnitOfWork::STATE_REMOVED, $state); $this->uow->scheduleInsert($object); $method->setAccessible(true); $state = $method->invoke($this->uow, $object); $method->setAccessible(false); $this->assertEquals(UnitOfWork::STATE_MANAGED, $state); }
/** * {@inheritDoc} * * Persist creates the PHPCR node (but does not map the fields to properties * yet) and populates the @Node, @Nodename and @Id annotations too. This * means that if you use the raw phpcr session you will already see the * nodes in case you need to add children to them. * If you need a raw PHPCR session but do not need to see those newly * created nodes, it is advised to use a separate session. * * For translatable documents has to determine the locale: * * - If there is a non-empty @Locale that field value is used * - If the document was previously loaded from the DocumentManager it has a non-empty @Locale * - Otherwise its a new document. The language chooser strategy is asked for the default language and that is used to store. The field is updated with the locale. */ public function persist($object) { $this->errorIfClosed(); $this->unitOfWork->scheduleInsert($object); }