Commit 80a2774c authored by Côme Chilliet's avatar Côme Chilliet

🚑 fix(plugins): Adapt code to new simplePlugin::remove function

issue #5759
parent fd0276a9
......@@ -176,7 +176,7 @@ class argonautFuseConfig extends simpleService
if ($plugin->is_account) {
$errors = $plugin->save();
} else {
$errors = $plugin->remove_from_parent();
$errors = $plugin->remove(FALSE);
}
if (!empty($errors)) {
msg_dialog::displayChecks($errors);
......@@ -185,23 +185,24 @@ class argonautFuseConfig extends simpleService
unset($plugin);
}
function remove_from_parent()
function remove($fulldelete = FALSE)
{
$errors = array();
/* Remove objects */
foreach ($this->plugin as &$plugin) {
$plugin->dn = $this->dn;
$result = $plugin->remove_from_parent();
$result = $plugin->remove($fulldelete);
if (!empty($result)) {
$errors = array_merge($errors, $result);
}
}
unset($plugin);
$result = parent::remove_from_parent();
if (!empty($result)) {
$errors = array_merge($result, $errors);
if (!empty($errors)) {
return $errors;
}
return $errors;
return parent::remove($fulldelete);
}
}
?>
......@@ -405,10 +405,10 @@ class dhcpSystem extends simplePlugin
);
}
function remove_from_parent()
protected function ldap_remove()
{
if ($this->is_template) {
return parent::remove_from_parent();
return parent::ldap_remove();
} elseif (($this->dn != '') && ($this->dn != 'new')) {
/* Remove all records */
$this->attributesAccess['dhcpHosts']->setValue(array());
......
......@@ -220,18 +220,20 @@ class opsiClient extends simplePlugin
}
}
function remove_from_parent()
function remove($fulldelete = FALSE)
{
global $config;
if ($this->member_of_group && !$this->is_template) {
// If the winstation is member of an ogroup which has OPSI activated, we must update_or_insert information
// We have to call this in here because save won't be called as is_account is FALSE
$this->update_or_insert();
}
if (!$this->initially_was_account) {
return;
}
return parent::remove($fulldelete);
}
protected function ldap_remove()
{
global $config;
if (!$this->is_template) {
$macAddresses = array();
......@@ -261,7 +263,7 @@ class opsiClient extends simplePlugin
}
}
return parent::remove_from_parent();
return parent::ldap_remove();
}
public function server_changed ()
......
......@@ -450,7 +450,7 @@ class posixAccount extends simplePlugin
return $message;
}
function prepare_save()
protected function prepare_save()
{
global $config;
/* Fill gecos */
......@@ -637,7 +637,7 @@ class posixAccount extends simplePlugin
return $errors;
}
function ldap_save()
protected function ldap_save()
{
$errors = parent::ldap_save();
......@@ -687,31 +687,28 @@ class posixAccount extends simplePlugin
return $errors;
}
/* remove object from parent */
function remove_from_parent()
protected function ldap_remove()
{
global $config;
/* Cancel if there's nothing to do here */
if ((!$this->initially_was_account) || (!$this->acl_is_removeable())) {
return;
}
/* Remove and write to LDAP */
$errors = parent::remove_from_parent();
$errors = parent::ldap_remove();
if (!empty($errors)) {
return $errors;
}
/* Delete group only if cn is uid and there are no other members inside */
$ldap = $config->get_ldap_link();
$ldap->cd ($config->current['BASE']);
$ldap->search ('(&(objectClass=posixGroup)(gidNumber='.ldap_escape_f($this->gidNumber).')(cn='.ldap_escape_f($this->getUid()).'))', array('cn', 'memberUid'));
if ($ldap->count() != 0) {
$attrs = $ldap->fetch();
if ($attrs['cn'][0] == $this->getUid() && !isset($this->attrs['memberUid'])) {
$ldap->rmDir($attrs['dn']);
if (!$this->is_template) {
/* Delete group only if cn is uid and there are no other members inside */
$ldap = $config->get_ldap_link();
$ldap->cd ($config->current['BASE']);
$ldap->search ('(&(objectClass=posixGroup)(gidNumber='.ldap_escape_f($this->gidNumber).')(cn='.ldap_escape_f($this->getUid()).'))', array('cn', 'memberUid'));
if ($ldap->count() != 0) {
$attrs = $ldap->fetch();
if ($attrs['cn'][0] == $this->getUid() && !isset($this->attrs['memberUid'])) {
$ldap->rmDir($attrs['dn']);
}
}
}
return array();
}
/* Adapt from template, using 'dn' */
......
......@@ -119,7 +119,7 @@ class ppolicyAccount extends simplePlugin
}
}
function remove_from_parent()
function remove($fulldelete = FALSE)
{
/* ppolicy fields are not real fields, they can’t be removed through ldap_modify
* It’s not possible to remove ppolicy info from a user node anyway */
......
......@@ -135,10 +135,10 @@ class etablissement extends simplePlugin
$this->set_root = (($root_code !== FALSE) && ($root_code == $this->supannEtablissement));
}
function remove_from_parent()
protected function ldap_remove()
{
global $config;
$errors = parent::remove_from_parent();
$errors = parent::ldap_remove();
if (!empty($errors)) {
return $errors;
}
......@@ -152,6 +152,7 @@ class etablissement extends simplePlugin
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
}
}
return array();
}
function ldap_save()
......
......@@ -398,15 +398,15 @@ class ServerService extends simpleManagement
// save_object of the dialog is called in management::execute
}
/*! \brief Remove all active services
/*! \brief Remove all active services
*/
function remove_from_parent()
function remove($fulldelete = FALSE)
{
$errors = array();
foreach ($this->plugins as $name => $obj) {
$this->updateServicesVars($name);
if ($this->plugins[$name]->initially_was_account) {
$result = $this->plugins[$name]->remove_from_parent();
$result = $this->plugins[$name]->remove($fulldelete);
if (!empty($result)) {
$errors = array_merge($errors, $result);
}
......@@ -426,7 +426,7 @@ class ServerService extends simpleManagement
if ($this->plugins[$name]->is_account) {
$result = $this->plugins[$name]->save();
} elseif ($this->plugins[$name]->initially_was_account) {
$result = $this->plugins[$name]->remove_from_parent();
$result = $this->plugins[$name]->remove(FALSE);
}
if (!empty($result)) {
$errors = array_merge($errors, $result);
......
......@@ -112,23 +112,15 @@ class workstationGeneric extends ipHostPlugin
$this->attributesAccess['cn']->setUnique(TRUE);
}
function remove_from_parent()
protected function post_remove()
{
if (!$this->initially_was_account) {
return;
/* Clean queue form entries with this mac */
if (class_available('supportDaemon') && tests::is_mac($this->attributesAccess['macAddress']->getInitialValue())) {
$q = new supportDaemon();
$q->clean_queue_from_mac($this->attributesAccess['macAddress']->getInitialValue());
}
if ($this->acl_is_removeable()) {
$errors = parent::remove_from_parent();
/* Clean queue form entries with this mac */
if (class_available('supportDaemon') && tests::is_mac($this->attributesAccess['macAddress']->getInitialValue())) {
$q = new supportDaemon();
$q->clean_queue_from_mac($this->attributesAccess['macAddress']->getInitialValue());
}
return $errors;
}
return parent::post_remove();
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment