Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Child version test #247

Open
wants to merge 3 commits into from

3 participants

@fazy

As discussed here:
https://groups.google.com/forum/?fromgroups=#!topic/symfony-cmf-devs/--3J2hbMsa8

I've created failing test cases to show how I expect versioning to work with a node type child definition "on version copy".

In effect I'm expecting versions to be 'in sync' with this method, so that when creating a version of the parent, a new version of the child is also created; When reverting the parent, any changes to the child are also reverted.

I could be wrong of course, and I'm not 100% sure my node type is correct...

Also, there's probably a better place to load the node type definition, but I don't think it's ready to go in the standard fixtures.

@dbu dbu commented on the diff
...ts/ODM/PHPCR/Functional/Versioning/VersioningTest.php
@@ -45,6 +46,19 @@ public function setUp()
$this->markTestSkipped('PHPCR repository does not support versioning');
}
+ $session = $this->dm->getPhpcrSession();
+
+ /** @var $ntm \Jackalope\NodeType\NodeTypeManager */
+ $ntm = $session->getWorkspace()->getNodeTypeManager();
+
+ if (! $ntm->hasNodeType('phpcr:versionCascade')) {
+ $cnd = <<<END_CND
+[phpcr:versionCascade] > nt:unstructured
+ + * multiple copy
+END_CND;
+ $ntm->registerNodeTypesCnd($cnd, false);
@dbu Collaborator
dbu added a note

thanks to JCR 2.1 this (cnd) is now part of the API. but atm the cnd parser is not finished so this will trip jackalope-doctrine-dbal

@dbu Collaborator
dbu added a note

ah but then jackalope-doctrine-dbal does not support versioning so we need not worry. cnd should come faster than versioning.

@fazy
fazy added a note

Another option might be to do it via the tests/travis_jackrabbit.sh script...

@dbu Collaborator
dbu added a note

i think its fine as is. jcr/phpcr 2.1 requires implementations to support it and jackalope-doctrine-dbal soon will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbu dbu commented on the diff
...ts/ODM/PHPCR/Functional/Versioning/VersioningTest.php
((4 lines not shown))
+
+ /**
+ * Check when a version is made of a document, a version is also made of the child
+ * (using a node type where version is set to "copy")
+ */
+ public function testVersionCopyWithChild()
+ {
+ $doc = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild');
+
+ $this->dm->checkpoint($doc);
+ $versions = $this->dm->getAllLinearVersions($doc);
+ $this->assertCount(2, $versions);
+
+ $child = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild/versionTestChild');
+ $versions = $this->dm->getAllLinearVersions($child);
+ $this->assertCount(2, $versions);
@dbu Collaborator
dbu added a note

so this is 1 instead of 2. is it a problem with the storage not cascading versioning, or just a caching issue in the odm? if you $dm->clear before getting the versions, does that fix anything? what does PHPCR tell at the point?

@fazy
fazy added a note

Yep, 1 instead of 2. $dm-clear() doesn't have any effect on this. $versions is an array of 1 version, 'jcr:rootVersion'.

Although it could be affected by this problem: https://groups.google.com/d/msg/symfony-cmf-devs/--3J2hbMsa8/bupTUgqeb-wJ - getAllLinearVersions() seemed to be 'stuck' on the first result it saw, even after $dm->clear()

@dbu Collaborator
dbu added a note

with the fix you did on jackalope, this should now work, right?

@fazy
fazy added a note

Unfortunately not; I've just tried messing around with a few permutations of this, but I suspect a separate issue that the versions don't cascade in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbu dbu commented on the diff
...ts/ODM/PHPCR/Functional/Versioning/VersioningTest.php
((28 lines not shown))
+ $user = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild');
+ $child = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild/versionTestChild');
+ $this->dm->checkpoint($user);
+ $user->username = 'nicam';
+ $child->username = 'nicam';
+ $this->dm->flush();
+
+ $versions = $this->dm->getAllLinearVersions($user);
+ each($versions);
+ list($dummy, $versionInfo) = each($versions);
+ $versionName = $versionInfo['name'];
+ $versionDocument = $this->dm->findVersionByName($this->typeVersion, '/functional/versionTestObjWithChild', $versionName);
+ $this->dm->restoreVersion($versionDocument);
+
+ $this->assertEquals('lsmith', $user->username);
+ $this->assertEquals('lsmith', $child->username);
@dbu Collaborator
dbu added a note

after the $dm->clear things are fine? is it "just" a caching issue? i wonder if we can even expect this to work or should require to call a refresh. the children version is on the database level, doctrine does not see that so it would need to refresh about everything after restoring...

@fazy
fazy added a note

Sorry that code probably isn't clear enough - the clear() and subsequent asserts are just mimicking the testRestoreVersion() method that was already there. The last asserts will also fail, even after the clear().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbu
Collaborator

thanks for the PR, best way to demo a bug! and ensure we won't have regression once we fixed it.

@fazy

No problem, I'll try and do more of these when needed.

@fazy

I've had a quick look around the code to try and understand what might be needed to get cascading children versions to work.

Is this something that's already been started, but not quite working, or is it completely missing? I'm wondering if it should be done in, for example, Jackalope\ObjectManager - but there are other layers above this of course, and then also the underlying Apache Jackrabbit data store itself.

@dbu
Collaborator

cascading versioning onto child nodes happens on the PHPCR storage layer. jackalope-doctrine-dbal does not implement versioning at all, so nothing to be found. for jackalope-jackrabbit, it just communicates the requests to jackrabbit, so it should work automatically on PHPCR level. what exactly is not working yet? does the restore not restore the child node? if that is the case, i recommend to see in phpcr-api-tests in the Versioning chapter if there is a bug on jackalope level. that will be much easier to debug then debugging jackalope from inside phpcr-odm

@fazy

It looks like the child is unaffected by both checkpoint() and restoreVersion(), for example in testRestoreVersionCopyWithChild().

Before the test, both the parent node and the child have names 'lsmith' (maybe I should change the child name to avoid confusion).

After checkpoint(), the number of linear versions is unchanged. After doing the checkpoint, I set the node and child names both to 'nicam'.

After restoreVersion(), the parent node name is restored to 'lsmith' but the child name remains set to 'nicam'.

Of course, I don't know if there's a bug, or just that I'm missing something in the tests. :) I'll take up your suggestion and try the same thing in phpcr-api-tests.

@lsmith77
Owner

So JCR automatically cascades versioning to children? i thought each node was versioned separately?

@fazy

@lsmith77 it looks like it should be possible, still trying to make it work though:

I am still not 100% sure how well it will work in practice. In my content hierarchy I have the concept of 'pages' and 'blocks' (both can be nested). If I make a new version of a page, I want the child blocks to be automatically versioned, but not child pages (that would be fun, at the top of a large content tree!)

So, the way I currently understand it I will probably need to make a custom node type for a page and another type for a block. The page type will need to only cascade versions down to child blocks, not child pages. In my examples for now though, I'm just trying to cascade everything.

@dbu
Collaborator

@lsmith77 you can configure the node type definition to cascade versioning to child nodes.

@fazy did you check if the checkpoint on the parent document creates a new version of the child at all? maybe the restore is still not cascaded? you could ask to users@jackrabbit.apache.org what the expected behaviour is when creating versions and when restoring versions.

@dbu dbu referenced this pull request
Open

Version a entire subtree #519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2013
  1. Now using the correct document class in the test

    Lars Janssen authored
Commits on Feb 28, 2013
This page is out of date. Refresh to see the latest.
View
87 tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTest.php
@@ -36,6 +36,7 @@ class VersioningTest extends \Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase
public function setUp()
{
$this->typeVersion = 'Doctrine\Tests\ODM\PHPCR\Functional\Versioning\VersionTestObj';
+ $this->typeVersionCopy = 'Doctrine\Tests\ODM\PHPCR\Functional\Versioning\VersionCopyTestObj';
$this->typeReference = 'Doctrine\Tests\ODM\PHPCR\Functional\Versioning\ReferenceTestObj';
$this->dm = $this->createDocumentManager();
@@ -45,6 +46,19 @@ public function setUp()
$this->markTestSkipped('PHPCR repository does not support versioning');
}
+ $session = $this->dm->getPhpcrSession();
+
+ /** @var $ntm \Jackalope\NodeType\NodeTypeManager */
+ $ntm = $session->getWorkspace()->getNodeTypeManager();
+
+ if (! $ntm->hasNodeType('phpcr:versionCascade')) {
+ $cnd = <<<END_CND
+[phpcr:versionCascade] > nt:unstructured
+ + * multiple copy
+END_CND;
+ $ntm->registerNodeTypesCnd($cnd, false);
@dbu Collaborator
dbu added a note

thanks to JCR 2.1 this (cnd) is now part of the API. but atm the cnd parser is not finished so this will trip jackalope-doctrine-dbal

@dbu Collaborator
dbu added a note

ah but then jackalope-doctrine-dbal does not support versioning so we need not worry. cnd should come faster than versioning.

@fazy
fazy added a note

Another option might be to do it via the tests/travis_jackrabbit.sh script...

@dbu Collaborator
dbu added a note

i think its fine as is. jcr/phpcr 2.1 requires implementations to support it and jackalope-doctrine-dbal soon will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+
$this->node = $this->resetFunctionalNode($this->dm);
$versionNode = $this->node->addNode('versionTestObj');
@@ -58,6 +72,18 @@ public function setUp()
$referenceNode->setProperty('phpcr:class', $this->typeReference);
$referenceNode->addMixin("mix:referenceable");
+ $versionNodeWithChild = $this->node->addNode('versionTestObjWithChild');
+ $versionNodeWithChild->setProperty('username', 'lsmith');
+ $versionNodeWithChild->setProperty('numbers', array(3, 1, 2));
+ $versionNodeWithChild->setProperty('phpcr:class', $this->typeVersionCopy);
+ $versionNodeWithChild->addMixin("mix:versionable");
+
+ $childNode = $versionNodeWithChild->addNode('versionTestChild');
+ $childNode->setProperty('username', 'lsmith');
+ $childNode->setProperty('numbers', array(3, 1, 2));
+ $childNode->setProperty('phpcr:class', $this->typeVersion);
+ $childNode->addMixin("mix:versionable");
+
$this->dm->getPhpcrSession()->save();
$versionNodeWithReference = $this->node->addNode('versionTestObjWithReference');
@@ -308,6 +334,53 @@ public function testDeletedVersionDoesNotExistAnymore($lastVersionName)
{
$this->dm->findVersionByName($this->typeVersion, '/functional/versionTestObj', $lastVersionName);
}
+
+ /**
+ * Check when a version is made of a document, a version is also made of the child
+ * (using a node type where version is set to "copy")
+ */
+ public function testVersionCopyWithChild()
+ {
+ $doc = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild');
+
+ $this->dm->checkpoint($doc);
+ $versions = $this->dm->getAllLinearVersions($doc);
+ $this->assertCount(2, $versions);
+
+ $child = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild/versionTestChild');
+ $versions = $this->dm->getAllLinearVersions($child);
+ $this->assertCount(2, $versions);
@dbu Collaborator
dbu added a note

so this is 1 instead of 2. is it a problem with the storage not cascading versioning, or just a caching issue in the odm? if you $dm->clear before getting the versions, does that fix anything? what does PHPCR tell at the point?

@fazy
fazy added a note

Yep, 1 instead of 2. $dm-clear() doesn't have any effect on this. $versions is an array of 1 version, 'jcr:rootVersion'.

Although it could be affected by this problem: https://groups.google.com/d/msg/symfony-cmf-devs/--3J2hbMsa8/bupTUgqeb-wJ - getAllLinearVersions() seemed to be 'stuck' on the first result it saw, even after $dm->clear()

@dbu Collaborator
dbu added a note

with the fix you did on jackalope, this should now work, right?

@fazy
fazy added a note

Unfortunately not; I've just tried messing around with a few permutations of this, but I suspect a separate issue that the versions don't cascade in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+
+ /**
+ * Check when restoring a document, changes are reverted in both the document and the child
+ * (using a node type where version is set to "copy")
+ */
+ public function testRestoreVersionCopyWithChild()
+ {
+ $user = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild');
+ $child = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild/versionTestChild');
+ $this->dm->checkpoint($user);
+ $user->username = 'nicam';
+ $child->username = 'nicam';
+ $this->dm->flush();
+
+ $versions = $this->dm->getAllLinearVersions($user);
+ each($versions);
+ list($dummy, $versionInfo) = each($versions);
+ $versionName = $versionInfo['name'];
+ $versionDocument = $this->dm->findVersionByName($this->typeVersion, '/functional/versionTestObjWithChild', $versionName);
+ $this->dm->restoreVersion($versionDocument);
+
+ $this->assertEquals('lsmith', $user->username);
+ $this->assertEquals('lsmith', $child->username);
@dbu Collaborator
dbu added a note

after the $dm->clear things are fine? is it "just" a caching issue? i wonder if we can even expect this to work or should require to call a refresh. the children version is on the database level, doctrine does not see that so it would need to refresh about everything after restoring...

@fazy
fazy added a note

Sorry that code probably isn't clear enough - the clear() and subsequent asserts are just mimicking the testRestoreVersion() method that was already there. The last asserts will also fail, even after the clear().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ $this->dm->clear();
+ $user = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild');
+ $child = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithChild/versionTestChild');
+ $this->assertEquals('lsmith', $user->username);
+ $this->assertEquals('lsmith', $child->username);
+ }
}
/**
@@ -336,6 +409,20 @@ class VersionTestObj
}
/**
+ * @PHPCRODM\Document(versionable="full", nodeType="phpcr:versionCascade")
+ */
+class VersionCopyTestObj
+{
+ /** @PHPCRODM\Id */
+ public $id;
+ /** @PHPCRODM\Node */
+ public $node;
+
+ /** @PHPCRODM\String(name="username") */
+ public $username;
+}
+
+/**
* @PHPCRODM\Document(referenceable=true)
*/
class ReferenceTestObj
Something went wrong with that request. Please try again.