diff --git a/communication/classes/api.php b/communication/classes/api.php index 57e549685292b..39081d38e5bf5 100644 --- a/communication/classes/api.php +++ b/communication/classes/api.php @@ -105,7 +105,6 @@ public static function load_by_instance( * Reload in the internal instance data. */ public function reload(): void { -//error_log("RELOAD"); $this->communication = processor::load_by_instance( context: $this->context, component: $this->component, @@ -462,85 +461,58 @@ public function update_room( ?\stored_file $avatar = null, ?\stdClass $instance = null, ): void { - // Existing object found, let's update the communication record and associated actions. - // if ($this->communication !== null) { - // Reload so the currently selected provider is used. - $this->reload(); -//error_log("API UPDATE CALLED, active = $active, provider = {$this->provider}"); - // If the provider is none, we don't need to do anything from room point of view. - if ($this->communication->get_provider() === processor::PROVIDER_NONE) { -// error_log("UPDATE PROVIDER IS NONEEEEEE"); - return; - } + // Reload so the currently selected provider is used. + $this->reload(); - $roomnamechange = null; - $activestatuschange = null; - $roomupdaterequired = false; - - // Check if the room name is being changed. - if ( - $communicationroomname !== null && - $communicationroomname !== $this->communication->get_room_name() - ) { - $roomnamechange = $communicationroomname; - $roomupdaterequired = true; - } + // If the provider is none, we don't need to do anything from room point of view. + if ($this->communication->get_provider() === processor::PROVIDER_NONE) { + return; + } - // Check if the active status of the provider is being changed. - if ( - $active !== null && - $active !== $this->communication->is_instance_active() - ) { -// error_log("IS DETECTING ACTIVE"); - $activestatuschange = $active; - } else { - $test = $this->communication->is_instance_active() ? "Already active" : "Not already active"; -// error_log("NOT DETECTING ACTIVE CHANGE, $test"); - } + $roomnamechange = null; + $activestatuschange = null; + $roomupdaterequired = false; + + // Check if the room name is being changed. + if ( + $communicationroomname !== null && + $communicationroomname !== $this->communication->get_room_name() + ) { + $roomnamechange = $communicationroomname; + $roomupdaterequired = true; + } - if ($roomnamechange !== null || $activestatuschange !== null) { -// error_log("CALLING COMM UPDATE INSTANCE"); - $this->communication->update_instance( - active: $active, - roomname: $communicationroomname, - ); - } + // Check if the active status of the provider is being changed. + if ( + $active !== null && + $active !== $this->communication->is_instance_active() + ) { + $activestatuschange = $active; + } - // Update provider record from form data. - if ($instance !== null) { - $this->communication->get_form_provider()->save_form_data($instance); - } + if ($roomnamechange !== null || $activestatuschange !== null) { + $this->communication->update_instance( + active: $active, + roomname: $communicationroomname, + ); + } - // Update the avatar. - // If the value is `null`, then unset the avatar. - if ($this->set_avatar($avatar)) { - $roomupdaterequired = true; - } + // Update provider record from form data. + if ($instance !== null) { + $this->communication->get_form_provider()->save_form_data($instance); + } - if ($roomupdaterequired) { - update_room_task::queue( - $this->communication, - ); - } + // Update the avatar. + // If the value is `null`, then unset the avatar. + if ($this->set_avatar($avatar)) { + $roomupdaterequired = true; + } - // Add ad-hoc task to update the provider room if the room name changed. - // TODO add efficiency considering dynamic fields. - // if ( - // $previousprovider === $selectedprovider - // ) { - // update_room_task::queue( - // $this->communication, - // ); - // } else { - // // Add ad-hoc task to create the provider room. - // create_and_configure_room_task::queue( - // $this->communication, - // ); - // } - // } else { - // // The instance had no communication record for this provider type, so create one. - // $this->create_and_configure_room($selectedprovider, $communicationroomname, $avatar, $instance); - // } + if ($roomupdaterequired) { + update_room_task::queue( + $this->communication, + ); + } } /** diff --git a/communication/classes/processor.php b/communication/classes/processor.php index 92f31e36bdeeb..5c8aad3677df2 100644 --- a/communication/classes/processor.php +++ b/communication/classes/processor.php @@ -124,9 +124,6 @@ public function update_instance( if ($active !== null && in_array($active, [self::PROVIDER_ACTIVE, self::PROVIDER_INACTIVE])) { $this->instancedata->active = $active; - error_log ("Updating status to $active"); - } else { - error_log("Not change in active status"); } if ($roomname !== null) { @@ -381,8 +378,6 @@ public static function load_by_instance( global $DB; if ($provider === null) { -// $test ="PROVIDER IS NULL^^^^^^^^^"; -// $test2 = "active provider"; // Fetch the active provider in this context. $record = $DB->get_record('communication', [ 'contextid' => $context->id, @@ -392,8 +387,6 @@ public static function load_by_instance( 'active' => 1, ]); } else { -// $test ="PROVIDER IS {$provider}^^^^^^^^^"; -// $test2 = "given provider"; // Fetch a specific provider in this context (which may be inactive). $record = $DB->get_record('communication', [ 'contextid' => $context->id, @@ -403,18 +396,6 @@ public static function load_by_instance( 'provider' => $provider, ]); } -// if (is_bool($record)) { -// error_log("NO RECORD FOUND - $test2 @@@@@@"); -// error_log($test); -// } else { -// error_log("!!!!!!!!!!!!!!!!!"); -// error_log("ID: {$record->id}"); -// error_log("Instance ID: {$record->instanceid}"); -// error_log("Provider: {$record->provider}"); -// error_log("Active: {$record->active}"); -// error_log("Room name: {$record->roomname}"); -// error_log($test); -// } if ($record && self::is_provider_available($record->provider)) { return new self($record); } diff --git a/communication/classes/task/create_and_configure_room_task.php b/communication/classes/task/create_and_configure_room_task.php index 98ffde607a07c..3439c4eabf7ba 100644 --- a/communication/classes/task/create_and_configure_room_task.php +++ b/communication/classes/task/create_and_configure_room_task.php @@ -44,8 +44,6 @@ public function execute() { mtrace("Skipping room creation because the instance is not active"); return; } -mtrace("####################################"); -mtrace("TASK PROVIDER: {$communication->get_provider()}"); // If the room is created successfully, add members to the room if supported by the provider. if ($communication->get_room_provider()->create_chat_room() && $communication->supports_user_features()) { add_members_to_room_task::queue( diff --git a/communication/configure.php b/communication/configure.php index 530b0e0cd1f20..c1c7f197b9209 100644 --- a/communication/configure.php +++ b/communication/configure.php @@ -45,7 +45,6 @@ if (!core_communication\api::is_available()) { throw new \moodle_exception('communicationdisabled', 'communication'); } -error_log("SELECTED: $selectedcommunication"); // Attempt to load the communication instance with the provided params. $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/course/lib.php b/course/lib.php index 9dfecebd216fb..7792a234af35d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2470,17 +2470,11 @@ function update_course($data, $editoroptions = NULL) { instanceid: $data->id, ); $existingprovider = $communication->get_provider(); - -$test1 = $communication->get_provider(); -error_log("############ new provider = $provider, old provider = $test1"); -error_log(var_export($test1,true)); - $addusersrequired = false; $enablenewprovider = false; // Action required changes if provider has changed. if ($provider !== $existingprovider) { -error_log("CHANGE IN PROVIDER"); // Provider changed, flag new one to be enabled. $enablenewprovider = true; @@ -2520,13 +2514,8 @@ function update_course($data, $editoroptions = NULL) { provider: $provider, ); -// error_log("SWITCH PROVIDER TO expect $provider, get {$communication->get_provider()}"); -// $communication->reload(); -// error_log("RELOADED PROVIDER - {$communication->get_provider()}"); - // Create it if it does not exist. if ($communication->get_provider() === '') { -error_log("Create provider"); $communication->create_and_configure_room( selectedcommunication: $provider, communicationroomname: $communicationroomname, @@ -2542,19 +2531,14 @@ function update_course($data, $editoroptions = NULL) { provider: $provider, ); } else if ($addusersrequired) { -error_log("Queue adding members"); // For providers that already exist, add members to the room if required. // Newly created providers automatically add members. $communication->add_members_to_room($enrolledusers); - } else { -error_log('Add users not required'); } } } if ($provider !== 'none') { - $test = $enablenewprovider ? \core_communication\processor::PROVIDER_ACTIVE : 0; - error_log("NEW STATUS WILL BE: $test for provider {$communication->get_provider()}"); // Update the currently enabled provider's room data. $communication->update_room( active: $enablenewprovider ? \core_communication\processor::PROVIDER_ACTIVE : null, @@ -2562,8 +2546,6 @@ function update_course($data, $editoroptions = NULL) { avatar: $courseimage, instance: $data, ); - } else { - error_log("NEW PROVIDER IS NONE"); } }