Versioning support #96

merged 33 commits into from Feb 3, 2012


None yet

4 participants

dbu commented Feb 2, 2012

adding versioning support as discussed on the mailing list. please see the added doc in the readme to see how this is to be used. the rudimentary versioning support that existed before is heavily refactored. if you used it, you will need to change:

  • Document attribute versionable is now required. it must be set to either "simple" or "full"
  • the @Version annotation is gone, it makes not much sense. for old version snapshot documents, you can use @ VersionName and @VersionCreated to track the metadata.
  • checkin and checkout are now lowercased to be consistent. note that we added checkpoint for convenience
  • restore has been renamed to restoreVersion and expects as parameter an old version rather than the document and version name.
  • instead of getPredecessors (which was misnamed anyways), use getAllLinearVersions to get metadata about versions, and use findVersionByName to get a detached document of the old version of your data.

apart from that, we added a removeVersion and update to latest jackalope with lots of fixes in version handling code.

Daniel Barsotti and others added some commits Nov 18, 2011
Daniel Barsotti Added a `translated` attribute to all the translatable field annotations f4ab6d5
Daniel Barsotti Revert "Added a `translated` attribute to all the translatable field …

This reverts commit f4ab6d5.
Daniel Barsotti Merge remote-tracking branch 'github/master' 69d5a6c
Daniel Barsotti Merge remote-tracking branch 'upstream/master' 0cf26f1
Daniel Barsotti Implemented the new Document(versioningType=...) annotation a257b1a
Daniel Barsotti Updated jackalope to the latest version f808e1a
Daniel Barsotti Refactored the versionable annotation to be compatible with the new s…
Daniel Barsotti Fixed case in versioning related methods 5cb4b88
Daniel Barsotti Corrected case inconsistency in method calls ee662cb
Daniel Barsotti Cleanup about versioning annotation
- The correct versionable mixin is set on document creation, checkin and checkout
- A document cannot have a @Version field if it is not versionable
- Corrected the exiting version related tests
Daniel Barsotti Moved the existing VersioningTest to the proper directory 54f2728
Daniel Barsotti Implemented checkpoint and getAllLinearVersions (IN PROGRESS) cd72e9a
Daniel Barsotti Finished implementation of DocumentManager::getAllLinearVersions a78aea2
@0x616469 0x616469 work in progress for findVersionByName() f0503d2
Daniel Barsotti Added basic tests for DocumentManager::findVersionByName e838c50
@dbu dbu cleaning up findVersionByName and refactoring restore to restoreVersion 72fa043
@dbu dbu little code cleanup on checkpoint 0499d41
Daniel Barsotti Implemented DocumentManager::removeVersion - the test VersioningTest:…
…:testRemoveVersion is still failing !!
@dbu dbu check for version node rather than the frozen node, use fixed jackalo…
…pe that handles version deletion correctly
@dbu dbu annotation for VersionName and VersionCreated, clean up some locale a…
…ccess to use reflection
@dbu dbu code and doc cleanups 571f834
@dbu dbu code cleanups and use the newly implemented PHPCR getAllLinearVersion…
…s instead of the hack
@dbu dbu adjust test to cleanup aaab6e0
@dbu dbu removing obsolete getPRedecessors 3e042f4
@dbu dbu and we do have doc for versioning too eb5cbbc
@dbu dbu Merge remote branch 'upstream/master' into versioning, remove alias f…
…rom test documents

@dbu dbu adjust LocaleChooserInterface to implementation f422a96
@dbu dbu removing @Version annotation as its no longer needed, tweaking handli…
…ng of @VersionName and @VersionCreated
@dbu dbu move validation from driver into ClassMetadata d0c1471
@dbu dbu add the version mappings in yml and xml drivers e62e666
@lsmith77 lsmith77 and 1 other commented on an outdated diff Feb 2, 2012
@@ -1647,4 +1738,17 @@ private static function objToStr($obj)
return method_exists($obj, '__toString') ? (string)$obj : get_class($obj) . '@' . spl_object_hash($obj);
+ protected function setVersionableMixin(Mapping\ClassMetadata $metadata, NodeInterface $node)
+ {
+ if ($metadata->versionable === 'simple') {
+ $node->addMixin('mix:simpleVersionable');
+ } elseif ($metadata->versionable === 'full') {
+ $node->addMixin('mix:versionable');
+ } elseif ($metadata->versionable) {
lsmith77 Feb 2, 2012 Member

no need for those 2 last "else"

dbu Feb 2, 2012 Member

i removed the check whether the document is versionable of an unknown type.
but i want to keep the last line, we call this method on checkin and checkout as well, whithout sanitizing. and there we want to notice if somebody tries to checkin a document that is not versionable.

lsmith77 Feb 2, 2012 Member

ah no .. my point wasn't that the exception throwing should be removed .. but actually my comment was bogus .. never mind :)

@lsmith77 lsmith77 commented on an outdated diff Feb 2, 2012
@@ -445,6 +441,20 @@ class DocumentRepository extends BaseDocumentRepository implements RepositoryIdI
+ <td> VersionName: </td>
lsmith77 Feb 2, 2012 Member

some extra spaces

@stof stof and 1 other commented on an outdated diff Feb 2, 2012
@@ -14,7 +14,7 @@
public $nodeType = 'nt:unstructured';
/** @var string */
public $repositoryClass;
- /** @var boolean */
+ /** @var string */
public $versionable = false;
stof Feb 2, 2012 Member

string with a boolean default ? this seems weird

dbu Feb 2, 2012 Member

removed the default

@stof stof commented on the diff Feb 2, 2012
@@ -372,6 +382,9 @@ public function setLifecycleCallbacks(array $callbacks)
public function setVersioned($versionable)
+ if (!in_array($versionable, self::$validVersionableAnnotations)) {
stof Feb 2, 2012 Member

does it work when the attribute is false ?

stof Feb 2, 2012 Member

ah nvm, the method is not called in such case

@stof stof and 2 others commented on an outdated diff Feb 2, 2012
@@ -141,6 +141,7 @@ public function testRemoveChildParent()
$parent = $this->dm->find('Doctrine\Tests\ODM\PHPCR\Functional\ChildrenTestObj', '/functional/parent');
+ public function assertCount($exp, $col) {$this->assertTrue($exp==count($col));}
stof Feb 2, 2012 Member

what is it ?

lsmith77 Feb 2, 2012 Member

its time we require phpunit 3.6

dbu Feb 2, 2012 Member

ups, damn. i just put that in so i could run the tests without updating my phpunit during a train ride...

i promise to update, remove this and will look for tests that could use assertCount

@stof stof and 1 other commented on an outdated diff Feb 2, 2012
+ $user = $this->dm->find($this->type, '/functional/versionTestObj');
+ $this->assertEquals('lsmith', $user->username);
+ }
+ public function testGetAllLinearVersions()
+ {
+ $doc = $this->dm->find($this->type, '/functional/versionTestObj');
+ $this->dm->checkpoint($doc);
+ $this->dm->checkpoint($doc);
+ $this->dm->checkpoint($doc);
+ $this->dm->checkpoint($doc);
+ $versions = $this->dm->getAllLinearVersions($doc);
+ $this->assertEquals(5, count($versions));
stof Feb 2, 2012 Member

why not using the dedicated assertion assertCount ?

dbu Feb 2, 2012 Member

done. there is lots of existing code with this issue too. will update when i find time.

dbu commented Feb 2, 2012

i will merge tomorrow unless somebody finds more issues. went through the api with lukas again and he is ok with it.

@lsmith77 lsmith77 merged commit a574615 into doctrine:master Feb 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment