Fix Zone add api. Restart zmc when adding a zone. Use validation. Fixes #2983

This commit is contained in:
Isaac Connor 2020-07-20 16:24:49 -04:00
parent bbee6b4f58
commit 955fc00b87
1 changed files with 34 additions and 13 deletions

View File

@ -40,6 +40,7 @@ class ZonesController extends AppController {
'_serialize' => array('zones')
));
}
public function index() {
$this->Zone->recursive = -1;
@ -63,7 +64,11 @@ class ZonesController extends AppController {
* @return void
*/
public function add() {
if ( $this->request->is('post') ) {
if ( !$this->request->is('post') ) {
throw new BadRequestException(__('Invalid method. Should be post'));
return;
}
global $user;
$canEdit = (!$user) || $user['Monitors'] == 'Edit';
@ -72,14 +77,30 @@ class ZonesController extends AppController {
return;
}
$zone = null;
$this->Zone->create();
if ( $this->Zone->save($this->request->data) ) {
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
$zone = $this->Zone->save($this->request->data);
if ( $zone ) {
require_once __DIR__ .'/../../../includes/Monitor.php';
$monitor = new ZM\Monitor($zone['Zone']['MonitorId']);
$monitor->zmaControl('restart');
$message = 'Saved';
//$zone = $this->Zone->find('first', array('conditions' => array( array('Zone.' . $this->Zone->primaryKey => $this->Zone),
} else {
$message = 'Error: ';
// if there is a validation message, use it
if ( !$this->Zone->validates() ) {
$message = $this->Zone->validationErrors;
}
}
$monitors = $this->Zone->Monitor->find('list');
$this->set(compact('monitors'));
}
$this->set(array(
'message' => $message,
'zone' => $zone,
'_serialize' => array('message','zone')
));
} // end function add()
/**
* edit method