syncFieldFromLDAP.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
require_once('../../config/dmsDefaults.php');
require_once('Net/LDAP.php');
require_once(KT_LIB_DIR . '/metadata/metadatautil.inc.php');
$oKTConfig =& KTConfig::getSingleton();
$config = array(
'dn' => $oKTConfig->get("ldap/ldapSearchUser"),
'password' => $oKTConfig->get("ldap/ldapSearchPassword"),
'host' => $oKTConfig->get("ldap/ldapServer"),
'base' => $oKTConfig->get("ldap/ldapRootDn"),
);
$oFieldset =& KTFieldset::getByNamespace('http://ktcvs.local/local/fieldsets/synctest');
$oField = DocumentField::getByFieldsetAndName($oFieldset, 'synctest');
$oLdap =& Net_LDAP::connect($config);
if (PEAR::isError($oLdap)) {
var_dump($oLdap);
exit(0);
}
$aParams = array(
'scope' => 'sub',
'attributes' => array('cn'),
);
$rootDn = $oKTConfig->get("ldap/ldapRootDn");
if (is_array($rootDn)) {
$rootDn = join(",", $rootDn);
}
$aResults = $oLdap->search($rootDn, '(objectClass=organizationalPerson)', $aParams);
$aValues = array();
foreach ($aResults->entries() as $oEntry) {
// print $oEntry->dn() . "\n";
$sValue = $oEntry->get_value('cn', 'single');
// print $sValue . "\n";
$aValues[] = $sValue;
}
KTMetadataUtil::synchroniseMetadata($oField, $aValues);