Example #1
0
 /**
  * @see DocumentManager::findVersionByName
  */
 public function findVersionByName($className, $id, $versionName)
 {
     $versionManager = $this->session->getWorkspace()->getVersionManager();
     try {
         $history = $versionManager->getVersionHistory($id);
     } catch (ItemNotFoundException $e) {
         // there is no document with $id
         return null;
     } catch (UnsupportedRepositoryOperationException $e) {
         throw new InvalidArgumentException("Document with id {$id} is not versionable", $e->getCode(), $e);
     }
     try {
         $version = $history->getVersion($versionName);
         $node = $version->getFrozenNode();
     } catch (RepositoryException $e) {
         throw new InvalidArgumentException("No version {$versionName} on document {$id}", $e->getCode(), $e);
     }
     $hints = array('versionName' => $versionName, 'ignoreHardReferenceNotFound' => true);
     $frozenDocument = $this->getOrCreateDocument($className, $node, $hints);
     $this->dm->detach($frozenDocument);
     $oid = spl_object_hash($frozenDocument);
     $this->documentHistory[$oid] = $history;
     $this->documentVersion[$oid] = $version;
     // Set the annotations
     $metadata = $this->dm->getClassMetadata(get_class($frozenDocument));
     if ($metadata->versionNameField) {
         $metadata->reflFields[$metadata->versionNameField]->setValue($frozenDocument, $versionName);
     }
     if ($metadata->versionCreatedField) {
         $metadata->reflFields[$metadata->versionCreatedField]->setValue($frozenDocument, $version->getCreated());
     }
     return $frozenDocument;
 }
Example #2
0
 public function testDetachWithChildren()
 {
     $parent = $this->dm->find(null, '/functional');
     $this->dm->detach($parent);
 }