-
Notifications
You must be signed in to change notification settings - Fork 502
Plugin: Cleanup BBB recordings on course/session deletion - refs #3143 #6377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
christianbeeznest
wants to merge
1
commit into
chamilo:master
Choose a base branch
from
christianbeeznest:GH-3143
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
use Chamilo\CoreBundle\Entity\ConferenceMeeting; | ||
use Chamilo\CoreBundle\Entity\ConferenceRecording; | ||
use Chamilo\CourseBundle\Entity\CCourseSetting; | ||
use Chamilo\CoreBundle\Entity\Course; | ||
|
||
|
@@ -60,6 +62,7 @@ protected function __construct() | |
'bbb_force_record_generation' => 'checkbox', | ||
'disable_course_settings' => 'boolean', | ||
'meeting_duration' => 'text', | ||
'delete_recordings_on_course_delete' => 'boolean', | ||
] | ||
); | ||
|
||
|
@@ -159,6 +162,128 @@ public static function updateCourseFieldInAllCourses(string $variable, string $v | |
$entityManager->flush(); | ||
} | ||
|
||
// Hook called when a course is deleted | ||
public function doWhenDeletingCourse($courseId): void | ||
{ | ||
// Check if the setting is enabled | ||
if ($this->get('delete_recordings_on_course_delete') !== 'true') { | ||
return; | ||
} | ||
|
||
$this->removeBbbRecordingsForCourse($courseId); | ||
} | ||
|
||
// Hook called when a session is deleted | ||
public function doWhenDeletingSession($sessionId): void | ||
{ | ||
// Check if the setting is enabled | ||
if ($this->get('delete_recordings_on_course_delete') !== 'true') { | ||
return; | ||
} | ||
|
||
$this->removeBbbRecordingsForSession($sessionId); | ||
} | ||
|
||
// Remove BBB recordings linked to a specific course | ||
private function removeBbbRecordingsForCourse(int $courseId): void | ||
{ | ||
$em = Database::getManager(); | ||
$meetingRepo = $em->getRepository(ConferenceMeeting::class); | ||
$recordingRepo = $em->getRepository(ConferenceRecording::class); | ||
|
||
// Get all BBB meetings for this course | ||
$meetings = $meetingRepo->createQueryBuilder('m') | ||
->where('m.course = :cid') | ||
->andWhere('m.serviceProvider = :sp') | ||
->setParameters(['cid' => $courseId, 'sp' => 'bbb']) | ||
->getQuery() | ||
->getResult(); | ||
|
||
foreach ($meetings as $meeting) { | ||
// Get all recordings of this meeting | ||
$recordings = $recordingRepo->findBy([ | ||
'meeting' => $meeting, | ||
'formatType' => 'bbb', | ||
]); | ||
|
||
foreach ($recordings as $rec) { | ||
// Try to extract the record ID from the URL | ||
if ($recordId = $this->extractRecordId($rec->getResourceUrl())) { | ||
$this->deleteRecording($recordId); // Call BBB API to delete | ||
} | ||
|
||
$em->remove($rec); // Remove local record | ||
} | ||
|
||
$em->remove($meeting); // Optionally remove the meeting entity | ||
} | ||
|
||
$em->flush(); // Save all removals | ||
} | ||
|
||
// Remove BBB recordings linked to a specific session | ||
private function removeBbbRecordingsForSession(int $sessionId): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
{ | ||
$em = Database::getManager(); | ||
$meetingRepo = $em->getRepository(ConferenceMeeting::class); | ||
$recordingRepo = $em->getRepository(ConferenceRecording::class); | ||
|
||
// Get all BBB meetings for this session | ||
$meetings = $meetingRepo->findBy([ | ||
'session' => $sessionId, | ||
'serviceProvider' => 'bbb', | ||
]); | ||
|
||
foreach ($meetings as $meeting) { | ||
$recordings = $recordingRepo->findBy([ | ||
'meeting' => $meeting, | ||
'formatType' => 'bbb', | ||
]); | ||
|
||
foreach ($recordings as $rec) { | ||
if ($recordId = $this->extractRecordId($rec->getResourceUrl())) { | ||
$this->deleteRecording($recordId); | ||
} | ||
|
||
$em->remove($rec); | ||
} | ||
|
||
$em->remove($meeting); | ||
} | ||
|
||
$em->flush(); | ||
} | ||
|
||
// Extracts the recordID from the BBB recording URL | ||
private function extractRecordId(string $url): ?string | ||
{ | ||
// Match parameter ?recordID=xxx | ||
if (preg_match('/[?&]recordID=([\w-]+)/', $url, $matches)) { | ||
return $matches[1]; | ||
} | ||
|
||
// Optional: match paths like .../recordingID-123456 | ||
if (preg_match('/recordingID[-=](\d+)/', $url, $matches)) { | ||
return $matches[1]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
// Sends a deleteRecordings API request to BigBlueButton | ||
private function deleteRecording(string $recordId): void | ||
{ | ||
$host = rtrim($this->get('host'), '/'); | ||
$salt = $this->get('salt'); | ||
|
||
$query = "recordID={$recordId}"; | ||
$checksum = sha1('deleteRecordings' . $query . $salt); | ||
$url = "{$host}/bigbluebutton/api/deleteRecordings?{$query}&checksum={$checksum}"; | ||
|
||
// Send the request (silently) | ||
@file_get_contents($url); | ||
} | ||
|
||
public function get_name(): string | ||
{ | ||
return 'Bbb'; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
removeBbbRecordingsForCourse
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.