Working notification system
* Added things to mail templates * Modified user password reset call for new mail template * Added BASEPATH to smarty code to ensure templates are compiled in the proper directory * Updated mail and notification class * Updated notification cron * Added notification cron to run-cron list
This commit is contained in:
parent
4966f64a59
commit
432540335f
@ -30,23 +30,32 @@ if (empty($aWorkers)) {
|
||||
foreach ($aWorkers as $aWorker) {
|
||||
$aData = $aWorker;
|
||||
$aData['username'] = $user->getUserName($aWorker['account_id']);
|
||||
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
|
||||
$aData['email'] = $user->getUserEmail($aData['username']);
|
||||
if (!$notification->isNotified($aData)) {
|
||||
if (!$notification->addNotification('idle_worker', $aData) && $notification->sendMail('sebastian@grewe.ca', 'idle_worker', $aData))
|
||||
verbose("Unable to send notification: " . $notification->getError() . "\n");
|
||||
} else {
|
||||
verbose("Already notified for this worker\n");
|
||||
if ( $notification->isNotified($aData) ) {
|
||||
verbose("Worker already notified\n");
|
||||
continue;
|
||||
}
|
||||
if ($notification->addNotification('idle_worker', $aData) && $notification->sendMail($aData['email'], 'idle_worker', $aData)) {
|
||||
verbose ("Notified " . $aData['email'] . " for IDLE worker " . $aWorker['username'] . "\n");
|
||||
} else {
|
||||
verbose("Unable to send notification: " . $notification->getError() . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We notified, lets check which recovered
|
||||
$aNotifications = $notification->getAllActive();
|
||||
foreach ($aNotifications as $aNotification) {
|
||||
$aData = json_decode($aNotification['data'], true);
|
||||
$aWorker = $worker->getWorker($aData['id']);
|
||||
if ($aWorker['active'] == 1)
|
||||
if (!$notification->setInactive($aNotification['id']))
|
||||
if ($aWorker['active'] == 1) {
|
||||
if ($notification->setInactive($aNotification['id'])) {
|
||||
verbose("Marked notification " . $aNotification['id'] . " as inactive\n");
|
||||
} else {
|
||||
verbose("Failed to set notification inactive for " . $aWorker['username'] . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -16,7 +16,7 @@ PIDFILE='/tmp/mmcfe-ng-cron.pid'
|
||||
CRONHOME='.'
|
||||
|
||||
# List of cruns to execute
|
||||
CRONS="findblock.php proportional_payout.php blockupdate.php auto_payout.php tickerupdate.php"
|
||||
CRONS="findblock.php proportional_payout.php blockupdate.php auto_payout.php tickerupdate.php notifications.php"
|
||||
|
||||
# Additional arguments to pass to cronjobs
|
||||
CRONARGS="-v"
|
||||
|
||||
@ -19,7 +19,12 @@ class Mail {
|
||||
public function setConfig($config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
function checkStmt($bState) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($bState ===! true) {
|
||||
@ -30,8 +35,10 @@ class Mail {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendMail($email, $template, $vars) {
|
||||
public function sendMail($email, $template, $aData) {
|
||||
$this->smarty->assign('WEBSITENAME', $this->config['website']['name']);
|
||||
$this->smarty->assign('SUBJECT', $aData['subject']);
|
||||
$this->smarty->assign('DATA', $aData);
|
||||
$headers = 'From: Website Administration <' . $this->config['website']['email'] . ">\n";
|
||||
$headers .= "MIME-Version: 1.0\n";
|
||||
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
|
||||
|
||||
@ -41,6 +41,7 @@ class Notification extends Mail {
|
||||
return true;
|
||||
// Catchall
|
||||
// Does not seem to have a notification set
|
||||
$this->setErrorMessage("Unable to run query: " . $this->mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -486,6 +486,7 @@ class User {
|
||||
}
|
||||
$smarty->assign('TOKEN', $token);
|
||||
$smarty->assign('USERNAME', $username);
|
||||
$smarty->assign('SUBJECT', 'Password Reset Request');
|
||||
$smarty->assign('WEBSITENAME', $this->config['website']['name']);
|
||||
$headers = 'From: Website Administration <' . $this->config['website']['email'] . ">\n";
|
||||
$headers .= "MIME-Version: 1.0\n";
|
||||
|
||||
@ -16,10 +16,10 @@ $smarty = new Smarty;
|
||||
|
||||
// Assign our local paths
|
||||
$debug->append('Define Smarty Paths', 3);
|
||||
$smarty->template_dir = 'templates/' . THEME . '/';
|
||||
$smarty->compile_dir = 'templates/compile/';
|
||||
$smarty->template_dir = BASEPATH . 'templates/' . THEME . '/';
|
||||
$smarty->compile_dir = BASEPATH . 'templates/compile/';
|
||||
|
||||
// Optional smarty caching, check Smarty documentation for details
|
||||
$smarty->caching = $config['cache'];
|
||||
$smarty->cache_dir = "templates/cache";
|
||||
$smarty->cache_dir = BASEPATH . "templates/cache";
|
||||
?>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>One of your workers is currently IDLE.</p>
|
||||
<p>One of your workers is currently IDLE: {$DATA.username}</p>
|
||||
<p>Since monitoring is enabled for this worker, this notification was sent.</p>
|
||||
<p>Please check your workers!</p>
|
||||
<br/>
|
||||
|
||||
@ -1 +1 @@
|
||||
[ {$WEBSITENAME} ] Password Reset Request
|
||||
[ {$WEBSITENAME} ] {$SUBJECT}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user