-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* This plugin sends an email to a specified user after | ||
* it has detected a config setting was changed when | ||
* running cron. The to and from email addresses can | ||
* be changed in the settings page. | ||
* | ||
* @package local | ||
* @subpackage configlogemailer | ||
* @copyright 2013 Alex Rowe - Study Group | ||
* @author Alex Rowe [email protected] | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
$string['pluginname'] = 'Config Log Emailer'; | ||
$string['subject'] = 'There have been Moodle Site config changes'; | ||
$string['messagetext'] = 'Changes made on: {$a} | ||
Date | Name | Plugin | Setting | New Value | Old Value | ||
'; | ||
$string['to_email_title'] = 'Send to email'; | ||
$string['to_email_description'] = 'Who do you want to send the email to'; | ||
$string['to_email_default'] = '{$a}'; | ||
$string['from_email_title'] = 'Send from email'; | ||
$string['from_email_description'] = 'Who do you want to send the email from'; | ||
$string['from_email_default'] = '{$a}'; | ||
$string['from_firstname_title'] = 'Send from firstname'; | ||
$string['from_firstname_description'] = 'What is the first name of the sender'; | ||
$string['from_firstname_default'] = '{$a}'; | ||
$string['from_lastname_title'] = 'Send from lastname'; | ||
$string['from_lastname_description'] = 'What is the last name of the sender'; | ||
$string['from_lastname_default'] = '{$a}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* This plugin sends an email to a specified user after | ||
* it has detected a config setting was changed when | ||
* running cron. The to and from email addresses can | ||
* be changed in the settings page. | ||
* | ||
* @package local | ||
* @subpackage configlogemailer | ||
* @copyright 2013 Alex Rowe - Study Group | ||
* @author Alex Rowe [email protected] | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
function local_configlogemailer_cron() { | ||
global $CFG, $DB; | ||
|
||
// Create the from and to users | ||
$from = get_admin(); | ||
$to = get_admin(); | ||
// Overwrite the email address with the local plugin settings | ||
$to->email = get_config('local_configlogemailer','to_email'); | ||
// Check when the last cron was run, if it was the first time, then make it the current time | ||
$lastcron = get_config('local_configlogemailer','lastcron'); | ||
if (empty($lastcron)) { | ||
$lastcron = time(); | ||
} | ||
|
||
$from->email = get_config('local_configlogemailer','from_email'); | ||
$from->firstname = get_config('local_configlogemailer','from_firstname'); | ||
$from->lastname = get_config('local_configlogemailer','from_lastname'); | ||
|
||
$subject = get_string('subject', 'local_configlogemailer'); | ||
$messagetext = get_string('messagetext', 'local_configlogemailer',$CFG->wwwroot) | ||
|
||
$sql = "SELECT u.firstname, u.lastname, cl.timemodified, cl.plugin, cl.name, cl.value, cl.oldvalue | ||
FROM {config_log} cl | ||
JOIN {user} u ON u.id = cl.userid | ||
WHERE cl.timemodified >= $lastcron | ||
ORDER BY cl.timemodified DESC"; | ||
$rs = $DB->get_recordset_sql($sql); | ||
if ($rs->valid()) { | ||
foreach ($rs as $log) { | ||
$messagetext .= date('Y-m-d H:i:s', $log->timemodified) . ' | '; | ||
$messagetext .= $log->firstname . ' ' . $log->lastname . ' | '; | ||
if (is_null($log->plugin)) { | ||
$plugin = 'core'; | ||
} else { | ||
$plugin = $log->plugin; | ||
} | ||
$messagetext .= $plugin . ' | '; | ||
$messagetext .= $log->name . ' | '; | ||
$messagetext .= $log->value . ' | '; | ||
$messagetext .= $log->oldvalue . ' | ||
'; | ||
} | ||
$rs->close(); | ||
email_to_user($to, $from, $subject, $messagetext); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
moodle-local_configlogemailer | ||
|
||
Moodle local plugin to email config log updates | ||
|
||
This plugin sends an email to a specified user after | ||
it has detected a config setting was changed when | ||
running cron. The to and from email addresses can | ||
be changed in the settings page. | ||
|
||
@package local | ||
@subpackage configlogemailer | ||
@copyright 2013 Alex Rowe - Study Group | ||
@author Alex Rowe [email protected] | ||
@license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
|
||
Install into /local/ | ||
|
||
Version 1.0 (2013072200) | ||
|
||
Required Moodle 2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
defined('MOODLE_INTERNAL') || die; | ||
|
||
if ($hassiteconfig) { | ||
|
||
$from = get_admin(); | ||
|
||
$settings = new admin_settingpage('local_configlogemailer', 'Config Log Emailer'); | ||
$ADMIN->add('localplugins', $settings); | ||
|
||
$name = 'local_configlogemailer/to_email'; | ||
$title = get_string('to_email_title','local_configlogemailer'); | ||
$description = get_string('to_email_description','local_configlogemailer'); | ||
$default = get_string('to_email_default','local_configlogemailer'); | ||
$setting = new admin_setting_configtext($name, $title, $description, $default); | ||
$settings->add($setting); | ||
|
||
$name = 'local_configlogemailer/from_email'; | ||
$title = get_string('from_email_title','local_configlogemailer'); | ||
$description = get_string('from_email_description','local_configlogemailer'); | ||
$default = get_string('from_email_default','local_configlogemailer',$from->email); | ||
$setting = new admin_setting_configtext($name, $title, $description, $default); | ||
$settings->add($setting); | ||
|
||
$name = 'local_configlogemailer/from_firstname'; | ||
$title = get_string('from_firstname_title','local_configlogemailer'); | ||
$description = get_string('from_firstname_description','local_configlogemailer'); | ||
$default = get_string('from_firstname_default','local_configlogemailer',$from->firstname); | ||
$setting = new admin_setting_configtext($name, $title, $description, $default); | ||
$settings->add($setting); | ||
|
||
$name = 'local_configlogemailer/from_lastname'; | ||
$title = get_string('from_lastname_title','local_configlogemailer'); | ||
$description = get_string('from_lastname_description','local_configlogemailer'); | ||
$default = get_string('from_lastname_default','local_configlogemailer',$from->lastname); | ||
$setting = new admin_setting_configtext($name, $title, $description, $default); | ||
$settings->add($setting); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* This plugin sends an email to a specified user after | ||
* it has detected a config setting was changed when | ||
* running cron. The to and from email addresses can | ||
* be changed in the settings page. | ||
* | ||
* @package local | ||
* @subpackage configlogemailer | ||
* @copyright 2013 Alex Rowe - Study Group | ||
* @author Alex Rowe [email protected] | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
$plugin->version = 2013072200; // The (date) version of this plugin | ||
$plugin->requires = 2012120300; // Requires this Moodle version |