Skip to content
This repository

Versioning support #96

Merged
merged 33 commits into from about 2 years ago

4 participants

David Buchmann Lukas Kahwe Smith Christophe Coevoet Adrian Schlegel
David Buchmann
Collaborator

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.

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

This reverts commit f4ab6d53bacc074f9f98dd338a90234f8f007460.
8b9cc53
Merge remote-tracking branch 'github/master' 69d5a6c
Merge remote-tracking branch 'upstream/master' 0cf26f1
Implemented the new Document(versioningType=...) annotation a257b1a
Updated jackalope to the latest version f808e1a
Refactored the versionable annotation to be compatible with the new s…
…emantic
fd882ea
Fixed case in versioning related methods 5cb4b88
Corrected case inconsistency in method calls ee662cb
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
ede00dd
Moved the existing VersioningTest to the proper directory 54f2728
Implemented checkpoint and getAllLinearVersions (IN PROGRESS) cd72e9a
Finished implementation of DocumentManager::getAllLinearVersions a78aea2
Adrian Schlegel work in progress for findVersionByName() f0503d2
Added basic tests for DocumentManager::findVersionByName e838c50
David Buchmann cleaning up findVersionByName and refactoring restore to restoreVersion 72fa043
David Buchmann little code cleanup on checkpoint 0499d41
Implemented DocumentManager::removeVersion - the test VersioningTest:…
…:testRemoveVersion is still failing !!
05dede9
David Buchmann check for version node rather than the frozen node, use fixed jackalo…
…pe that handles version deletion correctly
44f08f6
David Buchmann annotation for VersionName and VersionCreated, clean up some locale a…
…ccess to use reflection
9c4aec0
David Buchmann code and doc cleanups 571f834
David Buchmann code cleanups and use the newly implemented PHPCR getAllLinearVersion…
…s instead of the hack
4999e2c
David Buchmann adjust test to cleanup aaab6e0
David Buchmann removing obsolete getPRedecessors 3e042f4
David Buchmann and we do have doc for versioning too eb5cbbc
David Buchmann Merge remote branch 'upstream/master' into versioning, remove alias f…
…rom test documents

Conflicts:
	README.md
	lib/Doctrine/ODM/PHPCR/UnitOfWork.php
	lib/vendor/jackalope
	tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php
8f150f9
David Buchmann adjust LocaleChooserInterface to implementation f422a96
David Buchmann removing @Version annotation as its no longer needed, tweaking handli…
…ng of @VersionName and @VersionCreated
0b86501
David Buchmann move validation from driver into ClassMetadata d0c1471
David Buchmann add the version mappings in yml and xml drivers e62e666
lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -1647,4 +1738,17 @@ private static function objToStr($obj)
1647 1738
     {
1648 1739
         return method_exists($obj, '__toString') ? (string)$obj : get_class($obj) . '@' . spl_object_hash($obj);
1649 1740
     }
  1741
+
  1742
+    protected function setVersionableMixin(Mapping\ClassMetadata $metadata, NodeInterface $node)
  1743
