Skip to content

Commit

Permalink
Remove log dumps and commented out bits
Browse files Browse the repository at this point in the history
  • Loading branch information
mickhawkins committed Oct 5, 2023
1 parent 1e15137 commit af7d398
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 113 deletions.
118 changes: 45 additions & 73 deletions communication/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
}
}

/**
Expand Down
19 changes: 0 additions & 19 deletions communication/classes/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions communication/classes/task/create_and_configure_room_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion communication/configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -2542,28 +2531,21 @@ 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,
communicationroomname: $communicationroomname,
avatar: $courseimage,
instance: $data,
);
} else {
error_log("NEW PROVIDER IS NONE");
}
}

Expand Down

0 comments on commit af7d398

Please sign in to comment.