Restore/fix forum changes

pull/4004/head
Julio 3 years ago
parent 2055edd804
commit 55e8de2b69
  1. 62
      public/main/forum/forumfunction.inc.php
  2. 2
      public/main/forum/viewthread.php
  3. 20
      src/CourseBundle/Repository/CForumCategoryRepository.php
  4. 4
      src/CourseBundle/Repository/CForumThreadRepository.php
  5. 2
      tests/CourseBundle/Repository/CForumCategoryRepositoryTest.php
  6. 1
      tests/CourseBundle/Repository/CThematicRepositoryTest.php

@ -757,17 +757,6 @@ function store_forum(array $values, array $courseInfo = [], bool $returnId = fal
// Update.
$repo->update($forum);
if (isset($upload_ok)) {
if ($has_attachment) {
//$params['forum_image'] = $new_file_name;
}
}
if (isset($values['remove_picture']) && 1 == $values['remove_picture']) {
/*$params['forum_image'] = '';
deleteForumImage($forum);*/
}
// Move groups from one group to another
if (isset($values['group_forum']) && false) {
$forumData = get_forums($values['forum_id']);
@ -786,9 +775,6 @@ function store_forum(array $values, array $courseInfo = [], bool $returnId = fal
];
Event::registerLog($logInfo);
} else {
if ($image_moved) {
$new_file_name = isset($new_file_name) ? $new_file_name : '';
}
$forum
->setParent($forumCategory)
->addCourseLink($course, $session);
@ -839,34 +825,32 @@ function deletePost(CForumPost $post): void
{
$table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
$em = Database::getManager();
if ($post) {
$em
->createQuery('
UPDATE ChamiloCourseBundle:CForumPost p
SET p.postParent = :parent_of_deleted_post
WHERE
p.postParent = :post AND
p.thread = :thread_of_deleted_post AND
p.forum = :forum_of_deleted_post
')
->execute([
'parent_of_deleted_post' => $post->getPostParent(),
'post' => $post->getIid(),
'thread_of_deleted_post' => $post->getThread() ? $post->getThread()->getIid() : 0,
'forum_of_deleted_post' => $post->getForum(),
]);
$attachments = $post->getAttachments();
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
$em->remove($attachment);
}
$em
->createQuery('
UPDATE ChamiloCourseBundle:CForumPost p
SET p.postParent = :parent_of_deleted_post
WHERE
p.postParent = :post AND
p.thread = :thread_of_deleted_post AND
p.forum = :forum_of_deleted_post
')
->execute([
'parent_of_deleted_post' => $post->getPostParent(),
'post' => $post->getIid(),
'thread_of_deleted_post' => $post->getThread() ? $post->getThread()->getIid() : 0,
'forum_of_deleted_post' => $post->getForum(),
]);
$attachments = $post->getAttachments();
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
$em->remove($attachment);
}
$em->remove($post);
$em->flush();
}
$em->remove($post);
$em->flush();
$lastPostOfTheTread = getLastPostOfThread($post->getThread()->getIid());
if (!empty($lastPostOfTheTread)) {

@ -169,7 +169,7 @@ switch ($my_action) {
) {
/** @var CForumPost $postEntity */
$postEntity = $repoPost->find($_GET['id']);
if (!empty($postEntity)) {
if (null !== $postEntity) {
deletePost($postEntity);
}
}

@ -30,24 +30,4 @@ class CForumCategoryRepository extends ResourceRepository
$session
);
}
/*public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroup $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}*/
public function delete(ResourceInterface $resource): void
{
/** @var CForumCategory $resource */
$forums = $resource->getForums();
$repo = $this->getEntityManager()->getRepository(CForum::class);
if (!empty($forums)) {
foreach ($forums as $forum) {
/** @var CForum $forum */
$repo->delete($forum);
}
}
parent::delete($resource);
}
}

@ -57,11 +57,9 @@ class CForumThreadRepository extends ResourceRepository
{
/** @var CForumThread $resource */
$posts = $resource->getPosts();
$repo = $this->getEntityManager()->getRepository(CForumPost::class);
if (!empty($posts)) {
foreach ($posts as $post) {
/** @var CForumPost $post */
$repo->delete($post);
parent::delete($post);
}
}
parent::delete($resource);

@ -58,6 +58,6 @@ class CForumCategoryRepositoryTest extends AbstractApiTest
$categoryRepo->delete($category);
$this->assertSame(0, $categoryRepo->count([]));
$this->assertSame(0, $forumRepo->count([]));
$this->assertSame(1, $forumRepo->count([]));
}
}

@ -29,6 +29,7 @@ class CThematicRepositoryTest extends AbstractApiTest
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);

Loading…
Cancel
Save