Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add version restore functionality to transport layer #283

Open
wants to merge 12 commits into
base: 2.x
Choose a base branch
from
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"php": ">=5.3.3",
"doctrine/dbal": ">=2.4.5,<3.0.x-dev",
"phpcr/phpcr": "~2.1.2",
"phpcr/phpcr-utils": "dev-versioning as 1.2.9",
"jackalope/jackalope": "dev-versioning as 1.3.0"
"phpcr/phpcr-utils": "^1.2.8",
"jackalope/jackalope": "dev-version-restore as 1.3.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert when merged

},
"provide": {
"jackalope/jackalope-transport": "1.1.0"
Expand All @@ -42,5 +42,15 @@
"branch-alias": {
"dev-master": "1.3-dev"
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/danrot/jackalope.git"
},
{
"type": "vcs",
"url": "https://github.com/danrot/phpcr-api-tests.git"
}
]
}
45 changes: 43 additions & 2 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jackalope\Transport\DoctrineDBAL;

use Jackalope\NamespaceRegistry;
use Jackalope\Version\GenericVersioningInterface;
use Jackalope\Version\VersionHandler;
use PHPCR\LoginException;
Expand Down Expand Up @@ -30,6 +31,8 @@
use PHPCR\Util\ValueConverter;
use PHPCR\Util\UUIDHelper;
use PHPCR\Util\PathHelper;
use PHPCR\Version\LabelExistsVersionException;
use PHPCR\Version\VersionException;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
Expand All @@ -51,7 +54,6 @@
use Jackalope\FactoryInterface;
use Jackalope\NotImplementedException;
use Jackalope\NodeType\NodeProcessor;
use PHPCR\Version\VersionException;

/**
* Class to handle the communication between Jackalope and RDBMS via Doctrine DBAL.
Expand Down Expand Up @@ -148,6 +150,7 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
*/
private $coreNamespaces = array(
NamespaceRegistryInterface::PREFIX_EMPTY => NamespaceRegistryInterface::NAMESPACE_EMPTY,
NamespaceRegistry::PREFIX_REP => NamespaceRegistry::NAMESPACE_REP,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu Is this solution ok? Have now moved the constant to jackalope/jackalope instead of phpcr/phpcr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i think that is the correct thing to do

NamespaceRegistryInterface::PREFIX_JCR => NamespaceRegistryInterface::NAMESPACE_JCR,
NamespaceRegistryInterface::PREFIX_NT => NamespaceRegistryInterface::NAMESPACE_NT,
NamespaceRegistryInterface::PREFIX_MIX => NamespaceRegistryInterface::NAMESPACE_MIX,
Expand Down Expand Up @@ -1915,6 +1918,16 @@ private function getNodeProcessor()
return $this->nodeProcessor;
}

/**
* Returns a handler for the versioning mechanism
*
* @return VersionHandler
*/
private function getVersionHandler()
{
return $this->versionHandler;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -2653,7 +2666,7 @@ public function checkoutItem($path)
*/
public function restoreItem($removeExisting, $versionPath, $path)
{
throw new NotImplementedException();
return $this->versionHandler->restoreItem($removeExisting, $versionPath, $path);
}

/**
Expand All @@ -2676,4 +2689,32 @@ public function setVersionHandler(VersionHandler $versionHandler)

$this->versionHandler = $versionHandler;
}

/**
* Adds the label <code>label</code> to the specified version.
*
* @param string $versionName the absolute path to the version
* @param string $label
* @param boolean $moveLabel
*
* @throws LabelExistsVersionException if, the label is set to another version and
* the parameter moveLabel is set to false.
*
* @throws RepositoryException in case of an other error.
*/
public function addVersionLabel($versionName, $label, $moveLabel)
{
// TODO: Implement addVersionLabel() method.
}

/**
* Removes a label from the specified version.
*
* @param string $versionPath the absolute path to the version.
* @param string $label the label, that has to be removed.
*/
public function removeVersionLabel($versionPath, $label)
{
// TODO: Implement removeVersionLabel() method.
}
}
3 changes: 1 addition & 2 deletions tests/ImplementationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function __construct(Connection $connection, $fixturePath)
'Query\\XPath', // Query language 'xpath' not implemented.
'Query\\Sql1', // Query language 'sql' is legacy and only makes sense with jackrabbit
'Writing\\CloneMethodsTest', // TODO: Support for workspace->clone, node->update, node->getCorrespondingNodePath
'Versioning\\SimpleVersionTest'
);

