本文整理汇总了PHP中Doctrine\ODM\PHPCR\DocumentManager::flush方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::flush方法的具体用法?PHP DocumentManager::flush怎么用?PHP DocumentManager::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReferenceOneDifferentTargetDocuments
public function testReferenceOneDifferentTargetDocuments()
{
$ref1 = new RefType1TestObj();
$ref1->id = '/functional/ref1';
$ref1->name = 'Ref1';
$ref2 = new RefType2TestObj();
$ref2->id = '/functional/ref2';
$ref2->name = 'Ref2';
$this->dm->persist($ref1);
$this->dm->persist($ref2);
$referer1 = new ReferenceOneObj();
$referer1->id = '/functional/referer1';
$referer1->reference = $ref1;
$this->dm->persist($referer1);
$referer2 = new ReferenceOneObj();
$referer2->id = '/functional/referer2';
$referer2->reference = $ref2;
$this->dm->persist($referer2);
$this->dm->flush();
$this->dm->clear();
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
$this->assertTrue($referer->reference instanceof RefType1TestObj);
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
$this->assertTrue($referer->reference instanceof RefType2TestObj);
}
示例2: createAction
public function createAction()
{
// bind form to page model
$page = new Page();
$this->form->bind($this->request, $page);
if ($this->form->isValid()) {
try {
// path for page
$parent = $this->form->get('parent')->getData();
$path = $parent . '/' . $page->name;
// save page
$this->dm->persist($page, $path);
$this->dm->flush();
// redirect with message
$this->request->getSession()->setFlash('notice', 'Page created!');
return $this->redirect($this->generateUrl('admin'));
} catch (HTTPErrorException $e) {
$path = new PropertyPath('name');
$this->form->addError(new DataError('Name already in use.'), $path->getIterator());
}
}
return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form));
}
示例3: testComputeChangesetTranslatableFind
public function testComputeChangesetTranslatableFind()
{
$this->dm->getEventManager()->addEventListener(array(Event::postUpdate), $this->listener);
// Create initial user
$user1 = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
$user1->name = 'david';
$user1->username = 'dbu';
$user1->status = 'activ';
$this->dm->persist($user1);
$this->dm->bindTranslation($user1, 'en');
$user1->status = 'actif';
$this->dm->bindTranslation($user1, 'fr');
$this->dm->flush();
$this->assertEquals(0, $this->listener->count);
$this->dm->clear();
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$this->dm->findTranslation(null, $user1->id, 'fr');
$this->dm->flush();
$this->assertEquals(0, $this->listener->count);
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$user1->status = 'active';
$this->dm->findTranslation(null, $user1->id, 'fr');
$this->dm->flush();
$this->assertEquals(1, $this->listener->count);
$this->dm->clear();
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$this->assertEquals('active', $user1->status);
}
示例4: testResetEvents
public function testResetEvents()
{
$page = new CmsPage();
$page->title = "my-page";
$pageContent = new CmsPageContent();
$pageContent->id = 1;
$pageContent->content = "long story";
$pageContent->formatter = "plaintext";
$page->content = $pageContent;
$this->dm->persist($page);
$this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content);
$this->dm->flush();
$this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
// This is required as the originalData in the UnitOfWork doesn’t set the node of the Document
$this->dm->clear();
$pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id);
$pageLoaded->title = "my-page-changed";
$this->assertEquals('my-page-changed', $pageLoaded->title);
$this->dm->flush();
$this->assertEquals('my-page', $pageLoaded->title);
$pageLoaded->content = $pageContent;
$this->dm->persist($pageLoaded);
$this->dm->flush();
$this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
}
示例5: testComputingBetweenEventsWithTranslation
public function testComputingBetweenEventsWithTranslation()
{
$this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
$this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
// Create initial user
$user = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
$user->name = 'mdekrijger';
$user->username = 'mdekrijger';
$user->status = 'active';
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
// username should be changed after loading the translation
$this->assertEquals('loadTranslation', $user->username);
// name had been changed pre binding translation
$this->assertEquals('preCreateTranslation', $user->name);
$this->dm->name = 'neuer Name';
$this->dm->bindTranslation($user, 'de');
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
$this->dm->removeTranslation($user, 'en');
$this->assertEquals('preRemoveTranslation', $user->name);
$this->dm->flush();
$this->dm->clear();
$this->assertEquals('postRemoveTranslation', $user->username);
}
示例6: persistGreetingAction
public function persistGreetingAction()
{
$greeting = new Greeting();
$greeting->setContent('Hello World!');
$this->documentManager->persist($greeting);
$this->documentManager->flush();
return array('greeting' => $greeting);
}
示例7: testMenuNode
public function testMenuNode()
{
$data = array('name' => 'test-node', 'label' => 'label_foobar', 'uri' => 'http://www.example.com/foo', 'route' => 'foo_route', 'linkType' => 'route', 'content' => $this->content, 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), 'attributes' => array('attr_foobar_1' => 'barfoo', 'attr_foobar_2' => 'barfoo'), 'childrenAttributes' => array('child_foobar_1' => 'barfoo', 'child_foobar_2' => 'barfoo'), 'linkAttributes' => array('link_foobar_1' => 'barfoo', 'link_foobar_2' => 'barfoo'), 'labelAttributes' => array('label_foobar_1' => 'barfoo', 'label_foobar_2' => 'barfoo'), 'extras' => array('extra_foobar_1' => 'barfoo', 'extra_foobar_2' => 'barfoo'), 'routeParameters' => array('route_param_foobar_1' => 'barfoo', 'route_param_foobar_2' => 'barfoo'), 'routeAbsolute' => true, 'display' => false, 'displayChildren' => false);
$startDateString = $data['publishStartDate']->format('Y-m-d');
$endDateString = $data['publishEndDate']->format('Y-m-d');
$menuNode = new MenuNode();
$refl = new \ReflectionClass($menuNode);
$menuNode->setParentDocument($this->rootDocument);
foreach ($data as $key => $value) {
$refl = new \ReflectionClass($menuNode);
$prop = $refl->getProperty($key);
$prop->setAccessible(true);
$prop->setValue($menuNode, $value);
}
$menuNode->addChild($this->child1);
$this->dm->persist($menuNode);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->find(null, '/test/test-node');
$this->assertNotNull($menuNode);
foreach ($data as $key => $value) {
$prop = $refl->getProperty($key);
$prop->setAccessible(true);
$v = $prop->getValue($menuNode);
if (!is_object($value)) {
$this->assertEquals($value, $v);
}
}
// test objects
$prop = $refl->getProperty('content');
$prop->setAccessible(true);
$content = $prop->getValue($menuNode);
$this->assertEquals('fake_weak_content', $content->getName());
// test children
$this->assertCount(1, $menuNode->getChildren());
// test publish start and end
$publishStartDate = $menuNode->getPublishStartDate();
$publishEndDate = $menuNode->getPublishEndDate();
$this->assertInstanceOf('\\DateTime', $publishStartDate);
$this->assertInstanceOf('\\DateTime', $publishEndDate);
$this->assertEquals($startDateString, $publishStartDate->format('Y-m-d'));
$this->assertEquals($endDateString, $publishEndDate->format('Y-m-d'));
// test multi-lang
$menuNode->setLocale('fr');
$this->dm->persist($menuNode);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->findTranslation(null, '/test/test-node', 'fr');
$this->assertEquals('fr', $menuNode->getLocale());
$child = $this->dm->find(null, '/test/test-node/child1');
$menuNode = $child->getParent();
$this->assertCount(1, $menuNode->getChildren());
$menuNode->removeChild($child);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->find(null, '/test/test-node');
$this->assertCount(0, $menuNode->getChildren());
}
示例8: testDetach
public function testDetach()
{
$user = $this->dm->find($this->type, '/functional/lsmith');
$user->username = "new-name";
$this->dm->detach($user);
$this->dm->flush();
$this->dm->clear();
$newUser = $this->dm->find($this->type, '/functional/lsmith');
$this->assertEquals('lsmith', $newUser->username);
}
示例9: testCreateFromFile
public function testCreateFromFile()
{
$parent = new FixPHPCR1TestObj();
$parent->id = '/functional/filetest';
$this->dm->persist($parent);
$parent->file = new File();
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->getNode('filetest')->hasNode('file'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data'));
}
示例10: testCreateCascade
public function testCreateCascade()
{
$folder = new Folder();
$folder->setId('/functional/folder');
$file = new File();
$file->setFileContent(self::FILE_CONTENT);
$file->setNodename('file');
$folder->addChild($file);
$this->dm->persist($folder);
$this->dm->flush();
$this->dm->clear();
$this->assertFolderAndFile($this->node);
}
示例11: testCreatedDate
public function testCreatedDate()
{
$parent = new FileTestObj();
$parent->file = new File();
$parent->id = '/functional/filetest';
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->persist($parent);
$this->dm->flush();
$this->dm->clear();
$file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file');
$this->assertNotNull($file);
$this->assertNotNull($file->getCreated());
}
示例12: testModificationWithProtectedProperty
public function testModificationWithProtectedProperty()
{
$object = new ProtectedPropertyTestObj();
$object->id = '/functional/pp';
try {
$this->dm->persist($object);
$this->dm->flush();
$object->changeme = 'changed';
$this->dm->flush();
$this->dm->clear();
} catch (\PHPCR\NodeType\ConstraintViolationException $e) {
$this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage()));
}
$this->assertTrue(true);
}
示例13: testUnversionedChildrenOnParentVersion
/**
* Try to access the children of a specific version of a document and assert they
* are hydrated properly
*/
public function testUnversionedChildrenOnParentVersion()
{
$versionableArticle = new FullVersionableArticleWithChildren();
$versionableArticle->author = 'mellowplace';
$versionableArticle->topic = 'children test';
$versionableArticle->id = '/functional/children-test';
$versionableArticle->setText('Parent article text');
$this->dm->persist($versionableArticle);
$childArticle = new NonVersionableArticle();
$childArticle->setText("This is the child");
$childArticle->id = '/functional/children-test/child';
$childArticle->author = 'mellowplace';
$childArticle->topic = 'children test - child';
$versionableArticle->addChildArticle($childArticle);
// checkin the first version (1.0)
$this->dm->flush();
$this->dm->checkpoint($versionableArticle);
// now modify the child nodes text and checkin the second version (1.1)
$childArticle->setText('modified text');
$this->dm->flush();
$this->dm->checkpoint($versionableArticle);
$firstVersion = $this->dm->findVersionByName('Doctrine\\Tests\\Models\\Versioning\\FullVersionableArticleWithChildren', $versionableArticle->id, '1.0');
$secondVersion = $this->dm->findVersionByName('Doctrine\\Tests\\Models\\Versioning\\FullVersionableArticleWithChildren', $versionableArticle->id, '1.1');
$this->assertEquals('This is the child', $firstVersion->childArticles->first()->getText(), 'The expected child article text is correct');
$this->assertEquals('modified text', $secondVersion->childArticles->first()->getText(), 'The expected, modified, child article text is correct');
}
示例14: testTranslationArrayProperties
/**
* Caution : Jackalope\Property guess the property type on the first element
* So if it's an boolean, all your array will be set to true
* The Array has to be an array of string
*/
public function testTranslationArrayProperties()
{
// First save some translations
$data = array();
$data['topic'] = 'Some interesting subject';
$data['text'] = 'Lorem ipsum...';
$data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html');
$node = $this->getTestNode();
$node->setProperty('author', 'John Doe');
$strategy = new AttributeTranslationStrategy($this->dm);
$strategy->saveTranslation($data, $node, $this->metadata, 'en');
// Save translation in another language
$data['topic'] = 'Un sujet intéressant';
$data['settings'] = array('is-active' => 'true', 'url' => 'super-article-en-francais.html');
$strategy->saveTranslation($data, $node, $this->metadata, 'fr');
$this->dm->flush();
$doc = new Article();
$doc->author = 'John Doe';
$doc->topic = $data['topic'];
$doc->setText($data['text']);
$strategy->loadTranslation($doc, $node, $this->metadata, 'en');
$this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
$this->assertEquals(array('is-active' => 'true', 'url' => 'great-article-in-english.html'), $doc->getSettings());
$strategy->loadTranslation($doc, $node, $this->metadata, 'fr');
$this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
$this->assertEquals(array('is-active' => 'true', 'url' => 'super-article-en-francais.html'), $doc->getSettings());
}
示例15: testCascadeManagedDocumentReferrerMtoMDuringFlush
/**
* Test Referrers ManyToMany cascade Flush
*/
public function testCascadeManagedDocumentReferrerMtoMDuringFlush()
{
$article1 = new \Doctrine\Tests\Models\CMS\CmsArticle();
$article1->text = "foo";
$article1->topic = "bar";
$article1->id = '/functional/article_m2m_referrer_1';
$this->dm->persist($article1);
$article2 = new \Doctrine\Tests\Models\CMS\CmsArticle();
$article2->text = "foo2";
$article2->topic = "bar2";
$article2->id = '/functional/article_m2m_referrer_2';
$this->dm->persist($article2);
$superman = new \Doctrine\Tests\Models\CMS\CmsArticlePerson();
$superman->name = "superman";
$this->dm->persist($superman);
$article1->addPerson($superman);
$this->dm->flush();
$this->dm->refresh($superman);
$this->assertEquals($superman, $article1->getPersons()->first());
// we want to attach article2 to superman
// in the form of edition, we will submit article1 and article2 at the same time
$superman->getArticlesReferrers()->add($article1);
$superman->getArticlesReferrers()->add($article2);
$this->dm->flush();
$this->dm->refresh($superman);
$this->assertEquals(1, $article1->getPersons()->count());
$this->assertEquals(2, $superman->getArticlesReferrers()->count());
$this->dm->clear();
}