2
I wrote a little script up to migrate all the data over. It's really rough (some things filled in by hand) and it relies on a temporary change to the core in order to run. It's possible that someone else might find it useful, so I'm including it here.
Create a file called LDAP_MapFields.php and place it in your root XOOPS directory. It should contain the following code:
include "mainfile.php";
include 'header.php';
include_once XOOPS_ROOT_PATH.'/class/auth/authfactory.php';
include_once XOOPS_ROOT_PATH.'/class/auth/auth_provisionning.php';
include_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/auth.php';
$member_handler =& xoops_gethandler('member');
$criteria = new Criteria('uid');
$members = $member_handler->getUsers($criteria);
$count = count($members);
$ldapConnection = ldap_connect("**directory.whatever.com**", '**389**') or die("Cound not connect");
$ldapBind = ldap_bind($ldapConnection);
echo "User Count: " . $count . "
";
$tab_mapping = explode('|', "**enter the value that you use in Site Preferences -> Authentication Options -> Field Mappings**");
$xoopsAuth =& XoopsAuthFactory::getAuthConnection('**I manually entered a user name (mine) here**');
$authProv = new XoopsAuthProvisionning($xoopsAuth);
foreach ($members as $member) {
$dn = "uid=" . $member->getVar('uname') . "** the rest of your base dn goes here**";
$sr = ldap_read($ldapConnection, $dn, '(objectclass=*)');
$entries = ldap_get_entries($ldapConnection, $sr);
foreach ($tab_mapping as $mapping) {
$fields = explode('=', trim($mapping));
if ($fields[0] && $fields[1]) {
echo "setVar(" . trim($fields[0]) . " for user " . $member->getVar("uname") . ": " . $entries["0"][trim($fields[1])]["0"] . ")
";
$member->setVar(trim($fields[0]), $entries["0"][trim($fields[1])]["0"]);
}
}
if ($member_handler->insertUser($member,true)) {
echo $member->getVar("uid") . "=good
";
} else {
echo $member->getVar("uid") . "=BAD
";
}
}
include 'footer.php';
?>
Look for code that contains ** and replace it with values appropriate to your web site.
Now the final trick. Edit kernel\user.php and comment out the lines that return from the function prematurely between lines 510 and 520:
function insert(&$user, $force = false)
{
if (strtolower(get_class($user)) != 'xoopsuser') {
//return false;
}
if (!$user->isDirty()) {
//return true;
}
if (!$user->cleanVars()) {
//return false;
}
foreach ($user->cleanVars as $k => $v) {
${$k} = $v;
}
Now run the LDAP_MapFields.php file from your browser. Once that's complete, remove the comments in user.php from above.
Your user fields for all users should now be filled with data from your LDAP directory without having to wait for everyone to log in again.