Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddf3489

Browse files
committed
bug #54839 Fix exception thrown during LDAP_MODIFY_BATCH_REMOVE_ALL batch operations (phasdev)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Fix exception thrown during `LDAP_MODIFY_BATCH_REMOVE_ALL` batch operations | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54829 | License | MIT Bugfix removes `values` array element for `LDAP_MODIFY_BATCH_REMOVE_ALL` operations. PHP throws an exception when this element is included. Testing this component is complicated by the fact that most tests are skipped unless there's a local LDAP server running. To create a test which demonstrated the issue and fix, I created a default GitHub Codespace and ran the attached shell commands. These commands install and configure a local OpenLDAP server. You'll probably need to do something similar to confirm the issue/fix. [setup-ldap-codespace.md](https://github.com/symfony/symfony/files/15208301/setup-ldap-codespace.md) Commits ------- 8ac1818 Fix exception thrown during `LDAP_MODIFY_BATCH_REMOVE_ALL` batch operations
2 parents ca66c1c + 8ac1818 commit ddf3489

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ public function __construct(int $operationType, string $attribute, ?array $value
4848

4949
public function toArray(): array
5050
{
51-
return [
51+
$op = [
5252
'attrib' => $this->attribute,
5353
'modtype' => $this->operationType,
54-
'values' => $this->values,
5554
];
55+
56+
if (\LDAP_MODIFY_BATCH_REMOVE_ALL !== $this->operationType) {
57+
$op['values'] = $this->values;
58+
}
59+
60+
return $op;
5661
}
5762
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ public function testLdapAddAttributeValuesError()
266266
$entryManager->addAttributeValues($entry, 'mail', $entry->getAttribute('mail'));
267267
}
268268

269+
public function testLdapApplyOperationsRemoveAll()
270+
{
271+
$entryManager = $this->adapter->getEntryManager();
272+
273+
$result = $this->executeSearchQuery(1);
274+
$entry = $result[0];
275+
276+
$entryManager->applyOperations($entry->getDn(), [new UpdateOperation(\LDAP_MODIFY_BATCH_REMOVE_ALL, 'mail', null)]);
277+
278+
$result = $this->executeSearchQuery(1);
279+
$entry = $result[0];
280+
281+
$this->assertNull($entry->getAttribute('mail'));
282+
283+
$entryManager->addAttributeValues($entry, 'mail', ['[email protected]', '[email protected]']);
284+
}
285+
269286
public function testLdapApplyOperationsRemoveAllWithArrayError()
270287
{
271288
$entryManager = $this->adapter->getEntryManager();

0 commit comments

Comments
 (0)