patch from Pavel
This commit is contained in:
parent
5a55856483
commit
207e7a443f
|
@ -507,29 +507,16 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get list of all applications for given extension and move it into new suffix.
|
function isMoveToNewSuffix(){
|
||||||
*
|
|
||||||
* @return array list of error messages
|
|
||||||
*/
|
|
||||||
function move_extention_to_new_suffix() {
|
|
||||||
$errors = array();
|
|
||||||
$orig_suffix = extractDNSuffix($this->getAccountContainer()->dn_orig);
|
$orig_suffix = extractDNSuffix($this->getAccountContainer()->dn_orig);
|
||||||
if (strcmp($orig_suffix, $this->getAccountContainer()->dnSuffix) != 0 && !$this->getAccountContainer()->isNewAccount){
|
if (strcmp($orig_suffix, $this->getAccountContainer()->dnSuffix) != 0 && !$this->getAccountContainer()->isNewAccount){
|
||||||
$is_rename_success = false;
|
return true;
|
||||||
for ($rowCounter = 0; $rowCounter < count($this->extensionRows); $rowCounter++) {
|
|
||||||
$row = $this->extensionRows[$rowCounter];
|
|
||||||
$oldDN = "cn=" . $row["cn"][0] . "," . $orig_suffix;
|
|
||||||
$newRDN = "cn=" . $row["cn"][0];
|
|
||||||
$is_rename_success = @ldap_rename($_SESSION['ldap']->server(), $oldDN, $newRDN, $this->getAccountContainer()->dnSuffix, true);
|
|
||||||
if (!$is_rename_success) {
|
|
||||||
$errors[] = array('ERROR', sprintf(_('Was unable to rename DN: %s.'), $this->dn_orig), ldap_error($_SESSION['ldap']->server()));
|
|
||||||
logNewMessage(LOG_ERR, 'Unable to rename ' . $oldDN . ' to ' . $newRDN . ',' . $this->getAccountContainer()->dnSuffix);
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if even one owner is set and false otherwise
|
* Return true if even one owner is set and false otherwise
|
||||||
|
@ -867,7 +854,24 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of all applications for given extension and move it into new suffix.
|
||||||
|
*
|
||||||
|
* @return array list of error messages
|
||||||
|
*/
|
||||||
|
function moveExtentionToNewSuffix($rowOrig) {
|
||||||
|
if ($this->isMoveToNewSuffix()) {
|
||||||
|
$orig_suffix = extractDNSuffix($this->getAccountContainer()->dn_orig);
|
||||||
|
$oldDN = "cn=" . $rowOrig["cn"][0] . "," . extractDNSuffix($this->getAccountContainer()->dn_orig);
|
||||||
|
$newRDN = "cn=" . $rowOrig["cn"][0];
|
||||||
|
$is_rename_success = false;
|
||||||
|
$is_rename_success = @ldap_rename($_SESSION['ldap']->server(), $oldDN, $newRDN, $this->getAccountContainer()->dnSuffix, true);
|
||||||
|
if (!$is_rename_success) {
|
||||||
|
$errors[] = array('ERROR', sprintf(_('Was unable to rename DN: %s.'), $this->getAccountContainer()->dn_orig), ldap_error($_SESSION['ldap']->server()));
|
||||||
|
logNewMessage(LOG_ERR, 'Unable to rename ' . $oldDN . ' to ' . $newRDN . ',' . $this->getAccountContainer()->dnSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of modifications which have to be made to the LDAP account.
|
* Returns a list of modifications which have to be made to the LDAP account.
|
||||||
|
@ -893,8 +897,6 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$this->extensionRows = $this->array_sort($this->extensionRows, 'astpriority');
|
$this->extensionRows = $this->array_sort($this->extensionRows, 'astpriority');
|
||||||
|
|
||||||
$moveErrors = $this->move_extention_to_new_suffix(); // move extension to new suffix if necessary
|
|
||||||
$errors = array_merge($errors, $moveErrors);
|
|
||||||
//Modify existent config roes if necessary
|
//Modify existent config roes if necessary
|
||||||
for ($rowCounter = 0; $rowCounter < count($this->extensionRowsOrig); $rowCounter++) {
|
for ($rowCounter = 0; $rowCounter < count($this->extensionRowsOrig); $rowCounter++) {
|
||||||
$rowOrig = $this->extensionRowsOrig[$rowCounter];
|
$rowOrig = $this->extensionRowsOrig[$rowCounter];
|
||||||
|
@ -909,6 +911,10 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
ldap_mod_add($_SESSION['ldap']->server(), "cn=" . $row["cn"][0] . "," . $this->getAccountContainer()->dnSuffix, $diffVals);
|
ldap_mod_add($_SESSION['ldap']->server(), "cn=" . $row["cn"][0] . "," . $this->getAccountContainer()->dnSuffix, $diffVals);
|
||||||
}
|
}
|
||||||
$diffValsSerialysed = array_diff(array_map("serialize", array_intersect_key($row, $rowOrig)), array_map("serialize", $rowOrig));
|
$diffValsSerialysed = array_diff(array_map("serialize", array_intersect_key($row, $rowOrig)), array_map("serialize", $rowOrig));
|
||||||
|
|
||||||
|
//if new suffix jast move old rows to the new suffix and go on
|
||||||
|
$this->moveExtentionToNewSuffix($rowOrig);
|
||||||
|
|
||||||
if (count($diffValsSerialysed) != 0) {
|
if (count($diffValsSerialysed) != 0) {
|
||||||
$diffVals = array_map("unserialize", $diffValsSerialysed);
|
$diffVals = array_map("unserialize", $diffValsSerialysed);
|
||||||
if($row["cn"][0] == $rowOrig["cn"][0]){
|
if($row["cn"][0] == $rowOrig["cn"][0]){
|
||||||
|
@ -916,12 +922,13 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
}else{
|
}else{
|
||||||
$origDN = "cn=" . $rowOrig["cn"][0] . "," . $this->getAccountContainer()->dnSuffix;
|
$origDN = "cn=" . $rowOrig["cn"][0] . "," . $this->getAccountContainer()->dnSuffix;
|
||||||
$newRDN = "cn=" . $row["cn"][0];
|
$newRDN = "cn=" . $row["cn"][0];
|
||||||
|
|
||||||
ldap_rename($_SESSION['ldap']->server(), $origDN, $newRDN, $this->getAccountContainer()->dnSuffix, true);
|
ldap_rename($_SESSION['ldap']->server(), $origDN, $newRDN, $this->getAccountContainer()->dnSuffix, true);
|
||||||
ldap_mod_replace($_SESSION['ldap']->server(), $newRDN . "," . $this->getAccountContainer()->dnSuffix, $diffVals);
|
ldap_mod_replace($_SESSION['ldap']->server(), $newRDN . "," . $this->getAccountContainer()->dnSuffix, $diffVals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ldap_delete($_SESSION['ldap']->server(), "cn=" . $rowOrig["cn"][0] . "," . $_SESSION['config']->get_Suffix('asteriskExtNewUI'));
|
ldap_delete($_SESSION['ldap']->server(), "cn=" . $rowOrig["cn"][0] . "," . extractDNSuffix($this->getAccountContainer()->dn_orig));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Add new config rows
|
//Add new config rows
|
||||||
|
@ -929,15 +936,11 @@ class asteriskExtensionNewUI extends baseModule {
|
||||||
$row = $this->extensionRows[$rowCounter];
|
$row = $this->extensionRows[$rowCounter];
|
||||||
ldap_add($_SESSION['ldap']->server(), "cn=" . $row["cn"][0] . "," . $this->getAccountContainer()->dnSuffix, $row);
|
ldap_add($_SESSION['ldap']->server(), "cn=" . $row["cn"][0] . "," . $this->getAccountContainer()->dnSuffix, $row);
|
||||||
}
|
}
|
||||||
//this is trick for Edit again button to work
|
|
||||||
if($this->getAccountContainer()->isNewAccount){
|
//a trick for Edit again to work
|
||||||
$this->getAccountContainer()->dn_orig = "cn=" . $this->extensionRows[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
$this->getAccountContainer()->dn_orig = "cn=" . $this->extensionRows[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
||||||
$this->getAccountContainer()->finalDN = "cn=" . $this->extensionRows[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
$this->getAccountContainer()->finalDN = "cn=" . $this->extensionRows[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
||||||
}else{
|
|
||||||
$this->getAccountContainer()->dn_orig = "cn=" . $this->extensionRowsOrig[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
|
||||||
$this->getAccountContainer()->finalDN = "cn=" . $this->extensionRowsOrig[0]['cn'][0] . "," . $this->getAccountContainer()->dnSuffix;
|
|
||||||
}
|
|
||||||
//print_r($this->getAccountContainer()->finalDN );
|
|
||||||
$retun_obj = $this->getAccountContainer()->save_module_attributes($this->orig, $this->orig);
|
$retun_obj = $this->getAccountContainer()->save_module_attributes($this->orig, $this->orig);
|
||||||
|
|
||||||
return $retun_obj;
|
return $retun_obj;
|
||||||
|
|
Loading…
Reference in New Issue