Skip to content

Commit

Permalink
Add deletion email
Browse files Browse the repository at this point in the history
  • Loading branch information
Syxton committed Feb 6, 2025
1 parent 483c021 commit 73b85a5
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 115 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:16
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -30,8 +30,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1']
moodle-branch: ['MOODLE_403_STABLE', 'MOODLE_402_STABLE']
php: ['8.2', '8.3']
moodle-branch: ['main']
database: [pgsql, mariadb]

steps:
Expand Down
6 changes: 4 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -13,13 +13,15 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for tool_coursearchiver.
* File containing processor class.
*
* @package tool_coursearchiver
* @copyright 2015 Matthew Davidson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_coursearchiver\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\contextlist;
Expand Down
67 changes: 43 additions & 24 deletions classes/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ class tool_coursearchiver_processor {
*/
const MODE_ARCHIVEEMAIL = 7;

/**
* Send emails about pending course deletion.
*/
const MODE_DELETEEMAIL = 8;

/**
* Delete courses.
*/
const MODE_DELETE = 8;
const MODE_DELETE = 9;

/**
* Optout courses.
*/
const MODE_OPTOUT = 9;
const MODE_OPTOUT = 10;

/** @var int processor mode. */
protected $mode;
Expand Down Expand Up @@ -146,6 +151,7 @@ public function __construct(array $options) {
self::MODE_DELETE,
self::MODE_HIDEEMAIL,
self::MODE_ARCHIVEEMAIL,
self::MODE_DELETEEMAIL,
self::MODE_OPTOUT,
])) {
throw new coding_exception('Unknown process mode');
Expand Down Expand Up @@ -183,6 +189,7 @@ public function execute($outputtype = tool_coursearchiver_tracker::NO_OUTPUT, $t
self::MODE_DELETE,
self::MODE_HIDEEMAIL,
self::MODE_ARCHIVEEMAIL,
self::MODE_DELETEEMAIL,
self::MODE_OPTOUT,
])) {
if (empty($mform)) {
Expand Down Expand Up @@ -366,6 +373,7 @@ public function execute($outputtype = tool_coursearchiver_tracker::NO_OUTPUT, $t
break;
case self::MODE_HIDEEMAIL:
case self::MODE_ARCHIVEEMAIL:
case self::MODE_DELETEEMAIL:
$tracker->start();
if (!empty($this->data)) {
// Loop over the user array.
Expand Down Expand Up @@ -819,6 +827,10 @@ protected function sendemail($obj) {
$subject = get_string('archivewarningsubject', 'tool_coursearchiver');
$message = $config->archivewarningemailsetting;
break;
case self::MODE_DELETEEMAIL:
$subject = get_string('deletewarningsubject', 'tool_coursearchiver');
$message = $config->deletewarningemailsetting;
break;
default:
$this->errors[] = get_string('invalidmode', 'tool_coursearchiver');
return false;
Expand Down Expand Up @@ -1354,6 +1366,8 @@ public function get_email_courses($obj, $links = true) {
$optoutbutton = get_string('optouthide', 'tool_coursearchiver');
} else if ($this->mode == self::MODE_ARCHIVEEMAIL) {
$optoutbutton = get_string('optoutarchive', 'tool_coursearchiver');
} else if ($this->mode == self::MODE_DELETEEMAIL) {
$optoutbutton = get_string('optoutdelete', 'tool_coursearchiver');
}

$tablehtml = [];
Expand All @@ -1365,30 +1379,35 @@ public function get_email_courses($obj, $links = true) {
// Create security key for each link.
$key = sha1($CFG->dbpass . $course->id . $obj["user"]->id);

// Only add courses that are visible if mode is HIDEEMAIL.
if ($this->mode == self::MODE_ARCHIVEEMAIL || $course->visible) {
$rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF";
$linkstring = "";
if ($links) {
$linkstring = html_writer::tag('td', '', ['width' => '5px']) .
html_writer::tag('td',
html_writer::link(new moodle_url('/admin/tool/coursearchiver/optout.php',
['courseid' => $course->id,
'userid' => $obj["user"]->id,
'key' => $key,
]),
$optoutbutton));
}

$tablehtml[] = html_writer::tag('tr',
html_writer::tag('td',
html_writer::link(new moodle_url('/course/view.php',
['id' => $course->id]),
$course->fullname)) . $linkstring,
['style' => 'background-color:' . $rowcolor]);
} else { // This course is not included in the email.
// Only add courses that are not hidden if mode is HIDEEMAIL.
if ($this->mode == self::MODE_HIDEEMAIL && !$course->visible) {
$this->notices[] = get_string('noticecoursehidden', 'tool_coursearchiver', $course);
continue;
}

// Change rowcolor.
$rowcolor = $rowcolor == "#FFF" ? "#EEE" : "#FFF";

// Add optout links.
$linkstring = "";
if ($links) {
$linkstring = html_writer::tag('td', '', ['width' => '5px']) .
html_writer::tag('td',
html_writer::link(new moodle_url('/admin/tool/coursearchiver/optout.php',
['courseid' => $course->id,
'userid' => $obj["user"]->id,
'key' => $key,
]),
$optoutbutton));
}

$tablehtml[] = html_writer::tag('tr',
html_writer::tag('td',
html_writer::link(new moodle_url('/course/view.php',
['id' => $course->id]),
$course->fullname)) . $linkstring,
['style' => 'background-color:' . $rowcolor]);

}
$tablehtml[] = html_writer::end_tag('table');

Expand Down
2 changes: 1 addition & 1 deletion classes/step1_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class tool_coursearchiver_step1_form extends moodleform {
* The standard form definiton.
* @return void
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$mform->addElement('header', 'searchhdr', get_string('search'));

Expand Down
2 changes: 1 addition & 1 deletion classes/step2_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step2_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand Down
3 changes: 2 additions & 1 deletion classes/step3_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step3_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand All @@ -56,6 +56,7 @@ public function definition () {
$buttonarray = [];
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('hideemail', 'tool_coursearchiver'));
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('archiveemail', 'tool_coursearchiver'));
$buttonarray[] = &$mform->createElement('submit', 'submit_button', get_string('deleteemail', 'tool_coursearchiver'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');

Expand Down
10 changes: 9 additions & 1 deletion classes/step4_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class tool_coursearchiver_step4_form extends moodleform {
* The standard form definiton.
* @return void.
*/
public function definition () {
public function definition() {
$mform = $this->_form;
$data = $this->_customdata['processor_data'];

Expand Down Expand Up @@ -72,6 +72,14 @@ public function definition () {
}
$message = get_string('confirmmessagearchiveemail', 'tool_coursearchiver', $count);
break;
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
foreach (unserialize($data["formdata"]) as $r) { // Loop through every possible user.
if (substr($r, 0, 1) == 'x') { // Determine if they were NOT selected.
$count--; // Remove 1 from count.
}
}
$message = get_string('confirmmessagedeleteemail', 'tool_coursearchiver', $count);
break;
case tool_coursearchiver_processor::MODE_HIDE:
$message = get_string('confirmmessagehide', 'tool_coursearchiver', $count);
break;
Expand Down
8 changes: 8 additions & 0 deletions classes/tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public function results($mode, $total, $errors, $notices) {
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
$modetext = "archiveemail";
break;
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
$modetext = "deleteemail";
break;
case tool_coursearchiver_processor::MODE_HIDE:
$modetext = "hide";
break;
Expand Down Expand Up @@ -284,6 +287,7 @@ public function start() {
case tool_coursearchiver_processor::MODE_DELETE:
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
case tool_coursearchiver_processor::MODE_OPTOUT:
break;
}
Expand Down Expand Up @@ -396,6 +400,7 @@ public function start() {
break;
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
$buffer = new progress_trace_buffer(new text_progress_trace());
$buffer->output('<h3>' . get_string('processemailing', 'tool_coursearchiver') .
'</h3><div class="coursearchiver_progress_bar_spacing"></div><br />');
Expand Down Expand Up @@ -466,6 +471,7 @@ public function output($data, $info = false) {
case tool_coursearchiver_processor::MODE_DELETE:
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
case tool_coursearchiver_processor::MODE_OPTOUT:
$out = $this->get_progressbar();
do {
Expand Down Expand Up @@ -598,6 +604,7 @@ public function output($data, $info = false) {
case tool_coursearchiver_processor::MODE_DELETE:
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
case tool_coursearchiver_processor::MODE_OPTOUT:
$this->buffer->output($this->get_progressbar());
break;
Expand Down Expand Up @@ -666,6 +673,7 @@ public function finish() {
case tool_coursearchiver_processor::MODE_DELETE:
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
case tool_coursearchiver_processor::MODE_OPTOUT:
$this->buffer->output('<div class="coursearchiver_completedmsg">' .
get_string('processcomplete', 'tool_coursearchiver') .
Expand Down
13 changes: 8 additions & 5 deletions cli/coursearchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
'O' => 'startafter',
'd' => 'endbefore',
'D' => 'endafter',
'g' => 'ignadmins',
's' => 'ignsiteroles',
'I' => 'ignadmins',
'S' => 'ignsiteroles',
'm' => 'mode',
'l' => 'location',
'e' => 'empty',
Expand Down Expand Up @@ -100,9 +100,9 @@
-O, --startafter Course starts after UNIX TIMESTAMP
-d, --endbefore Course ends before UNIX TIMESTAMP
-D, --endafter Course ends after UNIX TIMESTAMP
-i, --ignadmins Ignore admin account accesses
-I, --ignsiteroles Ignore site role accesses
-m, --mode courselist,emaillist,hide,backup,archive,delete,hideemail,archiveemail
-I, --ignadmins Ignore admin account accesses
-S, --ignsiteroles Ignore site role accesses
-m, --mode courselist,emaillist,hide,backup,archive,delete,hideemail,archiveemail,deleteemail
-l, --location Folder name to store archived courses (optional)
-e, --empty Only return empty courses
-v, --verbose Maximum output from tool (optional)
Expand All @@ -122,6 +122,7 @@
'hideemail' => tool_coursearchiver_processor::MODE_HIDEEMAIL,
'hide' => tool_coursearchiver_processor::MODE_HIDE,
'archiveemail' => tool_coursearchiver_processor::MODE_ARCHIVEEMAIL,
'deleteemail' => tool_coursearchiver_processor::MODE_DELETEEMAIL,
'backup' => tool_coursearchiver_processor::MODE_BACKUP,
'archive' => tool_coursearchiver_processor::MODE_ARCHIVE,
'delete' => tool_coursearchiver_processor::MODE_DELETE,
Expand Down Expand Up @@ -215,6 +216,7 @@
break;
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
$processor = new tool_coursearchiver_processor(["mode" => tool_coursearchiver_processor::MODE_COURSELIST,
"data" => $options,
]);
Expand Down Expand Up @@ -290,6 +292,7 @@
break;
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
case tool_coursearchiver_processor::MODE_DELETEEMAIL:
$owners = [];
foreach ($selected as $s) {
$t = explode("_", $s);
Expand Down
Loading

0 comments on commit 73b85a5

Please sign in to comment.