Report more saving errors to ui

This commit is contained in:
Isaac Connor 2021-11-17 18:57:36 -05:00
parent a0666e777a
commit b1d881b118
1 changed files with 38 additions and 31 deletions

View File

@ -24,6 +24,8 @@ if ( !canEdit('Monitors') ) {
return;
}
global $error_message;
if ($action == 'save') {
$mid = 0;
if (!empty($_REQUEST['mid'])) {
@ -48,13 +50,16 @@ if ( $action == 'save' ) {
# For convenience
$newMonitor = $_REQUEST['newMonitor'];
ZM\Debug("newMonitor: ". print_r($newMonitor, true));
if (!$newMonitor['ManufacturerId'] and ($newMonitor['Manufacturer'] != '')) {
# Need to add a new Manufacturer entry
$newManufacturer = ZM\Manufacturer::find_one(array('Name'=>$newMonitor['Manufacturer']));
if (!$newManufacturer) {
$newManufacturer = new ZM\Manufacturer();
$newManufacturer->save(array('Name'=>$newMonitor['Manufacturer']));
if (!$newManufacturer->save(array('Name'=>$newMonitor['Manufacturer']))) {
$error_message .= "Error saving new Manufacturer: " . $newManufacturer->get_last_error().'</br>';
}
}
$newMonitor['ManufacturerId'] = $newManufacturer->Id();
}
@ -64,10 +69,12 @@ if ( $action == 'save' ) {
$newModel = ZM\Model::find_one(array('Name'=>$newMonitor['Model']));
if (!$newModel) {
$newModel = new ZM\Model();
$newModel->save(array(
if (!$newModel->save(array(
'Name'=>$newMonitor['Model'],
'ManufacturerId'=>$newMonitor['ManufacturerId']
));
))) {
$error_message .= "Error saving new Model: " . $newModel->get_last_error().'</br>';
}
}
$newMonitor['ModelId'] = $newModel->Id();
}
@ -110,7 +117,9 @@ if ( $action == 'save' ) {
}
}
ZM\Debug("newMonitor: ". print_r($newMonitor, true));
$changes = $monitor->changes($newMonitor);
ZM\Debug("Changes: ". print_r($changes, true));
$restart = false;
if (count($changes)) {
@ -130,7 +139,6 @@ if ( $action == 'save' ) {
$oldH = $monitor->Height();
if ($monitor->save($changes)) {
// Groups will be added below
if ( isset($changes['Name']) or isset($changes['StorageId']) ) {
// creating symlinks when symlink already exists reports errors, but is perfectly ok
@ -230,8 +238,7 @@ if ( $action == 'save' ) {
} // end if rotation or just size change
} // end if changes in width or height
} else {
global $error_message;
$error_message = dbError('unknown');
$error_message .= $monitor->get_last_error();
} // end if successful save
$restart = true;
} else { // new monitor