Each time someone join a meeting the program go through a condition which test if the meeting has a create date "createtime". So each time a request is send to create a new record. But I don't want to create one each time. This behaviour is logical but my problem happens while the meeting is already created. So in this case the program should not go through the condition. So I have a duplication in my records list.
public static function join_meeting(instance $instance, $origin = logger::ORIGIN_BASE): string {
global $DB;
// See if the session is in progress.
$meeting = new meeting($instance);
// As the meeting doesn't exist, try to create it.
if (empty($meeting->get_meeting_info(true)->createtime)) {
$meetingInfos = $meeting->create_meeting();
$serverNumber = (!empty($meetingInfos['serverNumber'])) ? (int)$meetingInfos['serverNumber'] : 1;
}
else
$serverNumber = $DB->get_field('bigbluebuttonbn', 'server_number', array('id' => $meeting->get_meeting_info(true)->instanceid));
$instance->set_server_number($serverNumber);
return $meeting->join($origin, $serverNumber);
}
public function get_meeting_info() {
if (!$this->meetinginfo) {
$this->meetinginfo = $this->do_get_meeting_info();
}
return $this->meetinginfo;
}
public function create_meeting() {
global $DB;
$data = $this->create_meeting_data();
$serverNumber = (int)$DB->get_field('bigbluebuttonbn', 'server_number', ['id' => $this->instance->get_instance_id()]);
$metadata = $this->create_meeting_metadata();
$presentation = $this->instance->get_presentation_for_bigbluebutton_upload(); // The URL must contain nonce.
$presentationname = $presentation['name'] ?? null;
$presentationurl = $presentation['url'] ?? null;
$response = bigbluebutton_proxy::create_meeting($data, $metadata, $presentationname, $presentationurl, $serverNumber);
// CUSTOM : Log the meeting creation
logger::log_instance_start($this->instance->get_instance_data());
// New recording management: Insert a recordingID that corresponds to the meeting created.
if ($this->instance->is_recorded()) {
$recording = new recording(0, (object) [
'courseid' => $this->instance->get_course_id(),
'bigbluebuttonbnid' => $this->instance->get_instance_id(),
'recordingid' => $response['internalMeetingID'],
'groupid' => $this->instance->get_group_id(),
'server_number' => $serverNumber
]);
$recording->create();
}
return $response;
}
protected function do_get_meeting_info(bool $updatecache = false): stdClass {
$instance = $this->instance;
$meetinginfo = (object) [
'instanceid' => $instance->get_instance_id(),
'bigbluebuttonbnid' => $instance->get_instance_id(),
'groupid' => $instance->get_group_id(),
'meetingid' => $instance->get_meeting_id(),
'cmid' => $instance->get_cm_id(),
'ismoderator' => $instance->is_moderator(),
'joinurl' => $instance->get_join_url()->out(),
'userlimit' => $instance->get_user_limit(),
'presentations' => [],
];
if ($instance->get_instance_var('openingtime')) {
$meetinginfo->openingtime = intval($instance->get_instance_var('openingtime'));
}
if ($instance->get_instance_var('closingtime')) {
$meetinginfo->closingtime = intval($instance->get_instance_var('closingtime'));
}
$activitystatus = bigbluebutton_proxy::view_get_activity_status($instance);
// This might raise an exception if info cannot be retrieved.
// But this might be totally fine as the meeting is maybe not yet created on BBB side.
$totalusercount = 0;
// This is the default value for any meeting that has not been created.
$meetinginfo->statusrunning = false;
$meetinginfo->createtime = null;
$info = self::retrieve_cached_meeting_info($this->instance->get_meeting_id(), $instance->get_server_number(), $updatecache);
if (!empty($info)) {
$meetinginfo->statusrunning = $info['running'] === 'true';
$meetinginfo->createtime = $info['createTime'] ?? null;
$totalusercount = isset($info['participantCount']) ? $info['participantCount'] : 0;
}
$meetinginfo->statusclosed = $activitystatus === 'ended';
$meetinginfo->statusopen = !$meetinginfo->statusrunning && $activitystatus === 'open';
$meetinginfo->totalusercount = $totalusercount;
$canjoin = !$instance->user_must_wait_to_join() || $meetinginfo->statusrunning;
// Limit has not been reached or user does not count toward limit.
$canjoin = $canjoin && (
!$instance->has_user_limit_been_reached($totalusercount)
|| !$instance->does_current_user_count_towards_user_limit()
);
// User should only join during scheduled session start and end time, if defined.
$canjoin = $canjoin && ($instance->is_currently_open());
// Double check that the user has the capabilities to join.
$canjoin = $canjoin && $instance->can_join();
$meetinginfo->canjoin = $canjoin;
// If user is administrator, moderator or if is viewer and no waiting is required, join allowed.
if ($meetinginfo->statusrunning) {
$meetinginfo->startedat = floor(intval($info['startTime']) / 1000); // Milliseconds.
$meetinginfo->moderatorcount = $info['moderatorCount'];
$meetinginfo->moderatorplural = $info['moderatorCount'] > 1;
$meetinginfo->participantcount = $totalusercount - $meetinginfo->moderatorcount;
$meetinginfo->participantplural = $meetinginfo->participantcount > 1;
}
$meetinginfo->statusmessage = $this->get_status_message($meetinginfo, $instance);
$presentation = $instance->get_presentation(); // This is for internal use.
if (!empty($presentation)) {
$meetinginfo->presentations[] = $presentation;
}
$meetinginfo->attendees = [];
if (!empty($info['attendees'])) {
// Ensure each returned attendee is cast to an array, rather than a simpleXML object.
foreach ($info['attendees'] as $attendee) {
$meetinginfo->attendees[] = (array) $attendee;
}
}
$meetinginfo->guestaccessenabled = $instance->is_guest_allowed();
if ($meetinginfo->guestaccessenabled && $instance->is_moderator()) {
$meetinginfo->guestjoinurl = $instance->get_guest_access_url()->out();
$meetinginfo->guestpassword = $instance->get_guest_access_password();
}
$meetinginfo->features = $instance->get_enabled_features();
return $meetinginfo;
}
My expectation is to understand why when I join a meeting (which is already created) the program understand it's a new meeting so I have to create it.