Skip to content

Commit

Permalink
Merge pull request #293 from jackalope/fix_many_reference_delete
Browse files Browse the repository at this point in the history
fix issues with deleting of references
  • Loading branch information
dbu committed Oct 9, 2015
2 parents 3debea5 + f141ccb commit c12f081
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -27,7 +27,7 @@
},
"require-dev": {
"psr/log": "~1.0",
"phpcr/phpcr-api-tests": "2.1.7",
"phpcr/phpcr-api-tests": "2.1.8",
"phpunit/phpunit": "4.7.*",
"phpunit/dbunit": "~1.3"
},
Expand Down
25 changes: 12 additions & 13 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Expand Up @@ -738,12 +738,12 @@ private function getJcrName($path)
/**
* Actually write the node into the database
*
* @param string $uuid node uuid
* @param string $path absolute path of the node
* @param string $type node type
* @param boolean $isNewNode new nodes to insert (true) or existing node to update (false)
* @param array $props
* @param array $propsData
* @param string $uuid node uuid
* @param string $path absolute path of the node
* @param string $type node type name
* @param boolean $isNewNode new nodes to insert (true) or existing node to update (false)
* @param Property[] $props
* @param array $propsData
*
* @return boolean|string
*
Expand Down Expand Up @@ -823,9 +823,7 @@ private function syncNode($uuid, $path, $type, $isNewNode, $props = array(), $pr
$this->syncBinaryData($nodeId, $propsData['binaryData']);
}

if (!empty($propsData['references'])) {
$this->referencesToUpdate[$nodeId] = array('path' => $path, 'properties' => $propsData['references']);
}
$this->referencesToUpdate[$nodeId] = array('path' => $path, 'properties' => $propsData['references']);

return $nodeId;
}
Expand Down Expand Up @@ -856,23 +854,24 @@ private function syncBinaryData($nodeId, $binaryData)
}
}

private function syncReferences($referencesToUpdate)
private function syncReferences(array $referencesToUpdate)
{
if ($referencesToUpdate) {
// do not update references that are going to be deleted anyways
$toUpdate = array_diff_assoc($referencesToUpdate, $this->referencesToDelete);
$toUpdate = array_diff(array_keys($referencesToUpdate), array_keys($this->referencesToDelete));

try {
foreach ($this->referenceTables as $table) {
$query = "DELETE FROM $table WHERE source_id IN (?)";
$this->executeChunkedUpdate($query, array_keys($toUpdate));
$this->executeChunkedUpdate($query, $toUpdate);
}
} catch (DBALException $e) {
throw new RepositoryException('Unexpected exception while cleaning up after saving', $e->getCode(), $e);
}

$updates = array();
foreach ($toUpdate as $nodeId => $references) {
foreach ($toUpdate as $nodeId) {
$references = $referencesToUpdate[$nodeId];
foreach ($references['properties'] as $name => $data) {
foreach ($data['values'] as $value) {
$targetId = $this->getSystemIdForNodeUuid($value);
Expand Down

0 comments on commit c12f081

Please sign in to comment.