- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/classes/general/hrxml.php
- Класс: CUserHRXMLImport
- Вызов: CUserHRXMLImport::ImportUser
private function ImportUser($arUser, &$counter)
{
static $USER_COUNTER = null;
$obUser = &$this->__user;
if (null == $USER_COUNTER)
{
$dbRes = $GLOBALS['DB']->Query('SELECT MAX(ID) M FROM b_user');
$ar = $dbRes->Fetch();
$USER_COUNTER = $ar['M'];
}
if (isset($arUser['ID']))
$CURRENT_USER = $arUser['ID'];
else
$CURRENT_USER = 0;
if ($CURRENT_USER > 0)
{
unset ($arUser['ID']);
foreach ($arUser as $key => $value)
{
if ($key !== 'ACTIVE' && $key !== 'XML_ID' && !in_array($key, $this->arParams['UPDATE_PROPERTIES']))
unset($arUser[$key]);
}
// update existing user
if ($res = $obUser->Update($CURRENT_USER, $arUser))
$counter[$arUser['ACTIVE'] == 'Y' ? 'UPD' : 'DEA']++;
}
else
{
// EMAIL, LOGIN and PASSWORD fields
$USER_COUNTER++;
$arUser['LOGIN'] = '';
if ($this->arParams['LDAP_ID_PROPERTY_XML_ID'] && $this->arParams['LDAP_SERVER'])
{
$arUser['LOGIN'] = $arUser[$this->CalcPropertyFieldName($this->arParams['LDAP_ID_PROPERTY_XML_ID'])];
if ($arUser['LOGIN'])
$arUser['EXTERNAL_AUTH_ID'] = 'LDAP#'.$this->arParams['LDAP_SERVER'];
}
if (!$arUser['LOGIN'] && $this->arParams['LOGIN_TEMPLATE'])
$arUser['LOGIN'] = str_replace('#', $USER_COUNTER, $this->arParams['LOGIN_TEMPLATE']);
if (!$arUser['LOGIN'])
$arUser['LOGIN'] = 'user_' . $USER_COUNTER;
if (!$arUser['EXTERNAL_AUTH_ID'])
{
if (!$arUser['PASSWORD'])
{
$arUser['PASSWORD'] = $arUser['CONFIRM_PASSWORD'] = RandString(
$this->arParams['PASSWORD_LENGTH'] ? $this->arParams['PASSWORD_LENGTH'] : 7
);
}
}
$bEmailExists = !empty($arUser['EMAIL']);
if (empty($arUser['EMAIL']))
{
if (!empty($this->arParams['DEFAULT_EMAIL']))
$arUser['EMAIL'] = $this->arParams['DEFAULT_EMAIL'];
else
$arUser['EMAIL'] = COption::GetOptionString('main', 'email_from', 'admin@'.$_SERVER['SERVER_NAME']);
if ($arUser['EMAIL'] && $this->arParams['UNIQUE_EMAIL'] != 'N')
$arUser['EMAIL'] = preg_replace('/@/', '_'.$USER_COUNTER.'@', $arUser['EMAIL'], 1);
}
$arUser['LID'] = $this->arParams['SITE_ID'];
// set user groups list to default from main module setting
if (is_array($this->arUserGroups))
$arUser['GROUP_ID'] = $this->arUserGroups;
// create new user
if ($CURRENT_USER = $obUser->Add($arUser))
{
$counter['ADD']++;
if ($this->arParams['EMAIL_NOTIFY'] == 'Y' || $this->arParams['EMAIL_NOTIFY'] == 'E' && $bEmailExists)
{
$arUser['ID'] = $CURRENT_USER;
$this->__user->SendUserInfo(
$CURRENT_USER,
$this->arParams['SITE_ID'],
'',
$this->arParams['EMAIL_NOTIFY_IMMEDIATELY'] == 'Y'
);
}
}
else
{
$CURRENT_USER = $obUser->LAST_ERROR;
$GLOBALS['APPLICATION']->ThrowException($CURRENT_USER);
}
if (!$res = ($CURRENT_USER > 0))
$USER_COUNTER--;
}
if (!$res)
{
$counter['ERR']++;
// $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/user.log', 'a');
// fwrite($fp, "==============================================================rn");
// fwrite($fp, $obUser->LAST_ERROR."rn");
// fwrite($fp, print_r($arUser, true));
// fwrite($fp, "==============================================================rn");
// fclose($fp);
}
return $CURRENT_USER;
}