From 2898d5ff9ca785f7d171b41dbee2ddd76d06a84b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 12 Dec 2018 17:10:54 -0500 Subject: [PATCH] Implement doWhenDeletingUser to avoid constraint when deleting course/user --- plugin/ims_lti/ImsLtiPlugin.php | 13 +++++++++++++ plugin/studentfollowup/StudentFollowUpPlugin.php | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugin/ims_lti/ImsLtiPlugin.php b/plugin/ims_lti/ImsLtiPlugin.php index c996b9fd56..2b144ea6bd 100644 --- a/plugin/ims_lti/ImsLtiPlugin.php +++ b/plugin/ims_lti/ImsLtiPlugin.php @@ -543,4 +543,17 @@ class ImsLtiPlugin extends Plugin } } } + + /** + * Avoid conflict with foreign key when deleting a course + * + * @param int $courseId + */ + public function doWhenDeletingCourse($courseId) + { + $em = Database::getManager(); + + $em->createQuery('DELETE FROM ChamiloPluginBundle:ImsLti\ImsLtiTool tool WHERE tool.course = :c_id') + ->execute(['c_id' => (int) $courseId]); + } } diff --git a/plugin/studentfollowup/StudentFollowUpPlugin.php b/plugin/studentfollowup/StudentFollowUpPlugin.php index 26864c78a3..032ddc9d36 100644 --- a/plugin/studentfollowup/StudentFollowUpPlugin.php +++ b/plugin/studentfollowup/StudentFollowUpPlugin.php @@ -240,4 +240,15 @@ class StudentFollowUpPlugin extends Plugin { return 20; } + + /** + * @param int $userId + */ + public function doWhenDeletingUser($userId) + { + $userId = (int) $userId; + + Database::query("DELETE FROM sfu_post WHERE user_id = $userId"); + Database::query("DELETE FROM sfu_post WHERE insert_user_id = $userId"); + } }