diff --git a/html/class_passwordRecovery.inc b/html/class_passwordRecovery.inc index 30a0ab46cd92a61a636101b0222179b117abf979..46c52d9dd4131993358ade807d5b9e702baefcf6 100644 --- a/html/class_passwordRecovery.inc +++ b/html/class_passwordRecovery.inc @@ -590,14 +590,13 @@ class passwordRecovery extends standAlonePage { ); /* Is there any problem with entered passwords? */ - $error = $userTabs->check(); - if (!empty($error)) { - $this->message = $error; + $userTabs->save_object(); + $errors = $userTabs->save(); + if (!empty($errors)) { + $this->message = $errors; return; } - $userTabs->save_object(); - $userTabs->save(); fusiondirectory_log("User ".$this->uid." password has been changed"); /* Send the mail */ $mail_body = sprintf($this->mail2_body, $this->uid); diff --git a/include/class_logging.inc b/include/class_logging.inc index 1656b9ea70295ed4959e4bff6306cc90b2182e59..0b0906c4692a41ce884bd40646d351e32b0f1669 100644 --- a/include/class_logging.inc +++ b/include/class_logging.inc @@ -146,10 +146,8 @@ class logging { $baseObject->fdAuditAttributes = $entry['changes']; $baseObject->fdAuditResult = $entry['result']; $baseObject->base = $config->current['BASE']; - $message = $tabObject->check(); - if (count($message) == 0) { - $tabObject->save(); - } else { + $message = $tabObject->save(); + if (!empty($message)) { msg_dialog::displayChecks($message); } } diff --git a/include/class_management.inc b/include/class_management.inc index 9a1a45a146121f6b06c1cecde2f3f10334861735..abd99c11361f64fc82d6c5e11d859601d5a62bb8 100644 --- a/include/class_management.inc +++ b/include/class_management.inc @@ -773,12 +773,11 @@ class management { if ($this->tabObject instanceOf simpleTabs) { $this->tabObject->save_object(); - $msgs = $this->tabObject->check(); + $msgs = $this->tabObject->save(); if (count($msgs)) { msg_dialog::displayChecks($msgs); return; } else { - $this->tabObject->save(); @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Entry saved!'); $this->remove_lock(); $this->closeDialogs(); @@ -808,13 +807,12 @@ class management { if ($this->tabObject instanceOf simpleTabs) { $this->tabObject->save_object(); - $msgs = $this->tabObject->check(); + $msgs = $this->tabObject->save(); if (count($msgs)) { msg_dialog::displayChecks($msgs); return ""; } else { - $this->tabObject->save(); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, "Modifications applied!"); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, 'Modifications applied!'); $this->tabObject->re_init(); } } diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 92592bf3d863487a38760340419083979cbcd434..a071b77f6d3cdb8071fa9d9a11641b442ebf9834 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -355,7 +355,10 @@ class plugin } } } + } + function prepareNextCleanup() + { /* Update saved attributes and ensure that next cleanups will be successful too */ foreach ($this->attrs as $name => $value) { $this->saved_attributes[$name] = $value; diff --git a/include/functions.inc b/include/functions.inc index fc990519019bda4154ba39c5cc8623eda62bc097..5bbad2c0e108f690a14847c3426c137c25339b82 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2805,12 +2805,11 @@ function change_password ($dn, $password, $hash = "") $userTab->userPassword, $userTab->attributesAccess['userPassword']->isLocked() ); - $error = $userTabs->check(); + $userTabs->save_object(); + $error = $userTabs->save(); if (!empty($error)) { return $error; } - $userTabs->save_object(); - $userTabs->save(); return TRUE; } diff --git a/include/simpleplugin/class_simpleManagement.inc b/include/simpleplugin/class_simpleManagement.inc index aa77fb36fa5d805061fafe30063277ae85e3dbd6..fdd9565b6e7c6218eb55e1540d12d9281821b5e6 100644 --- a/include/simpleplugin/class_simpleManagement.inc +++ b/include/simpleplugin/class_simpleManagement.inc @@ -498,15 +498,14 @@ class simpleManagement extends management if ($cancel) { $msgs = array(); } else { - $msgs = $this->tabObject->check(); + $msgs = $this->tabObject->save(); } if (count($msgs)) { msg_dialog::displayChecks($msgs); return; } else { if (!$cancel) { - $this->tabObject->save(); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, "Template applied!"); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Template applied!'); } del_lock($this->dn); if (empty($this->dns)) { diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 23c13ff6b7cbc4b3b2de2cd742221d0511607d5b..9af36d81c1bf3c86f441693e5ca4bf07e1f1d19d 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -688,6 +688,7 @@ class simplePlugin extends plugin if (!empty($errors)) { return $errors; } + $this->prepareNextCleanup(); /* Post hooks and logging */ $this->post_save(); return; @@ -957,11 +958,10 @@ class simplePlugin extends plugin $info = ""; if (isset($_POST['edit_finish'])) { /* Perform checks */ - $message = $tabObject->check(); + $message = $tabObject->save(); /* No errors, save object */ if (count($message) == 0) { - $tabObject->save(); del_lock($entry_dn); session::un_set('edit'); diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc index ad6569241b4ef59beb57058493adfe9bbc19f9e3..0b0329c1261d7d1d7c9c82ba478f1cfbb05dccf7 100644 --- a/include/simpleplugin/class_simpleTabs.inc +++ b/include/simpleplugin/class_simpleTabs.inc @@ -332,7 +332,7 @@ class simpleTabs * * \param boolean $ignore_account false */ - function check() + protected function check() { global $config; $messages = array(); @@ -353,7 +353,7 @@ class simpleTabs $current_set = FALSE; /* Check all plugins */ - foreach ($this->by_object as $key => &$obj) { + foreach ($this->by_object as $key => $obj) { if (($obj->is_account || $obj->ignore_account) && (!$obj->is_template)) { @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key, "Checking"); @@ -373,7 +373,6 @@ class simpleTabs $obj->pl_notify = FALSE; } } - unset($obj); return $messages; } @@ -385,46 +384,62 @@ class simpleTabs */ function save() { + $messages = $this->check(); + if (!empty($messages)) { + return $messages; + } + $baseobject = $this->getBaseObject(); $new_dn = $baseobject->compute_dn(); @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $new_dn, "Saving"); + $errors = array(); + $iscreation = ($this->dn == 'new'); + /* Move ? */ if ($this->dn != $new_dn) { /* Write entry on new 'dn' */ - if ($this->dn != 'new') { + if ($creation) { + /* use the new one */ + $this->dn = $new_dn; + } else { if ($baseobject->move($this->dn, $new_dn)) { $this->dn = $new_dn; } else { - msg_dialog::display(_('Error'), sprintf(_('Move from "%s" to "%s" failed'), $this->dn, $new_dn), ERROR_DIALOG); + $errors[] = sprintf(_('Move from "%s" to "%s" failed'), $this->dn, $new_dn); } - } else { - /* use the new one */ - $this->dn = $new_dn; } } /* Save all plugins */ - foreach ($this->by_object as $key => &$obj) { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key, "Saving"); + $first = TRUE; + foreach ($this->by_object as $key => $obj) { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key, 'Saving'); $obj->dn = $this->dn; - if (!$obj instanceof plugin && !$obj instanceOf management) { - trigger_error("Something went wrong while saving ".$obj->dn.". Object class '".get_class($obj)."'."); + if (!($obj instanceof plugin) && !($obj instanceOf management)) { + trigger_error('Something went wrong while saving '.$obj->dn.'. Class "'.get_class($obj).'".'); } else { if ($obj->is_account || $obj->ignore_account) { - if ($obj->save() == 1) { - return 1; - } + $result = $obj->save(); } else { - $obj->remove_from_parent(); + $result = $obj->remove_from_parent(); } + if (!empty($result)) { + if ($creation && $first) + /* If the fail of main tab fails for a creation, cancel the save of other tabs */ + return $result; + } + $errors = array_merge($errors, $result); + } + } + if ($first) { + $first = FALSE; } } - unset($obj); - return 0; + return $errors; } /*! diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index 3847f75187add221b97107c543cbc85d501d3a5a..83c4253be40bac63e3266afde39b916637e7a69a 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -929,14 +929,11 @@ class Step_Migrate extends setupStep $_POST[$tabObject->current.'_posted'] = TRUE; $_POST['dialog_refresh'] = TRUE; $tabObject->save_object(); - $errors = $tabObject->check(); + $errors = $tabObject->save(); if (!empty($errors)) { - foreach ($errors as $error) { - msg_dialog::display(_('Error'), $error, ERROR_DIALOG); - } + msg_dialog::displayChecks($errors); return FALSE; } - $tabObject->save(); $admindn = $tabObject->dn; /* Assigning role */