Skip to content

Commit 32743c8

Browse files
Kyle Evansfabpot
authored andcommitted
[Ldap] Entry move support
1 parent bff9e68 commit 32743c8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/Symfony/Component/Ldap/Adapter/EntryManagerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* @author Charles Sarrazin <charles@sarraz.in>
2222
* @author Bob van de Vijver <bobvandevijver@hotmail.com>
2323
* @author Kevin Schuurmans <kevin.schuurmans@freshheads.com>
24+
*
25+
* @method void move(Entry $entry, string $newParent) Moves an entry on the Ldap server
2426
*/
2527
interface EntryManagerInterface
2628
{

src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ public function rename(Entry $entry, $newRdn, $removeOldRdn = true)
110110
}
111111
}
112112

113+
/**
114+
* Moves an entry on the Ldap server.
115+
*
116+
* @throws NotBoundException if the connection has not been previously bound.
117+
* @throws LdapException if an error is thrown during the rename operation.
118+
*/
119+
public function move(Entry $entry, string $newParent)
120+
{
121+
$con = $this->getConnectionResource();
122+
$rdn = $this->parseRdnFromEntry($entry);
123+
// deleteOldRdn does not matter here, since the Rdn will not be changing in the move.
124+
if (!@ldap_rename($con, $entry->getDn(), $rdn, $newParent, true)) {
125+
throw new LdapException(sprintf('Could not move entry "%s" to "%s": %s.', $entry->getDn(), $newParent, ldap_error($con)));
126+
}
127+
}
128+
113129
/**
114130
* Get the connection resource, but first check if the connection is bound.
115131
*/
@@ -139,4 +155,13 @@ public function applyOperations(string $dn, iterable $operations): void
139155
throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": "%s".', $dn, ldap_error($this->getConnectionResource())));
140156
}
141157
}
158+
159+
private function parseRdnFromEntry(Entry $entry)
160+
{
161+
if (!preg_match('/^([^,]+),/', $entry->getDn(), $matches)) {
162+
throw new LdapException(sprintf('Entry "%s" malformed, could not parse RDN', $entry->getDn()));
163+
}
164+
165+
return $matches[1];
166+
}
142167
}

src/Symfony/Component/Ldap/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* added `EntryManager::move`, not implementing it is deprecated
8+
49
4.2.0
510
-----
611

src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,22 @@ public function testUpdateOperationsThrowsExceptionWhenAddedDuplicatedValue()
341341

342342
$entryManager->applyOperations($entry->getDn(), $duplicateIterator);
343343
}
344+
345+
/**
346+
* @group functional
347+
*/
348+
public function testLdapMove()
349+
{
350+
$result = $this->executeSearchQuery(1);
351+
352+
$entry = $result[0];
353+
$this->assertNotContains('ou=Ldap', $entry->getDn());
354+
355+
$entryManager = $this->adapter->getEntryManager();
356+
$entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com');
357+
358+
$result = $this->executeSearchQuery(1);
359+
$movedEntry = $result[0];
360+
$this->assertContains('ou=Ldap', $movedEntry->getDn());
361+
}
344362
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy