diff --git a/classes/task/lifecycle_cleanup_task.php b/classes/task/lifecycle_cleanup_task.php
index 19455eaf..09a96e61 100644
--- a/classes/task/lifecycle_cleanup_task.php
+++ b/classes/task/lifecycle_cleanup_task.php
@@ -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]);
}
}
diff --git a/lang/de/tool_lifecycle.php b/lang/de/tool_lifecycle.php
index a92d11a1..68a88d3f 100644
--- a/lang/de/tool_lifecycle.php
+++ b/lang/de/tool_lifecycle.php
@@ -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
diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php
index 1d96728d..5718b20e 100644
--- a/lang/en/tool_lifecycle.php
+++ b/lang/en/tool_lifecycle.php
@@ -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
diff --git a/settings.php b/settings.php
index 3f37c086..90f7529d 100644
--- a/settings.php
+++ b/settings.php
@@ -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)));
diff --git a/step/email/db/install.xml b/step/email/db/install.xml
index 1620fde5..a46bb088 100644
--- a/step/email/db/install.xml
+++ b/step/email/db/install.xml
@@ -14,5 +14,18 @@
+
\ No newline at end of file
diff --git a/step/email/db/upgrade.php b/step/email/db/upgrade.php
new file mode 100644
index 00000000..e0821610
--- /dev/null
+++ b/step/email/db/upgrade.php
@@ -0,0 +1,63 @@
+.
+
+/**
+ * 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;
+}
diff --git a/step/email/lib.php b/step/email/lib.php
index 4635aed8..06c29744 100644
--- a/step/email/lib.php
+++ b/step/email/lib.php
@@ -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, ]);
diff --git a/step/email/version.php b/step/email/version.php
index 5b8d20f3..3bf08cd3 100644
--- a/step/email/version.php
+++ b/step/email/version.php
@@ -24,5 +24,5 @@
defined('MOODLE_INTERNAL') || die;
-$plugin->version = 2019070200;
+$plugin->version = 2024061301;
$plugin->component = 'lifecyclestep_email';
diff --git a/version.php b/version.php
index e8f6b54a..860e8349 100644
--- a/version.php
+++ b/version.php
@@ -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';