Commit 667582fc authored by Guillaume Heurtier's avatar Guillaume Heurtier

FIX #11641 TIME 2:30 fix bug on updating levels of sub-folders when moving folders

parent 8cb44085
......@@ -207,13 +207,15 @@ class FolderController
$data['parent_id'] = null;
$level = 0;
} else {
$folder = FolderController::getScopeFolders(['login' => $GLOBALS['userId'], 'folderId' => $data['parent_id']]);
if (empty($folder[0])) {
$folderParent = FolderController::getScopeFolders(['login' => $GLOBALS['userId'], 'folderId' => $data['parent_id']]);
if (empty($folderParent[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Parent Folder not found or out of your perimeter']);
}
$level = $folder[0]['level'] + 1;
$level = $folderParent[0]['level'] + 1;
}
$this->updateChildren($aArgs['id'], $level);
FolderModel::update([
'set' => [
'label' => $data['label'],
......@@ -674,4 +676,27 @@ class FolderController
}
return false;
}
private function updateChildren($parentId, $levelParent)
{
$folderChild = FolderModel::getChild(['id' => $parentId]);
if (!empty($folderChild)) {
$level = -1;
foreach ($folderChild as $child) {
$level = $levelParent + 1;
$this->updateChildren($child['id'], $level);
}
$idsChildren = array_column($folderChild, 'id');
FolderModel::update([
'set' => [
'level' => $level
],
'where' => ['id in (?)'],
'data' => [$idsChildren]
]);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment