Resources - Use $repo->update instead of em->persist + flush

pull/3706/head
Julio Montoya 4 years ago
parent 1f4f6779cc
commit 9a61c2f395
  1. 4
      public/main/course_description/course_description_controller.php
  2. 3
      public/main/exercise/TestCategory.php
  3. 24
      public/main/forum/forumfunction.inc.php
  4. 3
      public/main/inc/lib/AnnouncementManager.php
  5. 3
      public/main/inc/lib/ExerciseCategoryManager.php
  6. 6
      public/main/inc/lib/attendance.lib.php
  7. 3
      public/main/inc/lib/groupmanager.lib.php
  8. 6
      public/main/inc/lib/link.lib.php
  9. 3
      public/main/inc/lib/notebook.lib.php
  10. 3
      public/main/inc/lib/thematic.lib.php
  11. 3
      public/main/lp/learnpath.class.php
  12. 2
      public/main/lp/lp_subscribe_users_to_category.php
  13. 3
      public/main/work/edit.php
  14. 8
      public/main/work/work.lib.php
  15. 3
      public/main/work/work.php
  16. 3
      src/CoreBundle/Entity/Listener/ResourceListener.php
  17. 8
      src/CoreBundle/Repository/ResourceRepository.php

@ -161,9 +161,7 @@ class CourseDescriptionController
->setProgress($progress)
->setContent($content)
;
$repo->getEntityManager()->persist($courseDescription);
$repo->getEntityManager()->flush();
$repo->update($courseDescription);
/*$course_description->set_description_type($description_type);
$course_description->set_title($title);
$course_description->set_content($content);

@ -161,8 +161,7 @@ class TestCategory
->setTitle($this->name)
->setDescription($this->description);
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
$repo->update($category);
return true;
}

@ -166,8 +166,7 @@ function handleForum($url)
}
$resource->setLocked($locked);
$repo->getEntityManager()->persist($resource);
$repo->getEntityManager()->flush();
$repo->update($resource);
Display::addFlash(
Display::return_message($message, 'confirmation', false)
@ -664,9 +663,7 @@ function store_forumcategory($values, $courseInfo = [], $showMessage = true)
->setCatComment(isset($values['forum_category_comment']) ? $values['forum_category_comment'] : '')
->setCatTitle($values['forum_category_title'])
;
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
$repo->updateResource($category);
$message = get_lang('The forum category has been modified');
$logInfo = [
@ -837,9 +834,8 @@ function store_forum($values, $courseInfo = [], $returnId = false)
$session = api_get_session_entity($session_id);
if (isset($values['forum_id'])) {
// Edit
$repo->getEntityManager()->persist($forum);
$repo->getEntityManager()->flush();
// Update.
$repo->update($forum);
if (isset($upload_ok)) {
if ($has_attachment) {
@ -1306,8 +1302,7 @@ function move_up_down($content, $direction, $id)
/** @var CForumForum $forum */
$forum = $repo->find($id);
$forum->setForumOrder($next_sort);
$repo->getEntityManager()->persist($forum);
$repo->getEntityManager()->flush();
$repo->update($forum);
Display::addFlash(Display::return_message(get_lang('Updated')));
} else {
@ -1317,8 +1312,7 @@ function move_up_down($content, $direction, $id)
$category = $repo->find($id);
if ($category) {
$category->setCatOrder($next_sort);
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
$repo->update($category);
Display::addFlash(Display::return_message(get_lang('Updated')));
}
@ -3839,8 +3833,7 @@ function store_edit_post(CForumForum $forum, $values)
if ($updateStatus) {
$post->setStatus($status);
}
$repo->getEntityManager()->persist($post);
$repo->getEntityManager()->flush();
$repo->update($post);
}
// Update attached files
@ -5108,8 +5101,7 @@ function delete_attachment($postId, $attachmentId)
$post->removeAttachment($attachment);
$repo->getEntityManager()->remove($attachment);
}
$repo->getEntityManager()->persist($post);
$repo->getEntityManager()->flush();
$repo->update($post);
Display::addFlash(Display::return_message(get_lang('The attached file has been deleted'), 'confirmation'));
}

@ -903,8 +903,7 @@ class AnnouncementManager
$announcement->addCourseLink($course, $session);
}
$repo->getEntityManager()->persist($announcement);
$repo->getEntityManager()->flush();
$repo->update($announcement);
return $announcement;
}

@ -124,8 +124,7 @@ class ExerciseCategoryManager extends Model
->setDescription($params['description'])
;
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
$repo->update($category);
return true;
}

