private function executeReorders($documents)
{
foreach ($documents as $oid => $list) {
if (!$this->contains($oid)) {
continue;
}
foreach ($list as $value) {
list($parent, $src, $target, $before) = $value;
$parentNode = $this->session->getNode($this->getDocumentId($parent));
// check for src and target ...
$dest = $target;
if ($parentNode->hasNode($src) && $parentNode->hasNode($target)) {
// there is no orderAfter, so we need to find the child after target to use it in orderBefore
if (!$before) {
$dest = null;
$found = false;
foreach ($parentNode->getNodes() as $name => $child) {
if ($name === $target) {
$found = true;
} elseif ($found) {
$dest = $name;
break;
}
}
}
$parentNode->orderBefore($src, $dest);
$class = $this->dm->getClassMetadata(get_class($parent));
foreach ($class->childrenMappings as $fieldName) {
if ($parent instanceof Proxy && $parent->__isInitialized()) {
$children = $class->reflFields[$fieldName]->getValue($parent);
$children->refresh();
}
}
}
}
}
}