Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/logsendedmails #218

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions classes/task/lifecycle_cleanup_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function get_name() {
public function execute() {
global $DB;
$twomonthago = time() - 60 * 24 * 60 * 60;
$oneyearago = time() - 365 * 24 * 60 * 60;
$DB->delete_records_select('tool_lifecycle_delayed', 'delayeduntil <= :time', ['time' => $twomonthago]);
$DB->delete_records_select('tool_lifecycle_delayed_workf', 'delayeduntil <= :time', ['time' => $twomonthago]);
$DB->delete_records_select('lifecyclestep_email_notified', 'timemailsent <= :time', ['time' => $oneyearago]);
}
}
2 changes: 2 additions & 0 deletions lang/de/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
$string['config_delay_duration_desc'] = 'Diese Einstellung definiert den Standardlänge einer Kursausschlusses in einem Workflow
falls ein Prozess des Workflows zurückgesetzt oder beendigt wird. Die Länge des Kursausschlusses besagt, wie lange es dauert, bis
der Kurs wieder vom Workflow bearbeitet wird.';
$string['config_logreceivedmails'] = 'Zusätzliches Logging von E-mails zu Nutzern.';
$string['config_logreceivedmails_desc'] = 'Das Schreiben in die Datenbank hat den Vorteil, dass es explizit nachgeguckt werden kann, allerdings verbraucht es Speicher.';
$string['config_showcoursecounts'] = 'Zeige Anzahl der Kurse, die getriggert werden';
$string['config_showcoursecounts_desc'] = 'Die Workflow-Konfigurationsseite zeigt normalerweise die Anzahl an Kursen, die durch
die konfigurierten Trigger getriggert werden, was Performance-Probleme verursachen kann. Bei Performance-Problemen kann dies hiermit
Expand Down
2 changes: 2 additions & 0 deletions lang/en/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
$string['config_delay_duration_desc'] = 'This setting defines the default delay duration of a workflow
in case one of its processes is rolled back or finishes.
The delay duration determines how long a course will be excepted from being processed again in either of the cases.';
$string['config_logreceivedmails'] = 'Save sent mails to the database';
$string['config_logreceivedmails_desc'] = 'Additionally writing to the database has the advantage that it can be looked up, however it consumes memory.';
$string['config_showcoursecounts'] = 'Show amount of courses which will be triggered';
$string['config_showcoursecounts_desc'] = 'The workflow overview page by default shows the amount of courses which will be
triggered by the configured triggers which can be load heavy. Disable this option if you experience issues loading the workflow
Expand Down
5 changes: 5 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
get_string('config_showcoursecounts_desc', 'tool_lifecycle'),
1));

$settings->add(new admin_setting_configcheckbox('tool_lifecycle/logreceivedmails',
get_string('config_logreceivedmails', 'tool_lifecycle'),
get_string('config_logreceivedmails_desc', 'tool_lifecycle'),
0));

$ADMIN->add('lifecycle_category', new admin_externalpage('tool_lifecycle_workflow_drafts',
get_string('workflow_drafts_header', 'tool_lifecycle'),
new moodle_url(\tool_lifecycle\urls::WORKFLOW_DRAFTS)));
Expand Down
13 changes: 13 additions & 0 deletions step/email/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="lifecyclestep_email_notified" COMMENT="table containing the userid and the courseid that was sent">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true" COMMENT="id of the process"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="course id"/>
<FIELD NAME="userid" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="id of the user"/>
<FIELD NAME="timemailsent" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="unix timestamp."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="courseid_fk" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" COMMENT="Foreign key on course table"/>
<KEY NAME="userid_fk" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
63 changes: 63 additions & 0 deletions step/email/db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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/>.

/**
* Update script for lifecyclestep_email plugin
*
* @package lifecyclestep_email
* @copyright 2024 Nina Herrmann University of Münster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Update script for lifecyclestep_email.
* @param int $oldversion Version id of the previously installed version.
* @return bool
* @throws ddl_exception
* @throws ddl_field_missing_exception
* @throws ddl_table_missing_exception
* @throws dml_exception
* @throws downgrade_exception
* @throws upgrade_exception
*/
function xmldb_lifecyclestep_email_upgrade($oldversion) {

global $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2024061301) {
$table = new xmldb_table('lifecyclestep_email_notified');

// Adding fields to table tool_lifecycle_proc_error.
$table->add_field('id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('timemailsent', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);

// Adding keys to table tool_lifecycle_proc_error.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$table->add_key('courseid_fk', XMLDB_KEY_FOREIGN, ['courseid'], 'course', ['id']);
$table->add_key('userid_fk', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);

// Conditionally launch create table for tool_lifecycle_proc_error.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

// Lifecycle savepoint reached.
upgrade_plugin_savepoint(true, 2024061301, 'tool', 'lifecycle');
}
return true;
}
14 changes: 12 additions & 2 deletions step/email/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,26 @@ public function post_processing_bulk_operation() {
['instanceid' => $step->id,
'touser' => $user->id, ]);

$parsedsettings = $this->replace_placeholders($settings, $user, $step->id, $mailentries);
$parsedsettings = $this->replace_placeholders($settings, $user, $step->id, $mailentries);

$subject = $parsedsettings['subject'];
$content = $parsedsettings['content'];
$contenthtml = $parsedsettings['contenthtml'];
// TODO: use course info to parse content template!
$success = email_to_user($user, \core_user::get_noreply_user(), $subject, $content, $contenthtml);
if (!$success) {
mtrace("E-mail to user {$user->id} failed.");
}
$dblogging = get_config('tool_lifecycle', 'logreceivedmails');
if ($dblogging && $success) {
// Insert user id and course id in table tool_lifecycle_user_notified.
$record = new \stdClass();
$record->userid = $user->id;
$record->timemailsent = time();
foreach ($mailentries as $entry) {
$record->courseid = $entry->courseid;
$DB->insert_record('lifecyclestep_email_notified', $record);
}
}
$DB->delete_records('lifecyclestep_email',
['instanceid' => $step->id,
'touser' => $user->id, ]);
Expand Down
2 changes: 1 addition & 1 deletion step/email/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2019070200;
$plugin->version = 2024061301;
$plugin->component = 'lifecyclestep_email';
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die;

$plugin->maturity = MATURITY_BETA;
$plugin->version = 2024042300;
$plugin->version = 2024061302;
$plugin->component = 'tool_lifecycle';
$plugin->requires = 2022112800; // Requires Moodle 4.1+.
$plugin->release = 'v4.4-r1';
Loading