Skip to content

Commit

Permalink
Use new methods for retrieving fresh DN after insertion / move / rename
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Nov 7, 2023
1 parent 35edd34 commit 3e2f26d
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ protected function performInsert(): void
// but filter out any empty attributes before sending them
// to the server. LDAP servers will throw an exception if
// attributes have been given empty or null values.
$query->insert($this->getDn(), array_filter($this->getAttributes()));
$this->dn = $query->insertAndGetDn($this->getDn(), array_filter($this->getAttributes()));

$this->dispatch('created');

Expand Down Expand Up @@ -1190,12 +1190,10 @@ public function rename(string $rdn, Model|string $newParentDn = null, bool $dele

$this->dispatch('renaming', [$rdn, $newParentDn]);

$this->newQuery()->rename($this->dn, $rdn, $newParentDn, $deleteOldRdn);

// If the model was successfully renamed, we will set
// its new DN so any further updates to the model
// can be performed without any issues.
$this->dn = implode(',', [$rdn, $newParentDn]);
$this->dn = $this->newQuery()->renameAndGetDn($this->dn, $rdn, $newParentDn, $deleteOldRdn);

$map = $this->newDn($this->dn)->assoc();

Expand Down Expand Up @@ -1226,15 +1224,9 @@ public function getUpdateableRdn(string $name): string
*/
public function getCreatableDn(string $name = null, string $attribute = null): string
{
$query = $this->newQuery();

if ($this->in) {
$query->in($this->in);
}

return implode(',', [
$this->getCreatableRdn($name, $attribute),
$query->getDn() ?? $query->getBaseDn(),
$this->in ?? $this->newQuery()->getbaseDn(),
]);
}

Expand Down

0 comments on commit 3e2f26d

Please sign in to comment.