-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.php
69 lines (59 loc) · 2.75 KB
/
cleanup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use BigBlueButton\BigBlueButton;
use BigBlueButton\Parameters\GetRecordingsParameters;
use BigBlueButton\Parameters\DeleteRecordingsParameters;
/**
* Directory where published recording files are placed
*/
$recordingsPublishDir = '/mnt/scalelite-recordings/var/bigbluebutton/published/presentation/';
/**
* Hostname of the scalelite
*/
$url = 'https://example.com/bigbluebutton/';
/**
* The shared secret t
*/
$secret = '123456';
$bbb = new BigBlueButton($secret, $url);
$maxAge = strtotime('-2 weeks midnight', time());
$dir = new DirectoryIterator($recordingsPublishDir);
foreach ($dir as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
$metaXml = $recordingsPublishDir . $fileinfo->getFilename() . '/metadata.xml';
if (file_exists($metaXml)) {
$xml = simplexml_load_file($metaXml);
if ($xml) {
$endDate = ((float)$xml->end_time / 1000);
if ((string)$xml->state === 'published' && $maxAge > $endDate) {
$meetingName = (string)$xml->meetingName;
$meetingId = (string)$xml->meetingId;
$recordingParams = new GetRecordingsParameters();
$recordingParams->setMeetingId($meetingId);
$response = $bbb->getRecordings($recordingParams);
if ($response->getReturnCode() == 'SUCCESS') {
foreach ($response->getRawXml()->recordings->recording as $recording) {
$recordingStartDate = ((float)$recording->startTime / 1000);
$recordingEndDate = ((float)$recording->endTime / 1000);
if($maxAge > $recordingStartDate && $maxAge > $recordingEndDate) {
$recordingName = (string)$recording->name;
$deleteRecordingsParams= new DeleteRecordingsParameters((string)$recording->recordID);
$deleteResponse = $bbb->deleteRecordings($deleteRecordingsParams);
if ($deleteResponse->getReturnCode() == 'SUCCESS') {
printf("%s deleted (%s - %s)\n\n",
$recordingName,
date('d.m.Y H:i', $recordingStartDate),
date('d.m.Y H:i', $recordingEndDate)
);
} else {
echo "Error - {$recordingName}\n";
}
}
}
}
}
}
}
}
}