summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ab934d9)
raw | patch | inline | side by side (parent: ab934d9)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 22 Jun 2006 06:15:33 +0000 (06:15 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 22 Jun 2006 06:15:33 +0000 (06:15 +0000) |
modify, keep not modified attributes.
overwrite, remove not listed attributes from object.
Fixed import function, to support dns with spaces arround ','
like ou=Test , ou=bla , this caused errors in create missing trees ..
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3861 594d385d-05f5-0310-b6e9-bd551577e9d8
overwrite, remove not listed attributes from object.
Fixed import function, to support dns with spaces arround ','
like ou=Test , ou=bla , this caused errors in create missing trees ..
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3861 594d385d-05f5-0310-b6e9-bd551577e9d8
include/class_ldap.inc | patch | blob | history | |
include/class_plugin.inc | patch | blob | history | |
plugins/addons/ldapmanager/contentimport.tpl | patch | blob | history |
diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index 494b1da9bdad8f4f10098dd5d68d2a7479fee269..d79ef172c56dbb7e9dcb41bb1e35e10a301b0f14 100644 (file)
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
- function import_complete_ldif($str_attr,&$error,$overwrite,$cleanup)
+ /* This funktion imports ldifs
+
+ If DeleteOldEntries is true, the destination entry will be deleted first.
+ If JustModify is true the destination entry will only be touched by the attributes specified in the ldif.
+ if JustMofify id false the destination dn will be overwritten by the new ldif.
+ */
+
+ function import_complete_ldif($str_attr,&$error,$JustModify,$DeleteOldEntries)
{
if($this->reconnect) $this->connect();
$cnt = 0;
$current_line = 0;
+ /* FIX ldif */
+ $last = "";
+ $tmp = "";
+ $i = 0;
+ foreach($entries as $entry){
+ if(preg_match("/^ /",$entry)){
+ $tmp[$i] .= trim($entry);
+ }else{
+ $i ++;
+ $tmp[$i] = trim($entry);
+ }
+ }
+
/* Every single line ... */
- foreach($entries as $entry) {
+ foreach($tmp as $entry) {
$current_line ++;
/* Removing Spaces to ..
/* Delete before insert */
$usermdir= false;
- /* The dn address already exists! */
- if (($this->dn_exists($value))&&((!$overwrite)&&(!$cleanup))) {
+ /* The dn address already exists, Don't delete destination entry, overwrite it */
+ if (($this->dn_exists($value))&&((!$JustModify)&&(!$DeleteOldEntries))) {
- $error= sprintf(_("The dn: '%s' (from line %s) already exists in the LDAP database."), $line, $current_line);
- return ALREADY_EXISTING_ENTRY;
+ $usermdir = $usemodify = false;
- } elseif(($this->dn_exists($value))&&($cleanup)){
+ /* Delete old entry first, then add new */
+ } elseif(($this->dn_exists($value))&&($DeleteOldEntries)){
/* Delete first, then add */
$usermdir = true;
- } elseif(($this->dn_exists($value))&&($overwrite)) {
+ } elseif(($this->dn_exists($value))&&($JustModify)) {
/* Modify instead of Add */
$usemodify = true;
}
- /* Imports a single entry */
+ /* Imports a single entry
+ If $delete is true; The old entry will be deleted if it exists.
+ if $modify is true; All variables that are not touched by the new ldif will be kept.
+ if $modify is false; The new ldif overwrites the old entry, and all untouched attributes get lost.
+ */
function import_single_entry($str_attr,$modify,$delete)
{
if($this->reconnect) $this->connect();
/* If dn is an index of data, we should try to insert the data */
if(isset($data['dn'])) {
+
+ /* Fix dn */
+ $tmp = ldap_explode_dn($data['dn'],0);
+ unset($tmp['count']);
+ $newdn ="";
+ foreach($tmp as $tm){
+ $newdn.= trim($tm).",";
+ }
+ $newdn = preg_replace("/,$/","",$newdn);
+ $data['dn'] = $newdn;
+
/* Creating Entry */
$this->cd($data['dn']);
if($delete){
$this->rmdir_recursive($data['dn']);
}
-
+
/* Create missing trees */
+ $this->cd ($this->basedn);
$this->create_missing_trees($data['dn']);
+ $this->cd($data['dn']);
+ $dn = $data['dn'];
unset($data['dn']);
- /* If entry exists use modify */
if(!$modify){
- $ret = $this->add($data);
+
+ $this->cat($dn);
+ if($this->count()){
+
+ /* The destination entry exists, overwrite it with the new entry */
+ $attrs = $this->fetch();
+ foreach($attrs as $name => $value ){
+ if(!is_numeric($name)){
+ if(in_array($name,array("dn","count"))) continue;
+ if(!isset($data[$name])){
+ $data[$name] = array();
+ }
+ }
+ }
+ $ret = $this->modify($data);
+
+ }else{
+
+ /* The destination entry doesn't exists, create it */
+ $ret = $this->add($data);
+ }
+
} else {
+
+ /* Keep all vars that aren't touched by this ldif */
$ret = $this->modify($data);
}
}
index f9cfa6aa4209aedf92aa7238be9cabe99719f574..23fa324cabd8b83b8e481602d16f12d0a4877965 100644 (file)
--- a/include/class_plugin.inc
+++ b/include/class_plugin.inc
$data = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
/* Import the given data */
- $ldap->import_complete_ldif($data,$err,true,true);
+ $ldap->import_complete_ldif($data,$err,false,false);
show_ldap_error($ldap_to->get_error().$err, _("Restore snapshot failed."));
}
diff --git a/plugins/addons/ldapmanager/contentimport.tpl b/plugins/addons/ldapmanager/contentimport.tpl
index 0e814fb289669c74b8fa344b0ff167082fb18437..b7d5afc8d6215da823feb9385cb90e8cb2fd6469 100644 (file)
</p>
<p class="seperator"> </p>
-<table summary="">
+<table summary="" width="100%">
<tr>
- <td width="30%">
+ <td width="180">
<LABEL for="userfile">{t}Import LDIF File{/t}</LABEL>
</td>
<td>
</td>
<td>
- <input type="checkbox" name="overwrite" value="1" id="overwrite">
- <LABEL for="overwrite">{t}Modify existing attributes{/t}</LABEL>
+<!-- <input type="checkbox" name="overwrite" value="1" id="overwrite">-->
+ <input type="radio" name="overwrite" value="1" checked>{t}Modify existing objects, keep untouched attributes{/t}<br>
+ <input type="radio" name="overwrite" value="0">{t}Overwrite existing objects, all not listed attributes will be removed{/t}
</td>
</tr>
<tr>
</td>
<td>
<input type="checkbox" name="cleanup" value="1" id="cleanup">
- <LABEL for="cleanup">{t}Overwrite existing entry{/t}</LABEL>
+ <LABEL for="cleanup">{t}Remove existing entries first{/t}</LABEL>
</td>
</tr>
</table>