Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 7779a49

Browse files
author
Charles Marion
committed
ENH: Improved error notification process
1 parent 329af81 commit 7779a49

File tree

7 files changed

+39
-42
lines changed

7 files changed

+39
-42
lines changed

core/AppController.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function preDispatch()
5252
}
5353
Zend_Session::start();
5454
$user = new Zend_Session_Namespace('Auth_User');
55+
$modelLoad = new MIDAS_ModelLoader();
5556
if($user->Dao == null)
56-
{
57-
$modelLoad = new MIDAS_ModelLoader();
57+
{
5858
$userModel = $modelLoad->loadModel('User');
5959
$cookieData = $this->getRequest()->getCookie('midasUtil');
6060
if(!empty($cookieData))
@@ -70,19 +70,39 @@ public function preDispatch()
7070
}
7171
}
7272
}
73+
74+
if($fc->getRequest()->getControllerName() == 'browse')
75+
{
76+
session_write_close();
77+
}
7378
$this->userSession = $user;
7479
$this->view->recentItems = array();
7580
$this->view->showUploadedLink = false;
81+
$this->view->needUpgrade = false;
82+
$this->view->highNumberError = false;
7683
if($user->Dao != null && $user->Dao instanceof UserDao)
7784
{
78-
if($fc->getRequest()->getControllerName() != 'install' && $fc->getRequest()->getControllerName() != 'error' && $user->Dao->isAdmin() && $this->isUpgradeNeeded())
79-
{
80-
$this->view->needUpgrade = true;
81-
}
82-
else
83-
{
84-
$this->view->needUpgrade = false;
85+
if($fc->getRequest()->getControllerName() != 'install' && $fc->getRequest()->getControllerName() != 'error' && $user->Dao->isAdmin())
86+
{
87+
if($this->isUpgradeNeeded())
88+
{
89+
$this->view->needUpgrade = true;
90+
}
91+
$errorlogModel = $modelLoad->loadModel('Errorlog');
92+
$logs = $errorlogModel->getLog(date('c', strtotime("-24 hour")), date('c'), 'all', 'all');
93+
foreach($logs as $key => $l)
94+
{
95+
if($l->getPriority() == MIDAS_PRIORITY_INFO)
96+
{
97+
unset($logs[$key]);
98+
}
99+
}
100+
if(count($logs) > 5)
101+
{
102+
$this->view->highNumberError = true;
103+
}
85104
}
105+
86106

87107
if(!empty($user->uploaded))
88108
{

core/configs/application.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ application.lang=en
1313
smartoptimizer=1
1414
;Session lifetime (minute)
1515
session.lifetime=20
16-
;alert e-mail
17-
alert.email=charles.marion@kitware.com
18-
;E-mail admin
19-
alert.enable=1
2016
;Path to md5sum
2117
md5sum.path=
2218
;Password prefix

core/constant/error.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
define("MIDAS_PRIORITY_INFO", 6);
3+
define("MIDAS_PRIORITY_CRITICAL", 2);
4+
define("MIDAS_PRIORITY_WARNING", 4);
5+
?>

core/controllers/ErrorController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,5 @@ private function _applicationError()
111111
$this->view->message = nl2br($fullMessage);
112112
}
113113

114-
$this->Component->NotifyError->notify();
115114
}
116115
}

core/controllers/components/NotifyErrorComponent.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function fatalEror($logger, $mailer)
6969
echo $message;
7070
$this->_mailer = $mailer;
7171
$this->_environment = $environment;
72-
//$this->notify(true);
7372
break;
7473
default:
7574
$this->_server = $_SERVER;
@@ -248,31 +247,4 @@ public function getShortErrorMessage()
248247
return $message;
249248
}
250249

251-
/** Send an email*/
252-
public function notify($fatal = false)
253-
{
254-
if(!in_array($this->_environment, array('production')) && Zend_Registry::get('configGlobal')->alert->enable == '1')
255-
{
256-
return false;
257-
}
258-
259-
$this->_mailer->setFrom('do-not-reply@domain.com');
260-
$this->_mailer->setSubject("Exception on Application ".Zend_Registry::get('configGlobal')->application->name);
261-
if(!$fatal)
262-
{
263-
$this->_mailer->setBodyText($this->getFullErrorMessage());
264-
}
265-
$this->_mailer->addTo(Zend_Registry::get('configGlobal')->alert->email);
266-
$return = false;
267-
try
268-
{
269-
$return = $this->_mailer->send();
270-
}
271-
catch(Exception $e)
272-
{
273-
$this->getLogger()->crit($e->getMessage());
274-
}
275-
276-
return $return;
277-
}
278250
}

core/include.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
//include constant files
1111
include_once BASE_PATH.'/core/constant/global.php';
12+
include_once BASE_PATH.'/core/constant/error.php';
1213
include_once BASE_PATH.'/core/constant/datatype.php';
1314
include_once BASE_PATH.'/core/constant/community.php';
1415
include_once BASE_PATH.'/core/constant/group.php';

core/layouts/layout.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@
154154
{
155155
echo '<span style="color:red;">MIDAS need to be upgraded. <a href="'.$this->webroot.'/admin/#ui-tabs-1">Upgrade</a></span><br/><br/>';
156156
}
157+
if($this->highNumberError)
158+
{
159+
echo '<span style="color:red;">More thant 5 errors occured during the last 24 hours. <a href="'.$this->webroot.'/admin/#ui-tabs-2">Cherck the logs</a></span><br/><br/>';
160+
}
157161
?>
158162
<div class=SubWrapper">
159163

0 commit comments

Comments
 (0)