Commit 4d74c0b0 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols Committed by Richard Mansfield
Browse files

Keep track of sent mail count


Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent a0df66fe
......@@ -1282,6 +1282,13 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2009111200) {
$table = new XMLDBTable('artefact_internal_profile_email');
$field = new XMLDBField('mailssent');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
}
......
......@@ -396,12 +396,33 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='',
}
if ($mail->Send()) {
// Update the count of sent mail
update_send_count($userto);
return true;
}
throw new EmailException("Couldn't send email to $usertoname with subject $subject. "
. "Error from phpmailer was: " . $mail->ErrorInfo );
}
/**
* Update the send count for the specified e-mail address
*
* @param object $userto object to update count for. Must contain email and
* user id
* @param boolean reset Reset the sent mail count to 0 (optional).
*/
function update_send_count($userto, $reset=false) {
if (!$userto->id) {
// We need a user id to update the send count.
return false;
}
if ($mailinfo = get_record_select('artefact_internal_profile_email', 'owner = ? AND email = ? AND principal = 1', array($userto->id, $userto->email))) {
$mailinfo->mailssent = (!empty($reset)) ? 0 : $mailinfo->mailssent+1;
update_record('artefact_internal_profile_email', $mailinfo, array('email' => $userto->email, 'owner' => $userto->id));
}
}
/**
* converts a user object to a string representation of the user suitable for
* the current user (or specified user) to see
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009111001;
$config->version = 2009111200;
$config->release = '1.2.0rc2dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment