Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit32743c8

Browse files
Kyle Evansfabpot
Kyle Evans
authored andcommitted
[Ldap] Entry move support
1 parentbff9e68 commit32743c8

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+
publicfunctionmove(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+
thrownewLdapException(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
thrownewUpdateOperationException(sprintf('Error executing UpdateOperation on "%s": "%s".',$dn,ldap_error($this->getConnectionResource())));
140156
}
141157
}
158+
159+
privatefunctionparseRdnFromEntry(Entry$entry)
160+
{
161+
if (!preg_match('/^([^,]+),/',$entry->getDn(),$matches)) {
162+
thrownewLdapException(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+
publicfunctiontestLdapMove()
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)

[8]ページ先頭

©2009-2025 Movatter.jp