Bitrix easy user transfer with passwords
Rus
Eng
Битрикс простой перенос пользователей с паролями

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

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number