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

[Ldap] UpdateOperation toArray() function throws exception when using LDAP_MODIFY_BATCH_REMOVE_ALL operation type #54829

Copy link
Copy link
Closed
@phasdev

Description

@phasdev
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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