UserSynchronizer
API reference › LDAP › UserSynchronizer
Reads explicitly mapped LDAP user attributes in batches and passes them to application-owned persistence.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a synchronizer restricted to the directory component’s registered read connections. | UserSynchronizer |
sync() | Upserts each row using the configured connection name and the directory’s stable user identifier. | UserSynchronizer |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(yii2\extensions\ldap\Directory $directory)Creates a synchronizer restricted to the directory component’s registered read connections.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | Directory |
sync()
Section titled “sync() ”public function sync(LdapRecord\Query\Model\Builder $query, array<non-empty-string, non-empty-string> $attributes, Closure(string, string, array<string, mixed>): void $upsert, int $pageSize = 500): intUpserts each row using the configured connection name and the directory’s stable user identifier.
Missing or unreadable attributes are passed as null and all available values retain their native model representation. No local users are deleted. If a read or upsert fails, earlier successful upserts are not rolled back.
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | LdapRecord\ | User query built on an explicitly named read connection. |
$attributes | array<non-empty-string, | Map of application field to LDAP attribute. |
$upsert | Closure(string, | Persists one user using the connection and GUID as the key. |
$pageSize | int | LDAP page size; the server must support paged results. |
Returns
int: Number of users passed successfully to the persistence callback.
Throws
yii\base\InvalidConfigException: if the mapping, query, or page size is invalid.DirectoryUnavailableException: if a result lacks a stable identifier or paging does not complete.LdapRecord\LdapRecordException: if LdapRecord cannot bind or query the directory. Upsert exceptions propagate unchanged.