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

references by uuid #734

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from

Conversation

ElectricMaxxx
Copy link
Contributor

This should wrap up #493

didn't implement the stuff, commented in code not to change.

But there are still the Questions of @dbu

I go top to button through the text/conversation, cause it is really hard to remember what the purpose was, even for me :-)

Copy link
Contributor

@dantleech dantleech left a comment

Choose a reason for hiding this comment

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

Can you summarize the motivation behind this PR in the description? I don't really know the full implications of this change.

@@ -21,7 +21,8 @@
"phpcr/phpcr-implementation": "^2.1.0",
"phpcr/phpcr-utils": "^1.2.8",
"doctrine/instantiator": "^1.0.1",
"symfony/console": "^2.3|^3.0"
"symfony/console": "^2.3|^3.0",
"jackalope/jackalope-doctrine-dbal": "~1.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think this should be here...

$node = $this->session->getNode($this->determineDocumentId($document));
$pathOrUuid = $this->determineDocumentId($document);
$node = $this->getNodeByPathOrUuid($pathOrUuid);
if (UUIDHelper::isUUID($pathOrUuid)) {
Copy link
Contributor

@dantleech dantleech Jan 17, 2017

Choose a reason for hiding this comment

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

Empty line before if statement

$frozen = $this->session->nodeExists($id) && $this->session->getNode($id)->isNodeType('nt:frozenNode');
try {
$node = $this->getNodeByPathOrUuid($pathOrUuid);
$frozen = $node instanceof NodeInterface ? $node->isNodeType('nt:frozenNode') : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the node is not an instance of NodeInterface then what is it? If we are expecting null then I think we should check forr null.

@@ -917,13 +917,11 @@ public function initializeObject($document)
*/
public function getNodeForDocument($document)
{
if (!is_object($document)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove this validation?

@@ -917,13 +917,11 @@ public function initializeObject($document)
*/
public function getNodeForDocument($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
if (!$identifier = $this->unitOfWork->getDocumentId($document)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (null === $identifier = $this->...

@@ -674,7 +675,7 @@ public function getOrCreateProxy($targetId, $className, $locale = null)
$metadata = $this->dm->getClassMetadata($className);
$proxyDocument = $this->dm->getProxyFactory()->getProxy($className, array($metadata->identifier => $targetId));

// register the document under its own id
// register the document under its own id/uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

path/uuid.

@@ -3113,6 +3126,20 @@ public function getDocumentById($id)
}

/**
* Creates a node from a given path or an uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

given path or UUID

} catch (ItemNotFoundException $e) {
$frozen = false;
} catch (PathNotFoundException $e) {
$frozen = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

$frozen = false can be moved before the try block (doesn't need to be repeated twice)

$nodeData = array(
"jcr:primaryType" => $primaryType,
"jcr:system" => array(),
'username' => $username,
);
if (null !== $uuid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer a blank line before most if statements.

->will($this->returnValue($node));
}


Copy link
Contributor

Choose a reason for hiding this comment

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

One blank line too many

@ElectricMaxxx
Copy link
Contributor Author

This will fail for sure now ... Did a lot of changes

  • introduced a object hash - uuid map, which is filled when a document is registered by its uuid (on DocumentManager::getReference() call with proxies referencing documents by their uuid <- @dantleech purpose)
  • introduced a uuid - path map to find documents by their path in identity map, which are managed by uuid

so all documents still live in identityMap by their id, but the id can be the absolute paths directly or uuids which needs to be converted into paths (uuid - id map).

@ElectricMaxxx ElectricMaxxx changed the title [WIP] references by uuid references by uuid Jan 18, 2017
Copy link
Contributor

@dantleech dantleech left a comment

Choose a reason for hiding this comment

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

Still not sure what the motivation of this is? Regarding the mapping I wonder if it is worth introducing a Registry class to encapsulate the various maps, reducing complication in this already very complicated class, something like: https://github.com/sulu/sulu-document-manager/blob/master/lib/DocumentRegistry.php.

But maybe something for a later iteration.

@@ -100,6 +101,18 @@ class UnitOfWork
private $documentIds = array();

/**
* @var array
*/
private $documentUuids = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this would be better named $oidToUuidMap, but to be consistent this naming is fine for now I guess. But it should be commented.

*
* @var array
*/
private $uuidIdMapping = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

Id in uuidId is redundant. Better to name $uuidToPathMap.

@@ -3058,23 +3076,43 @@ private function unregisterDocument($document)
$this->documentVersion[$oid]
);

if (!empty($this->documentUuids[$oid]) && array_key_exists($this->documentUuids[$oid], $this->uuidIdMapping)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why check for !empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants