From 1503c586d28674423699c538944a2cf4335aee36 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 26 Jan 2018 10:30:29 -0500 Subject: [PATCH] When there is an error saving, add the invalidFields() info to the error message. Only restart the daemon on success. --- web/api/app/Controller/MonitorsController.php | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index c372463c1..de5a80d68 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -148,13 +148,26 @@ class MonitorsController extends AppController { throw new NotFoundException(__('Invalid monitor')); } if ($this->Session->Read('monitorPermission') != 'Edit') { - throw new UnauthorizedException(__('Insufficient privileges')); + throw new UnauthorizedException(__('Insufficient privileges')); return; } - if ($this->Monitor->save($this->request->data)) { - $message = 'Saved'; + + if ( $this->Monitor->save($this->request->data) ) { + $message .= 'Saved'; + $Monitor = $this->Monitor->find('first', array( + 'fields' => array('Function','ServerId'), + 'conditions' => array('Id' => $id) + ))['Monitor']; + + // - restart or stop this monitor after change + $func = $Monitor['Function']; + // We don't pass the request data as the monitor object because it may be a subset of the full monitor array + $this->daemonControl( $this->Monitor->id, 'stop' ); + if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID')) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) { + $this->daemonControl( $this->Monitor->id, 'start' ); + } } else { - $message = 'Error'; + $message .= 'Error ' . print_r($this->Monitor->invalidFields(), true); } $this->set(array( @@ -162,18 +175,6 @@ class MonitorsController extends AppController { '_serialize' => array('message') )); - $Monitor = $this->Monitor->find('first', array( - 'fields' => array('Function','ServerId'), - 'conditions' => array('Id' => $id) - ))['Monitor']; - - // - restart or stop this monitor after change - $func = $Monitor['Function']; - // We don't pass the request data as the monitor object because it may be a subset of the full monitor array - $this->daemonControl( $this->Monitor->id, 'stop' ); - if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID')) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) { - $this->daemonControl( $this->Monitor->id, 'start' ); - } } // end function edit /**