+    {
  1744
+        if ($metadata->versionable === 'simple') {
  1745
+            $node->addMixin('mix:simpleVersionable');
  1746
+        } elseif ($metadata->versionable === 'full') {
  1747
+            $node->addMixin('mix:versionable');
  1748
+        } elseif ($metadata->versionable) {
3
Lukas Kahwe Smith Collaborator

no need for those 2 last "else"

David Buchmann Collaborator
dbu added a note February 02, 2012

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.

Lukas Kahwe Smith Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
README.md
@@ -445,6 +441,20 @@ class DocumentRepository extends BaseDocumentRepository implements RepositoryIdI
445 441
     </td>
446 442
 </tr>
447 443
 <tr>
  444
+    <td> VersionName:   </td>
1
Lukas Kahwe Smith Collaborator

some extra spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php
@@ -14,7 +14,7 @@
14 14
     public $nodeType = 'nt:unstructured';
15 15
     /** @var string */
16 16
     public $repositoryClass;
17  
-    /** @var boolean */
  17
+    /** @var string */
18 18
     public $versionable = false;
2
Christophe Coevoet
stof added a note February 02, 2012

string with a boolean default ? this seems weird

David Buchmann Collaborator
dbu added a note February 02, 2012

removed the default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Christophe Coevoet stof commented on the diff February 02, 2012
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
@@ -372,6 +382,9 @@ public function setLifecycleCallbacks(array $callbacks)
372 382
      */
373 383
     public function setVersioned($versionable)
374 384
     {
  385
+        if (!in_array($versionable, self::$validVersionableAnnotations)) {
2
Christophe Coevoet
stof added a note February 02, 2012

does it work when the attribute is false ?

Christophe Coevoet
stof added a note February 02, 2012

ah nvm, the method is not called in such case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildrenTest.php
@@ -141,6 +141,7 @@ public function testRemoveChildParent()
141 141
         $parent = $this->dm->find('Doctrine\Tests\ODM\PHPCR\Functional\ChildrenTestObj', '/functional/parent');
142 142
         $this->assertNull($parent);
143 143
     }
  144
+    public function assertCount($exp, $col) {$this->assertTrue($exp==count($col));}
3
Christophe Coevoet
stof added a note February 02, 2012

what is it ?

Lukas Kahwe Smith Collaborator

its time we require phpunit 3.6

David Buchmann Collaborator
dbu added a note February 02, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/Doctrine/Tests/ODM/PHPCR/Functional/Versioning/VersioningTest.php
((82 lines not shown))
  82
+        $user = $this->dm->find($this->type, '/functional/versionTestObj');
  83
+        $this->assertEquals('lsmith', $user->username);
  84
+    }
  85
+
  86
+    public function testGetAllLinearVersions()
  87
+    {
  88
+        $doc = $this->dm->find($this->type, '/functional/versionTestObj');
  89
+
  90
+        $this->dm->checkpoint($doc);
  91
+        $this->dm->checkpoint($doc);
  92
+        $this->dm->checkpoint($doc);
  93
+        $this->dm->checkpoint($doc);
  94
+
  95
+        $versions = $this->dm->getAllLinearVersions($doc);
  96
+
  97
+        $this->assertEquals(5, count($versions));
2
Christophe Coevoet
stof added a note February 02, 2012

why not using the dedicated assertion assertCount ?

David Buchmann Collaborator
dbu added a note February 02, 2012

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

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

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

Lukas Kahwe Smith lsmith77 merged commit a574615 into from February 03, 2012
Lukas Kahwe Smith lsmith77 closed this February 03, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 33 unique commits by 3 authors.

Nov 18, 2011
Added a `translated` attribute to all the translatable field annotations f4ab6d5
Revert "Added a `translated` attribute to all the translatable field …
…annotations"

This reverts commit f4ab6d53bacc074f9f98dd338a90234f8f007460.
8b9cc53
Dec 21, 2011
Merge remote-tracking branch 'github/master' 69d5a6c
Jan 10, 2012
Merge remote-tracking branch 'upstream/master' 0cf26f1
Implemented the new Document(versioningType=...) annotation a257b1a
Updated jackalope to the latest version f808e1a
Jan 12, 2012
Refactored the versionable annotation to be compatible with the new s…
…emantic
fd882ea
Fixed case in versioning related methods 5cb4b88
Corrected case inconsistency in method calls ee662cb
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
ede00dd
Moved the existing VersioningTest to the proper directory 54f2728
Implemented checkpoint and getAllLinearVersions (IN PROGRESS) cd72e9a
Jan 13, 2012
Finished implementation of DocumentManager::getAllLinearVersions a78aea2
Jan 26, 2012
Adrian Schlegel work in progress for findVersionByName() f0503d2
Added basic tests for DocumentManager::findVersionByName e838c50
David Buchmann cleaning up findVersionByName and refactoring restore to restoreVersion 72fa043
David Buchmann little code cleanup on checkpoint 0499d41
Jan 27, 2012
Implemented DocumentManager::removeVersion - the test VersioningTest:…
…:testRemoveVersion is still failing !!
05dede9
Jan 30, 2012
David Buchmann check for version node rather than the frozen node, use fixed jackalo…
…pe that handles version deletion correctly
44f08f6
David Buchmann annotation for VersionName and VersionCreated, clean up some locale a…
…ccess to use reflection
9c4aec0
Feb 01, 2012
David Buchmann code and doc cleanups 571f834
David Buchmann code cleanups and use the newly implemented PHPCR getAllLinearVersion…
…s instead of the hack
4999e2c
David Buchmann adjust test to cleanup aaab6e0
David Buchmann removing obsolete getPRedecessors 3e042f4
David Buchmann and we do have doc for versioning too eb5cbbc
Feb 02, 2012
David Buchmann Merge remote branch 'upstream/master' into versioning, remove alias f…
…rom test documents

Conflicts:
	README.md
	lib/Doctrine/ODM/PHPCR/UnitOfWork.php
	lib/vendor/jackalope
	tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php
8f150f9
David Buchmann adjust LocaleChooserInterface to implementation f422a96
David Buchmann removing @Version annotation as its no longer needed, tweaking handli…
…ng of @VersionName and @VersionCreated
0b86501
David Buchmann move validation from driver into ClassMetadata d0c1471
David Buchmann add the version mappings in yml and xml drivers e62e666
David Buchmann remove unnecessary check. class meta data ensures valid data 2777191
David Buchmann cleanups for the comments 04d66a5
David Buchmann reset documentHistory and documentVersion arrays in Unitofwork::clear 6936dbc
Something went wrong with that request. Please try again.