@ -421,8 +421,7 @@ class Attendance
;
$repo = Container::getAttendanceRepository();
$repo->getEntityManager()->persist($attendance);
$repo->getEntityManager()->flush();
$repo->update($attendance);
/*$params = [
'name' => $this->name,
@ -544,8 +543,7 @@ class Attendance
$repo = Container::getAttendanceRepository();
$attendance->setActive(2);
$repo->getEntityManager()->persist($attendance);
$repo->getEntityManager()->flush();
$repo->update($attendance);
Skill::deleteSkillsFromItem($attendance->getIid(), ITEM_TYPE_ATTENDANCE);

@ -773,8 +773,7 @@ class GroupManager
->setDocumentAccess($documentAccess)
;
$repo->getEntityManager()->persist($group);
$repo->getEntityManager()->flush();
$repo->update($group);
/* Here we are updating a field in the table forum_forum that perhaps
duplicates the table group_info.forum_state cvargas*/

@ -561,8 +561,7 @@ class Link extends Model
$link->setCategory($category);
}
$repo->getEntityManager()->persist($link);
$repo->getEntityManager()->flush();
$repo->update($link);
// Update search enchine and its values table if enabled.
if ('true' === api_get_setting('search_enabled')) {
@ -721,8 +720,7 @@ class Link extends Model
->setDescription($values['description'])
;
$repo->getEntityManager()->persist($category);
$repo->getEntityManager()->flush();
$repo->update($category);
Display::addFlash(Display::return_message(get_lang('The category has been modified.')));

@ -121,8 +121,7 @@ class NotebookManager
->setDescription($values['note_comment'])
;
$repo->getEntityManager()->persist($notebook);
$repo->getEntityManager()->flush();
$repo->update($notebook);
return true;
}

@ -1025,8 +1025,7 @@ class Thematic
$thematic->getPlans()->removeElement($plan);
}
}
$repo->getEntityManager()->persist($thematic);
$repo->getEntityManager()->flush();
$repo->update($thematic);
return false;

@ -7008,8 +7008,7 @@ class learnpath
}
$document->setTitle($_REQUEST['title']);
$repo->getEntityManager()->persist($document);
$repo->getEntityManager()->flush();
$repo->update($document);
}
}

@ -1,11 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CLpCategoryUser;
use Chamilo\UserBundle\Entity\User;
use Doctrine\Common\Collections\Criteria;
require_once __DIR__.'/../inc/global.inc.php';

@ -266,8 +266,7 @@ if ($form->validate()) {
->setDescription($description)
->setTitle($title)
;
$repo->getEntityManager()->persist($studentPublication);
$repo->getEntityManager()->flush();
$repo->update($studentPublication);
}
/*api_item_property_update(

@ -4910,7 +4910,7 @@ function deleteWorkItem($item_id, $courseInfo)
/** @var CStudentPublication $work */
$work = $repo->find($item_id);
$work->setActive(2);
$repo->getEntityManager()->persist($work);
$repo->update($work);
$repo = Container::getStudentPublicationAssignmentRepository();
$params = ['cId' => $course_id, 'publicationId' => $item_id];
@ -5127,8 +5127,7 @@ function makeVisible($itemId, $course_info)
$studentPublication = $repo->find($itemId);
if ($studentPublication) {
$studentPublication->setAccepted(1);
$repo->getEntityManager()->persist($studentPublication);
$repo->getEntityManager()->flush();
$repo->update($studentPublication);
}
/*
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
@ -5160,8 +5159,7 @@ function makeInvisible($itemId, $course_info)
$studentPublication = $repo->find($itemId);
if ($studentPublication) {
$studentPublication->setAccepted(0);
$repo->getEntityManager()->persist($studentPublication);
$repo->getEntityManager()->flush();
$repo->update($studentPublication);
}
/*api_item_property_update(

@ -231,8 +231,7 @@ switch ($action) {
$studentPublication->setParentId($_REQUEST['move_to_id']);
$studentPublication->getResourceNode()->setParent($newParent->getResourceNode());
$repo->getEntityManager()->persist($studentPublication);
$repo->getEntityManager()->flush();
$repo->update($studentPublication);
/*api_item_property_update(
$courseInfo,

@ -82,7 +82,7 @@ class ResourceListener
public function prePersist(AbstractResource $resource, LifecycleEventArgs $event)
{
error_log('resource listener prePersist for obj: '.get_class($resource));
error_log('Resource listener prePersist for obj: '.get_class($resource));
$em = $event->getEntityManager();
$request = $this->request;
@ -229,7 +229,6 @@ class ResourceListener
public function preUpdate(AbstractResource $resource, PreUpdateEventArgs $event)
{
error_log('Resource listener preUpdate');
$this->setLinks($resource->getResourceNode(), $resource, $event->getEntityManager());
if ($resource->hasUploadFile()) {

@ -233,6 +233,14 @@ class ResourceRepository extends EntityRepository
$em->flush();
}*/
public function update(AbstractResource $resource): void
{
$resource->getResourceNode()->setTitle($resource->getResourceName());
$this->getEntityManager()->persist($resource);
$this->getEntityManager()->flush();
}
public function updateNodeForResource(ResourceInterface $resource): ResourceNode
{
$em = $this->getEntityManager();

Loading…
Cancel
Save