Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

Bug #18202 Adding attributes to a Fresh Entry saving and laterly updating fails
Submitted: 2011-01-19 00:47 UTC
From: arraintxo Assigned: beni
Status: Closed Package: Net_LDAP2 (version 2.0.10)
PHP Version: Irrelevant OS:
Roadmaps: 2.1.0    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 19 + 50 = ?

 
 [2011-01-19 00:47 UTC] arraintxo (Alayn Gortazar)
Description: ------------ If you create a fresh entry and add new attributes manually (add method), once you add the entry to the server, the manually created attributes are not replaceable. Looks like the "original" array on Net_LDAP2_Entry is not updated when entries are added to the server. Test script: --------------- $ldap = Net_LDAP2::connect($config); $data = array( 'objectClass' => 'inetOrgPerson', 'givenName' => 'foo', 'sn' => 'bar', ); $dn = 'uid=fbar,dc=example,dc=com'; $entry = Net_LDAP2_Entry::createFresh($dn, $data); $entry->add(array('cn' => 'Fu Bar')); $ldap->add($entry); $entry->replace(array('cn' => 'Foo Bar')); $result = $entry->update(); if (Net_LDAP2::isError($entry)) { echo $entry->getMessage(); } else { echo "allright Foo Bar" } Expected result: ---------------- "allright Foo Bar" Actual result: -------------- "Could not add new values to attribute cn: Type or value exists: LDAP_TYPE_OR_VALUE_EXISTS"

Comments

 [2011-01-19 14:16 UTC] beni (Benedikt Hallinger)
-Status: Open +Status: Assigned -Assigned To: +Assigned To: beni
Hello, thanks for your bug report, i will look at it. Regarding your test script i have questions: - You dont check the result of the ldap->add operation; does that go stright? - You fetch the result of the replace operation but then in the isError(), you test the entry, is that on purpose? A workaround would be to refetch the entry via $ldap->getEntry(), so you get a "clean" directory version of the entry, if that is possible in your situation.
 [2011-01-19 15:10 UTC] arraintxo (Alayn Gortazar)
Regarding to your questions: 1) Yes, the ldap->add operation works faultless 2) The script was wrong, I will correct it just know. I really chek the $result. About the workaround, is just what i'm doing right know, but seems a bit awkward and suboptimal to take the data again from LDAP... :(
 [2011-01-19 15:14 UTC] arraintxo (Alayn Gortazar)
Looks like I'm not able to change the code, so here it goes the "right" one: $ldap = Net_LDAP2::connect($config); $data = array( 'objectClass' => 'inetOrgPerson', 'givenName' => 'foo', 'sn' => 'bar', 'uid' => 'fbar', ); $dn = 'uid=fbar,dc=example,dc=com'; $entry = Net_LDAP2_Entry::createFresh($dn, $data); $entry->add(array('cn' => 'Fu Bar')); $ldap->add($entry); $entry->replace(array('cn' => 'Foo Bar')); $result = $entry->update(); if (Net_LDAP2::isError($result)) { echo $result->getMessage(); } else { echo "allright Foo Bar" }
 [2011-01-19 15:41 UTC] beni (Benedikt Hallinger)
Thank you. Yes, its called "workaround" for that reason ;) If you got time, it would be cool, if you would dig into Net_LDAPs code, maybe you find the problem and can provide a patch. Without looked at the code, i suppose that the problem may be a wrongly adjusted internal entry array at the end of the update() operation. Another place to look at is the replace() method, which may make a wrong check or wrong call to add().
 [2011-01-19 15:42 UTC] beni (Benedikt Hallinger)
-Roadmap Versions: +Roadmap Versions: 2.1.0
 [2011-01-19 17:04 UTC] arraintxo (Alayn Gortazar)
 [2011-01-19 17:06 UTC] arraintxo (Alayn Gortazar)
I made it work by checking in the "add" method if an Entry is a new entry and calling setAttributes if so. Patch uploaded
 [2011-01-19 18:19 UTC] beni (Benedikt Hallinger)
Wow, that was quick; thank you very much! I will check that patch and introduce it into the mainline fpr the next update, probably a patch release.
 [2011-01-19 18:20 UTC] beni (Benedikt Hallinger)
(note for myself: Also add unit test for this case)
 [2011-01-19 18:21 UTC] beni (Benedikt Hallinger)
-Status: Assigned +Status: Verified
 [2011-01-19 18:37 UTC] beni (Benedikt Hallinger)
Its in SVN rev. 307580.
 [2011-01-19 19:08 UTC] beni (Benedikt Hallinger)
-Status: Verified +Status: Closed
Fix is implemented, unit test present