From 4f7fd6331ddfa531f16e339bd7bbafef564eb443 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Fri, 6 Mar 2015 19:17:37 +0100 Subject: [PATCH 01/16] enabled versioning tests --- phpunit.xml.dist | 3 --- tests/ImplementationLoader.php | 1 - 2 files changed, 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d47021c7..2a8057e1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -47,9 +47,6 @@ - vendor/phpcr/phpcr/src/PHPCR/Version - vendor/jackalope/jackalope/src/Jackalope/Version - vendor/phpcr/phpcr/src/PHPCR/Lock vendor/jackalope/jackalope/src/Jackalope/Lock diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 38c81f03..3b8126b9 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -46,7 +46,6 @@ protected function __construct(Connection $connection, $fixturePath) 'SameNameSiblings', //TODO: Not implemented, no test currently written for it 'PermissionsAndCapabilities', //TODO: Transport does not support permissions 'Observation', //TODO: Transport does not support observation - 'Versioning', //TODO: Transport does not support versioning 'Locking', //TODO: Transport does not support locking ); From badb447a18fc10b149aea2558c8b933288f1706d Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 2 Apr 2015 19:32:42 +0200 Subject: [PATCH 02/16] implemented VersioningInterface --- .../Transport/DoctrineDBAL/Client.php | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index bed791ce..c1033c6a 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -2,6 +2,7 @@ namespace Jackalope\Transport\DoctrineDBAL; +use Jackalope\Transport\VersioningInterface; use PHPCR\LoginException; use PHPCR\NodeType\NodeDefinitionInterface; use PHPCR\NodeType\NodeTypeExistsException; @@ -23,6 +24,7 @@ use PHPCR\PathNotFoundException; use PHPCR\Query\InvalidQueryException; use PHPCR\NodeType\ConstraintViolationException; +use PHPCR\UnsupportedRepositoryOperationException; use PHPCR\Util\QOM\Sql2ToQomQueryConverter; use PHPCR\Util\ValueConverter; use PHPCR\Util\UUIDHelper; @@ -48,6 +50,7 @@ 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. @@ -58,7 +61,7 @@ * @author Benjamin Eberlei * @author Lukas Kahwe Smith */ -class Client extends BaseTransport implements QueryTransport, WritingInterface, WorkspaceManagementInterface, NodeTypeManagementInterface, TransactionInterface +class Client extends BaseTransport implements QueryTransport, WritingInterface, WorkspaceManagementInterface, NodeTypeManagementInterface, TransactionInterface, VersioningInterface { /** * SQlite can only handle a maximum of 999 parameters inside an IN statement @@ -2617,4 +2620,62 @@ private function initConnection() $this->connectionInitialized = true; } + + /** + * Check-in item at path. + * + * @see VersionManager::checkin + * + * @param string $path absolute path to the node + * + * @return string path to the new version + * + * @throws UnsupportedRepositoryOperationException + * @throws RepositoryException + */ + public function checkinItem($path) + { + // TODO: Implement checkinItem() method. + } + + /** + * Check-out item at path. + * + * @see VersionManager::checkout + * + * @param string $path absolute path to the node + * + * @throws UnsupportedRepositoryOperationException + * @throws RepositoryException + */ + public function checkoutItem($path) + { + // TODO: Implement checkoutItem() method. + } + + /** + * Restore the item at versionPath to the location path + * + * TODO: This is incomplete. Needs batch processing to avoid chicken-and-egg problems + * + * @see VersionManager::restoreItem + */ + public function restoreItem($removeExisting, $versionPath, $path) + { + // TODO: Implement restoreItem() method. + } + + /** + * Remove a version given the path to the version node and the name of the version. + * + * @param string $versionPath absolute path to the version node + * @param string $versionName The name of the version + * + * @throws ReferentialIntegrityException + * @throws VersionException + */ + public function removeVersion($versionPath, $versionName) + { + // TODO: Implement removeVersion() method. + } } From 7816e61bfbce7a1c9716b06136c30bc34f337019 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Fri, 1 May 2015 14:25:40 +0200 Subject: [PATCH 03/16] fixed tests for versioning --- composer.json | 10 ++++-- .../Transport/DoctrineDBAL/Client.php | 31 +++++++++++++++++-- .../Test/Fixture/DBUnitFixtureXML.php | 13 ++++++-- tests/fixtures/system.xml | 11 +++++++ tests/generate_fixtures.php | 4 +++ 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/system.xml diff --git a/composer.json b/composer.json index 9297c9f9..5a07789d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "doctrine/dbal": ">=2.4.5,<3.0.x-dev", "phpcr/phpcr": "~2.1.2", "phpcr/phpcr-utils": "^1.2.8", - "jackalope/jackalope": "~1.2.6" + "jackalope/jackalope": "dev-versioning as 1.3.0" }, "provide": { "jackalope/jackalope-transport": "1.1.0" @@ -42,5 +42,11 @@ "branch-alias": { "dev-master": "1.3-dev" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/danrot/jackalope.git" + } + ] } diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index c1033c6a..65105cf4 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -2,7 +2,8 @@ namespace Jackalope\Transport\DoctrineDBAL; -use Jackalope\Transport\VersioningInterface; +use Jackalope\Version\GenericVersioningInterface; +use Jackalope\Version\VersionHandler; use PHPCR\LoginException; use PHPCR\NodeType\NodeDefinitionInterface; use PHPCR\NodeType\NodeTypeExistsException; @@ -61,7 +62,7 @@ * @author Benjamin Eberlei * @author Lukas Kahwe Smith */ -class Client extends BaseTransport implements QueryTransport, WritingInterface, WorkspaceManagementInterface, NodeTypeManagementInterface, TransactionInterface, VersioningInterface +class Client extends BaseTransport implements QueryTransport, WritingInterface, WorkspaceManagementInterface, NodeTypeManagementInterface, TransactionInterface, GenericVersioningInterface { /** * SQlite can only handle a maximum of 999 parameters inside an IN statement @@ -192,6 +193,11 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface, */ private $nodeProcessor; + /** + * @var VersionHandler + */ + private $versionHandler; + /** * @param FactoryInterface $factory * @param Connection $conn @@ -1908,6 +1914,16 @@ private function getNodeProcessor() return $this->nodeProcessor; } + /** + * Returns a handler for the versioning mechanism + * + * @return VersionHandler + */ + private function getVersionHandler() + { + return $this->versionHandler; + } + /** * {@inheritDoc} */ @@ -2635,7 +2651,7 @@ private function initConnection() */ public function checkinItem($path) { - // TODO: Implement checkinItem() method. + return $this->getVersionHandler()->checkinItem($path); } /** @@ -2678,4 +2694,13 @@ public function removeVersion($versionPath, $versionName) { // TODO: Implement removeVersion() method. } + + /** + * Sets the generic version handler delivered by jackalope + * @param VersionHandler $versionHandler + */ + public function setVersionHandler(VersionHandler $versionHandler) + { + $this->versionHandler = $versionHandler; + } } diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index db93f757..e3cf6e7b 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -40,6 +40,12 @@ class DBUnitFixtureXML extends XMLDocument */ protected $expectedNodes; + /** + * Track if root nodes exists for workspace names + * @var array + */ + private $rootNodes; + /** * @param string $file - file path * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php @@ -101,8 +107,11 @@ public function addNamespaces(array $namespaces) public function addNodes($workspaceName, \DOMNodeList $nodes) { $node = $nodes->item(0); - if ('jcr:root' !== $node->getAttributeNS($this->namespaces['sv'], 'name')) { - $this->addRootNode('tests'); + if (!isset($this->rootNodes[$workspaceName])) { + if ('jcr:root' !== $node->getAttributeNS($this->namespaces['sv'], 'name')) { + $this->addRootNode('tests'); + } + $this->rootNodes[$workspaceName] = true; } foreach ($nodes as $node) { $this->addNode($workspaceName, $node); diff --git a/tests/fixtures/system.xml b/tests/fixtures/system.xml new file mode 100644 index 00000000..f37039c5 --- /dev/null +++ b/tests/fixtures/system.xml @@ -0,0 +1,11 @@ + + + + nt:unstructured + + + + nt:unstructured + + + diff --git a/tests/generate_fixtures.php b/tests/generate_fixtures.php index eead7523..ebab0f41 100755 --- a/tests/generate_fixtures.php +++ b/tests/generate_fixtures.php @@ -7,6 +7,9 @@ */ function generate_fixtures($srcDir, $destDir) { + $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml'); + $systemNodes = $srcDom->load()->getNodes(); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir)) as $srcFile) { if (method_exists($srcFile, 'getExtension')) { $extension = $srcFile->getExtension(); @@ -30,6 +33,7 @@ function generate_fixtures($srcDir, $destDir) $destDom->addWorkspace('tests'); $destDom->addNamespaces($srcDom->getNamespaces()); $destDom->addNodes('tests', $nodes); + $destDom->addNodes('tests', $systemNodes); // delay this to the end to not add entries for weak refs to not existing nodes $destDom->addReferences(); $destDom->save(); From c9585a2b13dd73136c4068b3f57736b68f8651a4 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Fri, 1 May 2015 17:08:32 +0200 Subject: [PATCH 04/16] included VersionHandler in NodeProcessor --- src/Jackalope/Transport/DoctrineDBAL/Client.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index 65105cf4..1a7fc2db 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -1908,7 +1908,8 @@ private function getNodeProcessor() $this->nodeProcessor = new NodeProcessor( $this->credentials->getUserID(), $this->getNamespacesObject(), - $this->getAutoLastModified() + $this->getAutoLastModified(), + $this->versionHandler ); return $this->nodeProcessor; @@ -2607,8 +2608,12 @@ public function rollbackSave() public function updateProperties(Node $node) { $this->assertLoggedIn(); - // we can ignore the operations returned, there will be no additions because of property updates - $this->getNodeProcessor()->process($node); + + $additionalAddOperations = $this->getNodeProcessor()->process($node); + + if (!empty($additionalAddOperations)) { + $this->storeNodes($additionalAddOperations); + } $this->syncNode($node->getIdentifier(), $node->getPath(), $node->getPrimaryNodeType(), false, $node->getProperties()); From 333d28f0e478be0d9f8e18ee05128092ac45501e Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 5 May 2015 10:15:32 +0200 Subject: [PATCH 05/16] added call to checkout method --- src/Jackalope/Transport/DoctrineDBAL/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index 1a7fc2db..1668e81c 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -2671,7 +2671,7 @@ public function checkinItem($path) */ public function checkoutItem($path) { - // TODO: Implement checkoutItem() method. + return $this->getVersionHandler()->checkoutItem($path); } /** From 22d2ee655fee0f7f9b3f944327fda69800851a04 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 5 May 2015 10:15:49 +0200 Subject: [PATCH 06/16] adjusted tests to skip not yet supported ones --- tests/ImplementationLoader.php | 7 +- .../Test/Fixture/DBUnitFixtureXML.php | 88 ++++++++++++++++++- tests/generate_fixtures.php | 4 - 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 3b8126b9..892abad9 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -53,6 +53,11 @@ 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 + + // TODO fully implement versioning + 'Versioning\\VersionHistoryTest', + 'Versioning\\VersionManagerTest', + 'Versioning\\VersionTest', ); $this->unsupportedTests = array( @@ -81,7 +86,7 @@ protected function __construct(Connection $connection, $fixturePath) // TODO: implement creating workspace with source 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithSource', - 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithInvalidSource' + 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithInvalidSource', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index e3cf6e7b..ba8c09fb 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -113,6 +113,12 @@ 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); } @@ -197,6 +203,12 @@ public function addNode($workspaceName, \DOMElement $node) $namespace = ''; } + if (isset($properties['jcr:mixinTypes']) + && in_array('mix:versionable', $properties['jcr:mixinTypes']['value']) + ) { + $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id); + } + $this->addRow('phpcr_nodes', array( 'id' => $id, 'path' => $childPath, @@ -270,7 +282,7 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = true; } - return array($name, array('type' => $type, 'value' => $values, 'multiValued' => $isMultiValue)); + return array($name, array('type' => $type, 'value' => $values, 'multiValued' => $isMultiValue)); } public function createPropertyNode($workspaceName, $propertyName, $propertyData, $id, \DOMDocument $dom) @@ -422,4 +434,78 @@ protected function ensureTableExists($tableName, $columns) return $this; } + + private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $workspaceName, $id) + { + $node->appendChild( + $this->createPropertyNode( + $workspaceName, + 'jcr:isCheckedOut', + array('type' => 'boolean', 'value' => array('true'), 'multiValued' => false), + $id, + $dom + ) + ); + + $versionNodeUuid = UUIDHelper::generateUUID(); + $versionParentPath = '/jcr:system/jcr:versionStorage'; + $versionPath = $versionParentPath . '/' . $versionNodeUuid; + $this->addRow( + 'phpcr_nodes', + array( + 'id' => self::$idCounter++, + 'path' => $versionPath, + 'parent' => $versionParentPath, + 'local_name' => $versionNodeUuid, + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $versionNodeUuid, + 'type' => 'nt:unstructured', + 'props' => '' + . '', + 'depth' => PathHelper::getPathDepth($versionPath), + 'sort_order' => $id - 2, + ) + ); + + $rootVersionPath = $versionPath . '/jcr:rootVersion'; + $rootVersionUuid = UUIDHelper::generateUUID(); + $this->addRow( + 'phpcr_nodes', + array( + 'id' => self::$idCounter++, + 'path' => $rootVersionPath, + 'parent' => $versionPath, + 'local_name' => 'jcr:rootVersion', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $rootVersionUuid, + 'type' => 'nt:version', + 'props' => '' + . '', + 'depth' => PathHelper::getPathDepth($rootVersionPath), + 'sort_order' => $id - 2, + ) + ); + + $node->appendChild( + $this->createPropertyNode( + $workspaceName, + 'jcr:versionHistory', + array('type' => 'reference', 'value' => array($versionNodeUuid), 'multiValued' => false), + $id, + $dom + ) + ); + + $node->appendChild( + $this->createPropertyNode( + $workspaceName, + 'jcr:predecessors', + array('type' => 'reference', 'value' => array(), 'multiValued' => true), + $id, + $dom + ) + ); + } } diff --git a/tests/generate_fixtures.php b/tests/generate_fixtures.php index ebab0f41..eead7523 100755 --- a/tests/generate_fixtures.php +++ b/tests/generate_fixtures.php @@ -7,9 +7,6 @@ */ function generate_fixtures($srcDir, $destDir) { - $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml'); - $systemNodes = $srcDom->load()->getNodes(); - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir)) as $srcFile) { if (method_exists($srcFile, 'getExtension')) { $extension = $srcFile->getExtension(); @@ -33,7 +30,6 @@ function generate_fixtures($srcDir, $destDir) $destDom->addWorkspace('tests'); $destDom->addNamespaces($srcDom->getNamespaces()); $destDom->addNodes('tests', $nodes); - $destDom->addNodes('tests', $systemNodes); // delay this to the end to not add entries for weak refs to not existing nodes $destDom->addReferences(); $destDom->save(); From 95ba2f34331895949ff36dda0833d9d41a491e76 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 5 May 2015 13:24:09 +0200 Subject: [PATCH 07/16] updated phpcr-utils --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5a07789d..8ffc5e99 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": ">=5.3.3", "doctrine/dbal": ">=2.4.5,<3.0.x-dev", "phpcr/phpcr": "~2.1.2", - "phpcr/phpcr-utils": "^1.2.8", + "phpcr/phpcr-utils": "dev-versioning as 1.2.9", "jackalope/jackalope": "dev-versioning as 1.3.0" }, "provide": { @@ -47,6 +47,10 @@ { "type": "vcs", "url": "https://github.com/danrot/jackalope.git" + }, + { + "type": "vcs", + "url": "https://github.com/danrot/phpcr-utils.git" } ] } From aa81162da16d87179a4258824dfefdb29987782a Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 19 May 2015 09:13:41 +0200 Subject: [PATCH 08/16] updated documentation --- .../Transport/DoctrineDBAL/Client.php | 38 +++---------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index 1668e81c..cf2fe8bb 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -2643,16 +2643,7 @@ private function initConnection() } /** - * Check-in item at path. - * - * @see VersionManager::checkin - * - * @param string $path absolute path to the node - * - * @return string path to the new version - * - * @throws UnsupportedRepositoryOperationException - * @throws RepositoryException + * {@inheritDoc} */ public function checkinItem($path) { @@ -2660,14 +2651,7 @@ public function checkinItem($path) } /** - * Check-out item at path. - * - * @see VersionManager::checkout - * - * @param string $path absolute path to the node - * - * @throws UnsupportedRepositoryOperationException - * @throws RepositoryException + * {@inheritDoc} */ public function checkoutItem($path) { @@ -2675,29 +2659,19 @@ public function checkoutItem($path) } /** - * Restore the item at versionPath to the location path - * - * TODO: This is incomplete. Needs batch processing to avoid chicken-and-egg problems - * - * @see VersionManager::restoreItem + * {@inheritDoc} */ public function restoreItem($removeExisting, $versionPath, $path) { - // TODO: Implement restoreItem() method. + throw new NotImplementedException(); } /** - * Remove a version given the path to the version node and the name of the version. - * - * @param string $versionPath absolute path to the version node - * @param string $versionName The name of the version - * - * @throws ReferentialIntegrityException - * @throws VersionException + * {@inheritDoc} */ public function removeVersion($versionPath, $versionName) { - // TODO: Implement removeVersion() method. + throw new NotImplementedException(); } /** From 05176669629bcfa305bdc5a780d3561ceed03b5d Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 2 Jun 2015 19:40:24 +0200 Subject: [PATCH 09/16] removed getter for VersionHandler --- .../Transport/DoctrineDBAL/Client.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index cf2fe8bb..a7577fa9 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -1915,16 +1915,6 @@ private function getNodeProcessor() return $this->nodeProcessor; } - /** - * Returns a handler for the versioning mechanism - * - * @return VersionHandler - */ - private function getVersionHandler() - { - return $this->versionHandler; - } - /** * {@inheritDoc} */ @@ -2647,7 +2637,7 @@ private function initConnection() */ public function checkinItem($path) { - return $this->getVersionHandler()->checkinItem($path); + return $this->versionHandler->checkinItem($path); } /** @@ -2655,7 +2645,7 @@ public function checkinItem($path) */ public function checkoutItem($path) { - return $this->getVersionHandler()->checkoutItem($path); + return $this->versionHandler->checkoutItem($path); } /** @@ -2680,6 +2670,10 @@ public function removeVersion($versionPath, $versionName) */ public function setVersionHandler(VersionHandler $versionHandler) { + if ($this->versionHandler) { + throw new \InvalidArgumentException('Version handler is already set'); + } + $this->versionHandler = $versionHandler; } } From be38d84b977ee2164754861e055366f1dfbd33a1 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 11 Jun 2015 09:19:22 +0200 Subject: [PATCH 10/16] updated dependencies --- composer.json | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 8ffc5e99..d47983ba 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,5 @@ "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-utils.git" - } - ] + } } From beb30ff2cf4fba782113500b0fc026449463c28c Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 19 May 2015 14:18:55 +0200 Subject: [PATCH 11/16] enabled version history tests --- tests/ImplementationLoader.php | 1 - .../Test/Fixture/DBUnitFixtureXML.php | 231 ++++++++++++------ 2 files changed, 159 insertions(+), 73 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 892abad9..65b486bb 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -55,7 +55,6 @@ protected function __construct(Connection $connection, $fixturePath) 'Writing\\CloneMethodsTest', // TODO: Support for workspace->clone, node->update, node->getCorrespondingNodePath // TODO fully implement versioning - 'Versioning\\VersionHistoryTest', 'Versioning\\VersionManagerTest', 'Versioning\\VersionTest', ); diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index ba8c09fb..0a3fbb5d 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -47,17 +47,17 @@ class DBUnitFixtureXML extends XMLDocument private $rootNodes; /** - * @param string $file - file path - * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php + * @param string $file - file path + * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php */ public function __construct($file, $options = null) { parent::__construct($file, $options); - $this->tables = array(); - $this->ids = array(); - $this->references = array(); - $this->expectedNodes = array(); + $this->tables = array(); + $this->ids = array(); + $this->references = array(); + $this->expectedNodes = array(); } public function addDataset() @@ -65,13 +65,16 @@ public function addDataset() $this->appendChild($this->createElement('dataset')); // purge binary in case no binary properties are in fixture - $this->ensureTableExists('phpcr_binarydata', array( - 'node_id', - 'property_name', - 'workspace_name', - 'idx', - 'data', - )); + $this->ensureTableExists( + 'phpcr_binarydata', + array( + 'node_id', + 'property_name', + 'workspace_name', + 'idx', + 'data', + ) + ); return $this; } @@ -99,7 +102,7 @@ public function addNamespaces(array $namespaces) * * If the root node is not called jcr:root, autogenerate a root node. * - * @param string $workspaceName + * @param string $workspaceName * @param \DOMNodeList $nodes * * @return DBUnitFixtureXML @@ -114,7 +117,9 @@ 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'); + $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); } @@ -141,20 +146,20 @@ public function addRootNode($workspaceName = 'default') 'identifier' => $uuid, 'type' => 'nt:unstructured', 'props' => '' - . '', + . '', 'depth' => 0, 'sort_order' => 0, )); @@ -164,7 +169,7 @@ public function addNode($workspaceName, \DOMElement $node) { $properties = $this->getAttributes($node); $uuid = isset($properties['jcr:uuid']['value'][0]) - ? (string) $properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); + ? (string)$properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); $this->ids[$uuid] = $id = isset($this->expectedNodes[$uuid]) ? $this->expectedNodes[$uuid] : self::$idCounter++; @@ -184,23 +189,25 @@ public function addNode($workspaceName, \DOMElement $node) throw new \InvalidArgumentException('"' . $propertyData['type'] . '" is not a valid JCR type.'); } - $phpcrNode->appendChild($this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode)); + $phpcrNode->appendChild( + $this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode) + ); } list($parentPath, $childPath) = $this->getPath($node); - $namespace = ''; - $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); + $namespace = ''; + $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); if (count($parts = explode(':', $name, 2)) == 2) { list($namespace, $name) = $parts; } if ($namespace == 'jcr' && $name == 'root') { - $id = 1; - $childPath = '/'; + $id = 1; + $childPath = '/'; $parentPath = ''; - $name = ''; - $namespace = ''; + $name = ''; + $namespace = ''; } if (isset($properties['jcr:mixinTypes']) @@ -209,19 +216,22 @@ public function addNode($workspaceName, \DOMElement $node) $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id); } - $this->addRow('phpcr_nodes', array( - 'id' => $id, - 'path' => $childPath, - 'parent' => $parentPath, - 'local_name' => $name, - 'namespace' => $namespace, - 'workspace_name'=> $workspaceName, - 'identifier' => $uuid, - 'type' => $properties['jcr:primaryType']['value'][0], - 'props' => $dom->saveXML(), - 'depth' => PathHelper::getPathDepth($childPath), - 'sort_order' => $id - 2, - )); + $this->addRow( + 'phpcr_nodes', + array( + 'id' => $id, + 'path' => $childPath, + 'parent' => $parentPath, + 'local_name' => $name, + 'namespace' => $namespace, + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => $properties['jcr:primaryType']['value'][0], + 'props' => $dom->saveXML(), + 'depth' => PathHelper::getPathDepth($childPath), + 'sort_order' => $id - 2, + ) + ); return $this; } @@ -229,7 +239,7 @@ public function addNode($workspaceName, \DOMElement $node) public function addReferences() { foreach ($this->references as $type => $references) { - $table = 'phpcr_nodes_'.$type.'s'; + $table = 'phpcr_nodes_' . $type . 's'; // make sure we have the references even if there is not a single entry in it to have it truncated $this->ensureTableExists($table, array('source_id', 'source_property_name', 'target_id')); @@ -277,7 +287,10 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 - || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') + || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS( + $this->namespaces['sv'], + 'multiple' + ) == 'true') ) { $isMultiValue = true; } @@ -294,14 +307,31 @@ public function createPropertyNode($workspaceName, $propertyName, $propertyData, $binaryDataIdx = 0; foreach ($propertyData['value'] as $value) { - $propertyNode->appendChild($this->createValueNodeByType($workspaceName, $propertyData['type'], $value, $id, $propertyName, $binaryDataIdx++, $dom)); + $propertyNode->appendChild( + $this->createValueNodeByType( + $workspaceName, + $propertyData['type'], + $value, + $id, + $propertyName, + $binaryDataIdx++, + $dom + ) + ); } return $propertyNode; } - public function createValueNodeByType($workspaceName, $type, $value, $id, $propertyName, $binaryDataIdx, \DOMDocument $dom) - { + public function createValueNodeByType( + $workspaceName, + $type, + $value, + $id, + $propertyName, + $binaryDataIdx, + \DOMDocument $dom + ) { $length = is_scalar($value) ? strlen($value) : null; switch ($type) { case 'binary': @@ -329,9 +359,9 @@ public function createValueNodeByType($workspaceName, $type, $value, $id, $prope } // do not repeat references $this->references[$type][$value][$id . $propertyName . $targetId] = array( - 'source_id' => $id, - 'source_property_name' => $propertyName, - 'target_id' => $targetId, + 'source_id' => $id, + 'source_property_name' => $propertyName, + 'target_id' => $targetId, ); break; } @@ -360,7 +390,7 @@ public function createValueNode($value, \DOMDocument $dom, $length) public function getPath(\DOMElement $node) { - $childPath = ''; + $childPath = ''; $parent = $node; do { @@ -379,10 +409,10 @@ public function getPath(\DOMElement $node) } /** - * @param int $id + * @param int $id * @param string $propertyName * @param string $workspaceName - * @param int $idx + * @param int $idx * @param string $data * * @return int - length of base64 decoded string @@ -391,13 +421,16 @@ public function addBinaryNode($id, $propertyName, $workspaceName, $idx, $data) { $data = base64_decode($data); - $this->addRow('phpcr_binarydata', array( - 'node_id' => $id, - 'property_name' => $propertyName, - 'workspace_name' => $workspaceName, - 'idx' => $idx, - 'data' => $data, - )); + $this->addRow( + 'phpcr_binarydata', + array( + 'node_id' => $id, + 'property_name' => $propertyName, + 'workspace_name' => $workspaceName, + 'idx' => $idx, + 'data' => $data, + ) + ); return strlen($data); } @@ -447,6 +480,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ ) ); + // version node in version storage $versionNodeUuid = UUIDHelper::generateUUID(); $versionParentPath = '/jcr:system/jcr:versionStorage'; $versionPath = $versionParentPath . '/' . $versionNodeUuid; @@ -462,12 +496,36 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ 'identifier' => $versionNodeUuid, 'type' => 'nt:unstructured', 'props' => '' - . '', + . '' + . '' + . '' . $versionNodeUuid . '' + . '' + . '', 'depth' => PathHelper::getPathDepth($versionPath), 'sort_order' => $id - 2, ) ); + $this->addRow( + 'phpcr_nodes_references', + array( + 'source_id' => $id, + 'source_property_name' => 'jcr:versionHistory', + 'target_id' => self::$idCounter - 1 + ) + ); + + $node->appendChild( + $this->createPropertyNode( + $workspaceName, + 'jcr:versionHistory', + array('type' => 'reference', 'value' => array($versionNodeUuid), 'multiValued' => false), + $id, + $dom + ) + ); + + // root version $rootVersionPath = $versionPath . '/jcr:rootVersion'; $rootVersionUuid = UUIDHelper::generateUUID(); $this->addRow( @@ -482,7 +540,11 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ 'identifier' => $rootVersionUuid, 'type' => 'nt:version', 'props' => '' - . '', + . '' + . '' + . '' . $rootVersionUuid . '' + . '' + . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, ) @@ -491,8 +553,8 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ $node->appendChild( $this->createPropertyNode( $workspaceName, - 'jcr:versionHistory', - array('type' => 'reference', 'value' => array($versionNodeUuid), 'multiValued' => false), + 'jcr:baseVersion', + array('type' => 'reference', 'value' => array($rootVersionUuid), 'multiValued' => false), $id, $dom ) @@ -507,5 +569,30 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ $dom ) ); + + // frozen node for root version + $rootVersionFrozenNodePath = $rootVersionPath . '/jcr:frozenNode'; + $rootVersionFrozenNodeUuid = UUIDHelper::generateUUID(); + $this->addRow( + 'phpcr_nodes', + array( + 'id' => self::$idCounter++, + 'path' => $rootVersionFrozenNodePath, + 'parent' => $rootVersionPath, + 'local_name' => 'jcr:rootVersion', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $rootVersionFrozenNodeUuid, + 'type' => 'nt:version', + 'props' => '' + . '' + . '' + . '' . $rootVersionFrozenNodeUuid . '' + . '' + . '', + 'depth' => PathHelper::getPathDepth($rootVersionFrozenNodePath), + 'sort_order' => $id - 2, + ) + ); } } From ae72e3fb799d21eb15c7f7286148abe516329528 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 19 May 2015 15:21:15 +0200 Subject: [PATCH 12/16] added required versioning properties to test fixtures --- tests/ImplementationLoader.php | 5 +++++ tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 65b486bb..46c6640b 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -86,6 +86,11 @@ protected function __construct(Connection $connection, $fixturePath) // TODO: implement creating workspace with source 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithSource', 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithInvalidSource', + + // TODO: implement remove version + 'Versioning\\VersionHistoryTest::testDeleteVersion', + 'Versioning\\VersionHistoryTest::testDeleteLatestVersion', + 'Versioning\\VersionHistoryTest::testDeleteUnexistingVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index 0a3fbb5d..ab2db7a0 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -213,7 +213,7 @@ public function addNode($workspaceName, \DOMElement $node) if (isset($properties['jcr:mixinTypes']) && in_array('mix:versionable', $properties['jcr:mixinTypes']['value']) ) { - $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id); + $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id, $uuid); } $this->addRow( @@ -468,7 +468,7 @@ protected function ensureTableExists($tableName, $columns) return $this; } - private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $workspaceName, $id) + private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $workspaceName, $id, $uuid) { $node->appendChild( $this->createPropertyNode( @@ -500,6 +500,9 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . '' . $versionNodeUuid . '' . '' + . '' + . '' . $uuid . '' + . '' . '', 'depth' => PathHelper::getPathDepth($versionPath), 'sort_order' => $id - 2, @@ -544,6 +547,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . '' . $rootVersionUuid . '' . '' + . '' . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, From 7abb78d45d8a750ba9ebd893e9262b221d0d4b09 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Sat, 30 May 2015 13:16:33 +0200 Subject: [PATCH 13/16] enabled VerstionTests --- tests/ImplementationLoader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 46c6640b..af344d50 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -56,7 +56,6 @@ protected function __construct(Connection $connection, $fixturePath) // TODO fully implement versioning 'Versioning\\VersionManagerTest', - 'Versioning\\VersionTest', ); $this->unsupportedTests = array( From afba78770df3aa9f3b05d5d152658516bab976f2 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Fri, 5 Jun 2015 17:52:22 +0200 Subject: [PATCH 14/16] added new tests and adapted fixtures --- tests/ImplementationLoader.php | 6 +++--- tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index af344d50..3974c8e1 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -53,9 +53,6 @@ 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 - - // TODO fully implement versioning - 'Versioning\\VersionManagerTest', ); $this->unsupportedTests = array( @@ -90,6 +87,9 @@ protected function __construct(Connection $connection, $fixturePath) 'Versioning\\VersionHistoryTest::testDeleteVersion', 'Versioning\\VersionHistoryTest::testDeleteLatestVersion', 'Versioning\\VersionHistoryTest::testDeleteUnexistingVersion', + 'Versioning\\VersionManagerTest::testRestoreByPathAndName', + 'Versioning\\VersionManagerTest::testRestoreByVersionObject', + 'Versioning\\VersionManagerTest::testRestoreRootVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index ab2db7a0..b861fe0a 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -548,6 +548,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . $rootVersionUuid . '' . '' . '' + . '' . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, From 8bdf1ddce5325166f3cc00912535132dc66d47cb Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Wed, 10 Jun 2015 21:13:58 +0200 Subject: [PATCH 15/16] removed the test for write protection --- composer.json | 8 +++++++- tests/ImplementationLoader.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d47983ba..f7892102 100644 --- a/composer.json +++ b/composer.json @@ -42,5 +42,11 @@ "branch-alias": { "dev-master": "1.3-dev" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/danrot/jackalope.git" + } + ] } diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 3974c8e1..82c1cca8 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -90,6 +90,7 @@ protected function __construct(Connection $connection, $fixturePath) 'Versioning\\VersionManagerTest::testRestoreByPathAndName', 'Versioning\\VersionManagerTest::testRestoreByVersionObject', 'Versioning\\VersionManagerTest::testRestoreRootVersion', + 'Versioning\\VersionManagerTest::testWriteNotCheckedOutVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { From 34946d715902b6bf1374bedb1dafe3d18d472739 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 11 Jun 2015 11:55:39 +0200 Subject: [PATCH 16/16] cleaned code --- composer.json | 8 +- .../Test/Fixture/DBUnitFixtureXML.php | 183 +++++++----------- 2 files changed, 76 insertions(+), 115 deletions(-) diff --git a/composer.json b/composer.json index f7892102..d47983ba 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,5 @@ "branch-alias": { "dev-master": "1.3-dev" } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/danrot/jackalope.git" - } - ] + } } diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index b861fe0a..17eb6b57 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -47,16 +47,16 @@ class DBUnitFixtureXML extends XMLDocument private $rootNodes; /** - * @param string $file - file path - * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php + * @param string $file - file path + * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php */ public function __construct($file, $options = null) { parent::__construct($file, $options); - $this->tables = array(); - $this->ids = array(); - $this->references = array(); + $this->tables = array(); + $this->ids = array(); + $this->references = array(); $this->expectedNodes = array(); } @@ -65,16 +65,13 @@ public function addDataset() $this->appendChild($this->createElement('dataset')); // purge binary in case no binary properties are in fixture - $this->ensureTableExists( - 'phpcr_binarydata', - array( - 'node_id', - 'property_name', - 'workspace_name', - 'idx', - 'data', - ) - ); + $this->ensureTableExists('phpcr_binarydata', array( + 'node_id', + 'property_name', + 'workspace_name', + 'idx', + 'data', + )); return $this; } @@ -102,7 +99,7 @@ public function addNamespaces(array $namespaces) * * If the root node is not called jcr:root, autogenerate a root node. * - * @param string $workspaceName + * @param string $workspaceName * @param \DOMNodeList $nodes * * @return DBUnitFixtureXML @@ -117,9 +114,7 @@ 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' - ); + $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); } @@ -137,31 +132,31 @@ public function addRootNode($workspaceName = 'default') $this->ids[$uuid] = self::$idCounter++; return $this->addRow('phpcr_nodes', array( - 'id' => $this->ids[$uuid], - 'path' => '/', - 'parent' => '', - 'local_name' => '', - 'namespace' => '', - 'workspace_name'=> $workspaceName, - 'identifier' => $uuid, - 'type' => 'nt:unstructured', - 'props' => '' - . '', - 'depth' => 0, - 'sort_order' => 0, + 'id' => $this->ids[$uuid], + 'path' => '/', + 'parent' => '', + 'local_name' => '', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => 'nt:unstructured', + 'props' => '' + . '', + 'depth' => 0, + 'sort_order' => 0, )); } @@ -169,7 +164,7 @@ public function addNode($workspaceName, \DOMElement $node) { $properties = $this->getAttributes($node); $uuid = isset($properties['jcr:uuid']['value'][0]) - ? (string)$properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); + ? (string) $properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); $this->ids[$uuid] = $id = isset($this->expectedNodes[$uuid]) ? $this->expectedNodes[$uuid] : self::$idCounter++; @@ -189,25 +184,23 @@ public function addNode($workspaceName, \DOMElement $node) throw new \InvalidArgumentException('"' . $propertyData['type'] . '" is not a valid JCR type.'); } - $phpcrNode->appendChild( - $this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode) - ); + $phpcrNode->appendChild($this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode)); } list($parentPath, $childPath) = $this->getPath($node); $namespace = ''; - $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); + $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); if (count($parts = explode(':', $name, 2)) == 2) { list($namespace, $name) = $parts; } if ($namespace == 'jcr' && $name == 'root') { - $id = 1; - $childPath = '/'; + $id = 1; + $childPath = '/'; $parentPath = ''; - $name = ''; - $namespace = ''; + $name = ''; + $namespace = ''; } if (isset($properties['jcr:mixinTypes']) @@ -216,22 +209,19 @@ public function addNode($workspaceName, \DOMElement $node) $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id, $uuid); } - $this->addRow( - 'phpcr_nodes', - array( - 'id' => $id, - 'path' => $childPath, - 'parent' => $parentPath, - 'local_name' => $name, - 'namespace' => $namespace, - 'workspace_name' => $workspaceName, - 'identifier' => $uuid, - 'type' => $properties['jcr:primaryType']['value'][0], - 'props' => $dom->saveXML(), - 'depth' => PathHelper::getPathDepth($childPath), - 'sort_order' => $id - 2, - ) - ); + $this->addRow('phpcr_nodes', array( + 'id' => $id, + 'path' => $childPath, + 'parent' => $parentPath, + 'local_name' => $name, + 'namespace' => $namespace, + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => $properties['jcr:primaryType']['value'][0], + 'props' => $dom->saveXML(), + 'depth' => PathHelper::getPathDepth($childPath), + 'sort_order' => $id - 2, + )); return $this; } @@ -239,7 +229,7 @@ public function addNode($workspaceName, \DOMElement $node) public function addReferences() { foreach ($this->references as $type => $references) { - $table = 'phpcr_nodes_' . $type . 's'; + $table = 'phpcr_nodes_'.$type.'s'; // make sure we have the references even if there is not a single entry in it to have it truncated $this->ensureTableExists($table, array('source_id', 'source_property_name', 'target_id')); @@ -287,10 +277,7 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 - || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS( - $this->namespaces['sv'], - 'multiple' - ) == 'true') + || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') ) { $isMultiValue = true; } @@ -307,31 +294,14 @@ public function createPropertyNode($workspaceName, $propertyName, $propertyData, $binaryDataIdx = 0; foreach ($propertyData['value'] as $value) { - $propertyNode->appendChild( - $this->createValueNodeByType( - $workspaceName, - $propertyData['type'], - $value, - $id, - $propertyName, - $binaryDataIdx++, - $dom - ) - ); + $propertyNode->appendChild($this->createValueNodeByType($workspaceName, $propertyData['type'], $value, $id, $propertyName, $binaryDataIdx++, $dom)); } return $propertyNode; } - public function createValueNodeByType( - $workspaceName, - $type, - $value, - $id, - $propertyName, - $binaryDataIdx, - \DOMDocument $dom - ) { + public function createValueNodeByType($workspaceName, $type, $value, $id, $propertyName, $binaryDataIdx, \DOMDocument $dom) + { $length = is_scalar($value) ? strlen($value) : null; switch ($type) { case 'binary': @@ -359,9 +329,9 @@ public function createValueNodeByType( } // do not repeat references $this->references[$type][$value][$id . $propertyName . $targetId] = array( - 'source_id' => $id, + 'source_id' => $id, 'source_property_name' => $propertyName, - 'target_id' => $targetId, + 'target_id' => $targetId, ); break; } @@ -409,10 +379,10 @@ public function getPath(\DOMElement $node) } /** - * @param int $id + * @param int $id * @param string $propertyName * @param string $workspaceName - * @param int $idx + * @param int $idx * @param string $data * * @return int - length of base64 decoded string @@ -421,16 +391,13 @@ public function addBinaryNode($id, $propertyName, $workspaceName, $idx, $data) { $data = base64_decode($data); - $this->addRow( - 'phpcr_binarydata', - array( - 'node_id' => $id, - 'property_name' => $propertyName, - 'workspace_name' => $workspaceName, - 'idx' => $idx, - 'data' => $data, - ) - ); + $this->addRow('phpcr_binarydata', array( + 'node_id' => $id, + 'property_name' => $propertyName, + 'workspace_name' => $workspaceName, + 'idx' => $idx, + 'data' => $data, + )); return strlen($data); }