Versioning support #96

Merged
merged 33 commits into from Feb 3, 2012

Projects

None yet

4 participants

@dbu
Doctrine member
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 …
…annotations"

This reverts commit f4ab6d53bacc074f9f98dd338a90234f8f007460.
8b9cc53
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…
…emantic
fd882ea
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
ede00dd
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 !!
05dede9
@dbu dbu check for version node rather than the frozen node, use fixed jackalo…
…pe that handles version deletion correctly
44f08f6
@dbu dbu annotation for VersionName and VersionCreated, clean up some locale a…
…ccess to use reflection
9c4aec0
@dbu dbu code and doc cleanups 571f834
@dbu dbu code cleanups and use the newly implemented PHPCR getAllLinearVersion…
…s instead of the hack
4999e2c
@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

Conflicts:
	README.md
	lib/Doctrine/ODM/PHPCR/UnitOfWork.php
	lib/vendor/jackalope
	tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php
8f150f9
@dbu dbu adjust LocaleChooserInterface to implementation f422a96
@dbu dbu removing @Version annotation as its no longer needed, tweaking handli…
…ng of @VersionName and @VersionCreated
0b86501
@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
lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -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
lsmith77 Feb 2, 2012

no need for those 2 last "else"

@dbu
dbu Feb 2, 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.

@lsmith77
lsmith77 Feb 2, 2012

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
README.md
@@ -445,6 +441,20 @@ class DocumentRepository extends BaseDocumentRepository implements RepositoryIdI
</td>
</tr>
<tr>
+ <td> VersionName: </td>
@lsmith77
lsmith77 Feb 2, 2012

some extra spaces

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

string with a boolean default ? this seems weird

@dbu
dbu Feb 2, 2012

removed the default

@stof stof commented on the diff Feb 2, 2012
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
@@ -372,6 +382,9 @@ public function setLifecycleCallbacks(array $callbacks)
*/
public function setVersioned($versionable)
{
+ if (!in_array($versionable, self::$validVersionableAnnotations)) {
@stof
stof Feb 2, 2012

does it work when the attribute is false ?

@stof
stof Feb 2, 2012

ah nvm, the method is not called in such case

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

what is it ?

@lsmith77
lsmith77 Feb 2, 2012

its time we require phpunit 3.6

@dbu
dbu Feb 2, 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

@stof stof and 1 other commented on an outdated diff Feb 2, 2012
...ts/ODM/PHPCR/Functional/Versioning/VersioningTest.php
+ $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
stof Feb 2, 2012

why not using the dedicated assertion assertCount ?

@dbu
dbu Feb 2, 2012

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

@dbu
Doctrine member
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