Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasCaleb committed Apr 29, 2024
1 parent b4e8df4 commit 1495fed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
10 changes: 5 additions & 5 deletions classes/task/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function execute() {
$users = null;

$types = $individualmessage.','.\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF;
if($configs->deletegroupmessages > 0) {
if ($configs->deletegroupmessages > 0) {
$types .= ','.\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP;
}

Expand All @@ -76,9 +76,9 @@ public function execute() {

$readmessagens = $DB->get_records_sql($sql, ['types' => $individualmessage,
'timeref' => $reftime, 'actiontype' => $viewaction,
'userref' => $user->userid,'timeref2' => $reftime,
'userref' => $user->userid, 'timeref2' => $reftime,
]);
foreach ($readmessagens as $readmessage) {// Just soft delete if both has saw it will be hard deleted
foreach ($readmessagens as $readmessage) {// Just soft delete if both has saw it will be hard deleted.
\core_message\api::delete_message($readmessage->useridfrom, $readmessage->messageid);
}
}
Expand All @@ -96,10 +96,10 @@ public function execute() {
LEFT JOIN {message_user_actions} uad on uad.messageid=m.id
";
$readmessagens = $DB->get_records_sql($sql, ['types' => $individualmessage,
'timeref' => $reftime,'userref' => $user->userid,
'timeref' => $reftime, 'userref' => $user->userid,
]);
foreach ($readmessagens as $readmessage) {
if ($configs->harddelete) {// If is old it need to be deleted
if ($configs->harddelete) {// If is old it need to be deleted.
hard_delete_message($readmessage->messageid);
} else {
\core_message\api::delete_message($readmessage->useridfrom, $readmessage->messageid);
Expand Down
60 changes: 33 additions & 27 deletions tests/tool_deletemessage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Delete Task.
*
Expand All @@ -18,16 +32,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_deletemessage_test extends \advanced_testcase {

/**
* Test if the hard delection function works
* @return void
* Make message to tests
* @return int message id
*/
public function test_deleting() {
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');
private function make_message(){
$userfrom = $this->getDataGenerator()->create_user();
$userto = $this->getDataGenerator()->create_user();

// Message text.
$messagetext = "hello";

Expand All @@ -43,8 +56,18 @@ public function test_deleting() {
$message->fullmessagehtml = $messagetext;
$message->smallmessage = $messagetext;

// Send message.
$messageid = message_send($message);
return message_send($message);
}

/**
* Test if the hard delection function works
* @return void
*/
public function test_deleting() {
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');

$messageid = $this->make_message();
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
hard_delete_message($messageid);
$this->assertEmpty($DB->get_records('message', ['id' => $messageid]));
Expand All @@ -55,28 +78,11 @@ public function test_deleting() {
* @return void
*/
public function test_taks_isnotdeleting() {
global $CFG,$DB;
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');
$user_from = $this->getDataGenerator()->create_user();
$user_to = $this->getDataGenerator()->create_user();

// Message text
$message_text = "hello";

// Create message object
$message = new \core\message\message();
$message->component = 'core';
$message->name = 'instantmessage';
$message->userfrom = $user_from;
$message->userto = $user_to;
$message->subject = '';
$message->fullmessage = $message_text;
$message->fullmessageformat = FORMAT_PLAIN;
$message->fullmessagehtml = $message_text;
$message->smallmessage = $message_text;
$messageid = $this->make_message();

// Send message
$messageid = message_send($message);
$cron = new \tool_deletemessage\task\delete();
$cron->execute();
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
Expand Down

0 comments on commit 1495fed

Please sign in to comment.