Update function action to use Monitor object

This commit is contained in:
Isaac Connor
2020-09-03 18:21:08 -04:00
parent 6f5acece66
commit 47971bb8f5

View File

@@ -31,20 +31,21 @@ if ( !canEdit('Monitors', $mid) ) {
}
if ( $action == 'function' ) {
$monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id=?', NULL, array($mid));
$monitor = new ZM\Monitor($mid);
if ( !$monitor ) {
ZM\Error("Monitor not found with Id=$mid");
return;
}
$newFunction = validStr($_REQUEST['newFunction']);
# Because we use a checkbox, it won't get passed in the request. So not being in _REQUEST means 0
$newEnabled = ( !isset($_REQUEST['newEnabled']) or $_REQUEST['newEnabled'] != '1' ) ? '0' : '1';
$oldFunction = $monitor['Function'];
$oldEnabled = $monitor['Enabled'];
$oldFunction = $monitor->Function();
$oldEnabled = $monitor->Enabled();
if ( $newFunction != $oldFunction || $newEnabled != $oldEnabled ) {
dbQuery('UPDATE Monitors SET `Function`=?, `Enabled`=? WHERE `Id`=?',
array($newFunction, $newEnabled, $mid));
$monitor->save(array('Function'=>$newFunction, 'Enabled'=>$newEnabled));
$monitor['Function'] = $newFunction;
$monitor['Enabled'] = $newEnabled;
if ( daemonCheck() && ($monitor['Type'] != 'WebSite') ) {
if ( daemonCheck() && ($monitor->Type() != 'WebSite') ) {
zmaControl($monitor, 'stop');
zmcControl($monitor, ($newFunction != 'None') ? 'restart' : 'stop');
if ( $newFunction != 'None' && $newFunction != 'NoDect' )