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

Appearance settings

Commit 2d8eeb2

Browse filesBrowse files
committed
[LDAP] implemented LDAP entry rename for ExtLdap adapter
1 parent fda8832 commit 2d8eeb2
Copy full SHA for 2d8eeb2

File tree

4 files changed

+86
-1
lines changed
Filter options

4 files changed

+86
-1
lines changed

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,8 @@ Yaml
390390
the `!php/object` tag.
391391

392392
* Duplicate mapping keys lead to a `ParseException`.
393+
394+
Ldap
395+
--------------
396+
397+
* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Ldap\Adapter\ExtLdap;
1313

1414
use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
15+
use Symfony\Component\Ldap\Adapter\RenameEntryInterface;
1516
use Symfony\Component\Ldap\Entry;
1617
use Symfony\Component\Ldap\Exception\LdapException;
1718
use Symfony\Component\Ldap\Exception\NotBoundException;
@@ -20,7 +21,7 @@
2021
* @author Charles Sarrazin <charles@sarraz.in>
2122
* @author Bob van de Vijver <bobvandevijver@hotmail.com>
2223
*/
23-
class EntryManager implements EntryManagerInterface
24+
class EntryManager implements EntryManagerInterface, RenameEntryInterface
2425
{
2526
private $connection;
2627

@@ -67,6 +68,18 @@ public function remove(Entry $entry)
6768
}
6869
}
6970

71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public function rename(Entry $entry, $newRdn, $removeOldRdn = true)
75+
{
76+
$con = $this->getConnectionResource();
77+
78+
if (!@ldap_rename($con, $entry->getDn(), $newRdn, null, $removeOldRdn)) {
79+
throw new LdapException(sprintf('Could not rename entry "%s" to "%s": %s', $entry->getDn(), $newRdn, ldap_error($con)));
80+
}
81+
}
82+
7083
/**
7184
* Get the connection resource, but first check if the connection is bound.
7285
*/
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\Component\Ldap\Adapter;
4+
5+
use Symfony\Component\Ldap\Entry;
6+
7+
/**
8+
* @deprecated This interface will be deprecated in 4.0, and merged with `EntryManagerInterface`
9+
*
10+
* @author Kevin Schuurmans <kevin.schuurmans@freshheads.com>
11+
*/
12+
interface RenameEntryInterface
13+
{
14+
/**
15+
* Renames an entry on the Ldap server.
16+
*
17+
* @param Entry $entry
18+
* @param string $newRdn
19+
* @param bool $removeOldRdn
20+
*/
21+
public function rename(Entry $entry, $newRdn, $removeOldRdn = true);
22+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,49 @@ private function executeSearchQuery($expectedResults = 1)
147147

148148
return $results;
149149
}
150+
151+
/**
152+
* @group functional
153+
*/
154+
public function testLdapRename()
155+
{
156+
$result = $this->executeSearchQuery(1);
157+
158+
$entry = $result[0];
159+
160+
$entryManager = $this->adapter->getEntryManager();
161+
$entryManager->rename($entry, 'cn=Kevin');
162+
163+
$result = $this->executeSearchQuery(1);
164+
$renamedEntry = $result[0];
165+
$this->assertEquals($renamedEntry->getAttribute('cn')[0], 'Kevin');
166+
167+
$oldRdn = $entry->getAttribute('cn')[0];
168+
$entryManager->rename($renamedEntry, 'cn='.$oldRdn);
169+
$this->executeSearchQuery(1);
170+
}
171+
172+
/**
173+
* @group functional
174+
*/
175+
public function testLdapRenameWithoutRemovingOldRdn()
176+
{
177+
$result = $this->executeSearchQuery(1);
178+
179+
$entry = $result[0];
180+
181+
$entryManager = $this->adapter->getEntryManager();
182+
$entryManager->rename($entry, 'cn=Kevin', false);
183+
184+
$result = $this->executeSearchQuery(1);
185+
186+
$newEntry = $result[0];
187+
$originalCN = $entry->getAttribute('cn')[0];
188+
189+
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
190+
191+
$entryManager->rename($newEntry, 'cn='.$originalCN);
192+
193+
$this->executeSearchQuery(1);
194+
}
150195
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.