- Fixes made after code upgrade on Ulmus
This commit is contained in:
parent
cb1528f34b
commit
bf115aeaf8
@ -4,7 +4,7 @@ namespace Ulmus\Ldap\Common;
|
||||
|
||||
use http\Exception\InvalidArgumentException;
|
||||
use LDAP\Result;
|
||||
use function ldap_set_option, ldap_start_tls, ldap_bind_ext, ldap_unbind, ldap_connect, ldap_close, ldap_get_entries, ldap_mod_replace, ldap_count_entries, ldap_errno, ldap_error;
|
||||
use function ldap_set_option, ldap_start_tls, ldap_bind_ext, ldap_unbind, ldap_connect, ldap_close, ldap_get_entries, ldap_delete_ext, ldap_count_entries, ldap_errno, ldap_error;
|
||||
|
||||
class LdapObject {
|
||||
|
||||
@ -193,7 +193,7 @@ class LdapObject {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function runAddQuery(array $filter, array $dataset)
|
||||
public function runAttributeAddQuery(array $filter, array $dataset)
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $filter, $dataset ]);
|
||||
|
||||
@ -208,6 +208,26 @@ class LdapObject {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function runAttributeDeleteQuery(array $filter, array $dataset)
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $filter ]);
|
||||
|
||||
if ( empty($filter['dn']) ) {
|
||||
throw new InvalidArgumentException("A valid DN must be provided to run a 'delete' query on LDAP connector");
|
||||
}
|
||||
|
||||
$this->lastQuery = ldap_mod_del_ext($this->connection, $filter['dn'], $dataset);
|
||||
|
||||
if ( $this->lastQuery === false ) {
|
||||
$this->throwLdapException();
|
||||
}
|
||||
|
||||
$this->rowCount = $this->lastQuery === false ? 0 : 1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function runUpdateQuery(array $filter, array $dataset)
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $filter, $dataset ]);
|
||||
|
||||
@ -21,7 +21,7 @@ class Repository extends \Ulmus\Repository
|
||||
|
||||
}
|
||||
|
||||
public function saveAdd(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool
|
||||
public function attributeAdd(object|array $entity, ? array $fieldsAndValue = null) : bool
|
||||
{
|
||||
if (is_array($entity)) {
|
||||
$entity = (new $this->entityClass())->fromArray($entity);
|
||||
@ -44,7 +44,42 @@ class Repository extends \Ulmus\Repository
|
||||
|
||||
$this->updateSqlQuery($diff)->finalizeQuery();
|
||||
|
||||
$ldapObject = $this->adapter->connector()->runAddQuery($this->queryBuilder->render(), array_merge($this->queryBuilder->values ?? [], $this->queryBuilder->parameters ?? []));
|
||||
$ldapObject = $this->adapter->connector()->runAttributeAddQuery($this->queryBuilder->render(), array_merge($this->queryBuilder->values ?? [], $this->queryBuilder->parameters ?? []));
|
||||
|
||||
$this->queryBuilder->reset();
|
||||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return $ldapObject ? (bool) $ldapObject->rowCount : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function attributeDelete(object|array $entity, ? array $fieldsAndValue = null) : bool
|
||||
{
|
||||
if (is_array($entity)) {
|
||||
$entity = (new $this->entityClass())->fromArray($entity);
|
||||
}
|
||||
|
||||
$dataset = $entity->toArray();
|
||||
|
||||
$primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField();
|
||||
|
||||
if ( $primaryKeyDefinition === null ) {
|
||||
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
||||
}
|
||||
|
||||
$diff = $fieldsAndValue ?? $this->generateWritableDataset($entity);
|
||||
|
||||
if ( [] !== $diff ) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
$pkFieldName = $primaryKeyDefinition[$pkField]->name ?? $pkField;
|
||||
$this->where($pkFieldName, $dataset[$pkFieldName]);
|
||||
|
||||
$this->updateSqlQuery($diff)->finalizeQuery();
|
||||
|
||||
$ldapObject = $this->adapter->connector()->runAttributeDeleteQuery($this->queryBuilder->render(), array_merge($this->queryBuilder->values ?? [], $this->queryBuilder->parameters ?? []));
|
||||
|
||||
$this->queryBuilder->reset();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user