Revert "Revert "kaban : fix comments count for virtual sample step""
This reverts commit 37b0175941.
This commit is contained in:
parent
37b0175941
commit
f47886ccf0
4 changed files with 78 additions and 51 deletions
|
|
@ -12,7 +12,6 @@ permissions:
|
|||
inspirations: false
|
||||
materials: false
|
||||
creations: false
|
||||
pages: false
|
||||
user:
|
||||
changeRole: false
|
||||
delete: false
|
||||
|
|
|
|||
|
|
@ -4,56 +4,58 @@ use adrienpayet\comments\Comment;
|
|||
|
||||
return [
|
||||
'pattern' => '(:all)create-comment.json',
|
||||
'method' => 'POST',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
// kirby()->impersonate('kirby');
|
||||
|
||||
$page = page($data->fileParentUri);
|
||||
$project = $page->parent()->template() == "project" ? $page->parent() : $page->parent()->parent();
|
||||
$project = $page->parent()->template() == 'project' ? $page->parent() : $page->parent()->parent();
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$commentData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"file" => $file
|
||||
'location' => [
|
||||
'page' => $page,
|
||||
'project' => $project,
|
||||
'file' => $file,
|
||||
],
|
||||
"position" => [
|
||||
"x" => $data->position->x,
|
||||
"y" => $data->position->y
|
||||
'position' => [
|
||||
'x' => $data->position->x,
|
||||
'y' => $data->position->y,
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment",
|
||||
'date' => (string) $data->date,
|
||||
'text' => $data->text,
|
||||
'author' => kirby()->user(),
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'comment',
|
||||
];
|
||||
|
||||
if (isset($data->position->pageIndex)) {
|
||||
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
|
||||
$commentData['position']['pageIndex'] = $data->position->pageIndex;
|
||||
}
|
||||
|
||||
$newComment = new Comment($commentData);
|
||||
|
||||
$comments[] = $newComment->toArray();
|
||||
|
||||
$comments[] = $newComment->toArray();
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
'comments' => $comments,
|
||||
]);
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
|
||||
try {
|
||||
$project->createNotification($commentData);
|
||||
$project->createNotification($commentData);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception($th->getMessage() . ". line " . $th->getLine() . " in file " . $th->getFile(), 1);
|
||||
throw new Exception($th->getMessage() . '. line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
];
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,45 +2,46 @@
|
|||
|
||||
return [
|
||||
'pattern' => '(:all)delete-comment.json',
|
||||
'method' => 'POST',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
// kirby()->impersonate('kirby');
|
||||
|
||||
$page = page($data->location->page->uri);
|
||||
|
||||
|
||||
$file = $page->file($data->location->file->uuid);
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$isReply = $data->location->parent->id ?? false;
|
||||
foreach ($comments as $key => &$comment) {
|
||||
if ($isReply) {
|
||||
if ($comment['id'] === $data->location->parent->id) {
|
||||
foreach ($comment['replies'] as $replyKey => $reply) {
|
||||
if ($reply['id'] === $data->id) {
|
||||
unset($comment['replies'][$replyKey]);
|
||||
$comment['replies'] = array_values($comment['replies']);
|
||||
if ($isReply) {
|
||||
if ($comment['id'] === $data->location->parent->id) {
|
||||
foreach ($comment['replies'] as $replyKey => $reply) {
|
||||
if ($reply['id'] === $data->id) {
|
||||
unset($comment['replies'][$replyKey]);
|
||||
$comment['replies'] = array_values($comment['replies']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($comment['id'] === $data->id) {
|
||||
unset($comments[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($comment['id'] === $data->id) {
|
||||
unset($comments[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$comments = array_values($comments);
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
'comments' => $comments,
|
||||
]);
|
||||
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
$project = $page->parents()->findBy("template", "project");
|
||||
|
||||
$project = $page->parents()->findBy('template', 'project');
|
||||
$project->deleteNotification($data->id);
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue