Skip to content

Commit

Permalink
Reverse-sort delete operations, fix for same-name siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Janssen committed Apr 16, 2013
1 parent 7ea1e02 commit 7943118
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Jackalope/Transport/Jackrabbit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,28 @@ public static function getDcrValue(DOMElement $node)
*/
public function deleteNodes(array $operations)
{
// Reverse sort the batch; work-around for problem with
// deleting same-name siblings. Not guaranteed to work
// across multiple calls to deleteNodes().
usort($operations, function ($a, $b) {
$aParts = array();
$bParts = array();
$regex = '/^(.+?)(?:\[(\d+)])?$/';

preg_match($regex, $a->srcPath, $aParts);
preg_match($regex, $b->srcPath, $bParts);

$aName = $aParts[1];
$bName = $bParts[1];
if ($aName != $bName) {
return strcmp($bName, $aName);
} else {
$aIndex = isset($aParts[2]) ? $aParts[2] : 1;
$bIndex = isset($bParts[2]) ? $bParts[2] : 1;
return $bIndex - $aIndex;
}
});

foreach ($operations as $operation) {
$this->deleteItem($operation->srcPath);
}
Expand Down

0 comments on commit 7943118

Please sign in to comment.