The last notes
All English-language materials have been translated fully automatically using the Google service
If you are faced with the task of transferring users from one Bitrix to another, then it is quite simple to do this.
First, create a correspondence table of user groups, where the keys are the id of the user group on the first site, and the id values of the corresponding user group on the second. Something like this:
$ tableOfGroups = [
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 9,
'6' => 10,
'7' => 11,
];
Then you will need to manually add to the second site Add. fields (if any) with the same codes. Then place the exportUSERS.php
file on the first site, and importUSERS.php
on the second site and write down the appropriate paths.
Listing of file exportUSERS.php
require_once ($ _ SERVER ['DOCUMENT_ROOT']. '/ bitrix / modules / main / include / prolog_before.php');
// Get the list of users
$ rsUsers = CUser :: GetList ($ by = "", $ order = "", [], array ("SELECT" => array ("UF_ *")));
while ($ user = $ rsUsers-> Fetch ()) {
$ arUsers [$ user ['ID']] = $ user;
if ($ user ['PERSONAL_PHOTO']) {
$ arFileTmp = CFile :: ResizeImageGet (
$ user ['PERSONAL_PHOTO'],
array ("width" => 1000, "height" => 1000),
BX_RESIZE_IMAGE_PROPORTIONAL,
true
);
$ arUsers [$ user ['ID']] ['PERSONAL_PHOTO'] = 'http: //'. $ _SERVER ['SERVER_NAME']. $ arFileTmp ["src"];
}
$ userGroups = CUser :: GetUserGroup ($ user ['ID']);
$ arUsers [$ user ['ID']] ['A'] ['GROUPS'] = $ userGroups;
}
echo json_encode ($ arUsers);
die ();
require_once ($ _ SERVER ['DOCUMENT_ROOT']. '/ bitrix / modules / main / include / prolog_after.php');
Listing of the file importUSERS.php
require_once ($ _ SERVER ['DOCUMENT_ROOT']. '/ bitrix / modules / main / include / prolog_before.php');
$ arTotal = array ();
$ url = 'https://your_site.ru/exportUSERS.php';
$ postdata = array ();
$ post = http_build_query ($ postdata);
$ ch = curl_init ($ url);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ ch, CURLOPT_POST, 1);
curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post);
$ response = curl_exec ($ ch);
curl_close ($ ch);
// Convert std to array
$ response = json_decode ($ response, True);
$ arTotal ['Received users'] = count ($ response);
$ arTotal ['Entered'] = 0;
if (! CModule :: IncludeModule ("iblock")) {die ();}
$ tableOfGroups = [
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 9,
'6' => 10,
'7' => 11,
];
$ connection = Bitrix \ Main \ Application :: getConnection ('default');
$ sqlHelper = $ connection-> getSqlHelper ();
foreach ($ response as $ key => $ value) {
$ arFields = [];
foreach ($ value as $ k => $ v) {
switch ($ k) {
case 'PERSONAL_PHOTO':
if ($ v) {
$ arIMAGE = CFile :: MakeFileArray ($ value ['PERSONAL_PHOTO']);
$ arIMAGE ["MODULE_ID"] = "main";
$ arFields [$ k] = $ arIMAGE;
}
break;
case 'A':
$ groupIDS = [];
// According to the group correspondence table, set the required access levels
foreach ($ v ['GROUPS'] as $ name => $ val) {
array_push ($ groupIDS, $ tableOfGroups [$ val]);
}
$ arFields ['GROUP_ID'] = $ groupIDS;
break;
case 'LID':
break;
case 'IS_ONLINE':
break;
case 'PASSWORD':
break;
case 'CHECKWORD':
break;
default:
if ($ v) {
$ arFields [$ k] = $ v;
}
break;
}
}
$ arFields ['PASSWORD'] = 'blabla';
$ arFields ['CHECKWORD'] = 'blabla';
$ user = new CUser;
$ ID = $ user-> Add ($ arFields);
if (intval ($ ID)> 0) {
$ arTotal ['Entered'] + = 1;
$ connection-> queryExecute ("UPDATE b_user SET PASSWORD = '". $ sqlHelper-> forSql ($ value ["PASSWORD"]). "', CHECKWORD = '". $ sqlHelper-> forSql ($ value ["CHECKWORD" ]). "'WHERE ID ='". $ ID. "'");
} else {
$ arTotal ['Errors'] = $ arTotal [' Errors']. '
'. $ user-> LAST_ERROR;
}
}
Remember to run your importUSERS.php
file and wait for the import process to complete. After the import is complete, delete both files
The solution was applied on the Business v20.0.600 edition
Comments