Closed
Description
Symfony version(s) affected
7.0.7
Description
Performing a batch operation using the LDAP_MODIFY_BATCH_REMOVE_ALL
operation type produces an exception: ldap_modify_batch(): If option modtype" is LDAP_MODIFY_BATCH_REMOVE_ALL, option "values" cannot be provided
How to reproduce
Apply a batch update operation with an LDAP_MODIFY_BATCH_REMOVE_ALL
operation type.
e.g. using the example code from https://symfony.com/doc/current/components/ldap.html ...
use Symfony\Component\Ldap\Adapter\ExtLdap\UpdateOperation;
use Symfony\Component\Ldap\Ldap;
$ldap = Ldap::create('ext_ldap', [
'host' => 'my-server',
'encryption' => 'ssl',
]);
$entryManager = $ldap->getEntryManager();
$entryManager->applyOperations('cn=Fabien Potencier,dc=symfony,dc=com', [
new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE_ALL , 'mail', NULL),
]);
Possible Solution
For LDAP_MODIFY_BATCH_REMOVE_ALL operations, omit the values
element from the toArray()
return value, i.e. update toArray
function:
public function toArray(): array
{
$op = [
'attrib' => $this->attribute,
'modtype' => $this->operationType,
];
if (\LDAP_MODIFY_BATCH_REMOVE_ALL !== $this->operationType) {
$op['values'] = $this->values;
}
return $op;
}
or (more concise/fewer changes):
public function toArray(): array
{
return [
'attrib' => $this->attribute,
'modtype' => $this->operationType,
...(\LDAP_MODIFY_BATCH_REMOVE_ALL !== $this->operationType ? ['values' => $this->values] : [])
];
}
Additional Context
No response