$this->unsupportedTests = array(
Expand Down Expand Up @@ -87,8 +88,6 @@ protected function __construct(Connection $connection, $fixturePath)
'Versioning\\VersionHistoryTest::testDeleteVersion',
'Versioning\\VersionHistoryTest::testDeleteLatestVersion',
'Versioning\\VersionHistoryTest::testDeleteUnexistingVersion',
'Versioning\\VersionManagerTest::testRestoreByPathAndName',
'Versioning\\VersionManagerTest::testRestoreByVersionObject',
'Versioning\\VersionManagerTest::testRestoreRootVersion',
'Versioning\\VersionManagerTest::testWriteNotCheckedOutVersion',
);
Expand Down
87 changes: 69 additions & 18 deletions tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ public function addNodes($workspaceName, \DOMNodeList $nodes)
$this->rootNodes[$workspaceName] = true;
}

$srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml');
foreach ($srcDom->load()->getNodes() as $node) {
$this->addNode($workspaceName, $node);
}

foreach ($nodes as $node) {
$this->addNode($workspaceName, $node);
}
Expand All @@ -131,6 +126,62 @@ public function addRootNode($workspaceName = 'default')
$uuid = UUIDHelper::generateUUID();
$this->ids[$uuid] = self::$idCounter++;

$this->addRow('phpcr_nodes', array(
'id' => self::$idCounter++,
'path' => '/jcr:system',
'parent' => '/',
'local_name' => 'jcr:system',
'namespace' => 'http://www.jcp.org/jcr/1.0',
'workspace_name' => $workspaceName,
'identifier' => UUIDHelper::generateUUID(),
'type' => 'rep:system',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:crx="http://www.day.com/crx/1.0"'
. ' xmlns:lx="http://flux-cms.org/2.0"'
. ' xmlns:test="http://liip.to/jackalope"'
. ' xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. ' xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. ' xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. ' xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. ' xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. ' xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. ' xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. ' xmlns:new_prefix="http://a_new_namespace"'
. ' xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. ' xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. ' xmlns:rep="internal" />',
'depth' => 1,
'sort_order' => 0,
));

$this->addRow('phpcr_nodes', array(
'id' => self::$idCounter++,
'path' => '/jcr:system/jcr:versionStorage',
'parent' => '/jcr:system',
'local_name' => 'jcr:versionStorage',
'namespace' => 'http://www.jcp.org/jcr/1.0',
'workspace_name' => $workspaceName,
'identifier' => UUIDHelper::generateUUID(),
'type' => 'rep:versionStorage',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:crx="http://www.day.com/crx/1.0"'
. ' xmlns:lx="http://flux-cms.org/2.0"'
. ' xmlns:test="http://liip.to/jackalope"'
. ' xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. ' xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. ' xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. ' xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. ' xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. ' xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. ' xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. ' xmlns:new_prefix="http://a_new_namespace"'
. ' xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. ' xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. ' xmlns:rep="internal" />',
'depth' => 2,
'sort_order' => 0,
));

return $this->addRow('phpcr_nodes', array(
'id' => $this->ids[$uuid],
'path' => '/',
Expand All @@ -142,19 +193,19 @@ public function addRootNode($workspaceName = 'default')
'type' => 'nt:unstructured',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:crx="http://www.day.com/crx/1.0"'
. 'xmlns:lx="http://flux-cms.org/2.0"'
. 'xmlns:test="http://liip.to/jackalope"'
. 'xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. 'xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. 'xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. 'xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. 'xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. 'xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. 'xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. 'xmlns:new_prefix="http://a_new_namespace"'
. 'xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. 'xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. 'xmlns:rep="internal" />',
. ' xmlns:lx="http://flux-cms.org/2.0"'
. ' xmlns:test="http://liip.to/jackalope"'
. ' xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. ' xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. ' xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. ' xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. ' xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. ' xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. ' xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. ' xmlns:new_prefix="http://a_new_namespace"'
. ' xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. ' xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. ' xmlns:rep="internal" />',
'depth' => 0,
'sort_order' => 0,
));
Expand Down