Answer the question
In order to leave comments, you need to log in
How to transfer user database from WordPress to 1C Bitrix?
Hello.
There is a task to transfer users from WordPress 3.9x to 1C Bitrix 15.0x standard.
In addition to users, nothing needs to be transferred.
So far, I noticed that information about users in WordPress is stored in two tables:
Wp_users - data about authorization, login, email, password are stored.
Wp_users_meta - additional data, first name, last name.
Is this correct or are there other tables that have information about users?
Bitrix users also have additional properties.
There is a b_users table in the Bitrix database, but standard values are stored there, such as login, email, pass.
How to connect it with additional properties?
Update #1:
Googled this so far:
promst59.ru/page/bitrix-struktura-bazy-dannyh-modu...
Update #2:
Google found out that WordPress does not store avatars in the database.
https://buddypress.org/support/topic/were-is-avata...
Avatars don't have a database entry. They live here:
/wp-content/uploads/avatars/[member_id]/[avatar file]
But there needs to be a thumb and a full-size, and you'll need to change the file names.
And they may need to be jpg.
For example:
4f5664228829d-bpthumb.jpg
4f5664228829dauto-bpfull.jpg
Answer the question
In order to leave comments, you need to log in
Finally I was able to import users from WordPress to Bitrix.
I've already written enough in updates to be able to write all the code myself.
But, just in case, I give my version with comments. It may come in handy:
1. We will import users through the standard Bitrix service "import users". Through it, you can import almost everything related to users:
Importing users via CSV
2. If you want to import a custom property, just specify the name of the column with an additional property, for example UF_USER_FIELD and the values in it, (if this is not a multiple property, about multiple ones below) .
If it's a picture (avatar), just specify the relative path to the picture in the PERSONAL_PHOTO column. The folder from which the pictures will be taken, specify in the admin panel when importing users: "Path to pictures relative to the root of the site".
Now to the specifics.
information about users in WordPress is stored in tables:
wp_users - login, password, email
wp_bp_xprofile_data - analogy with Bitrix user properties, values are stored
wp_bp_xprofile_fields - names of user properties
You need to link these tables in the request and create a CSV file.
Example:
// Подключение к БД вордпресса
$mysqli = new mysqli("localhost", "root", "", "wp") or die("Not connected");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "select
t_users.ID as `UF_OLD_USER_ID` /*Заранее создал поль
свойство с таким именем. Понадобится при импорте аватарок,
да и лучше сохранить старые ИД. На всякий случаи. */
, '1.jpg' as `PERSONAL_PHOTO`
, t_users.user_login as `LOGIN`
, t_users.user_pass as `PASSWORD`
, t_users.user_email as `EMAIL`
, t_users.user_registered as `DATE_REGISTER`
, SUBSTRING_INDEX(t_users.display_name, ' ', 1) as `NAME`
, SUBSTRING_INDEX(t_users.display_name, ' ', -1) as `LAST_NAME`
, max(CASE WHEN t2.name = 'Телефон'
THEN t1.value ELSE null END) as `PERSONAL_PHONE`
, max(CASE WHEN t2.name = 'Город'
THEN t1.value ELSE null END) as `PERSONAL_CITY`
, max(CASE WHEN t2.name = 'Адрес студии'
THEN t1.value ELSE null END) as `UF_ADDRESS`
, max(CASE WHEN t2.name = 'Сайт'
THEN t1.value ELSE null END) as `PERSONAL_WWW`
, max(CASE WHEN t2.name = 'Образ'
THEN t1.value ELSE null END) as `MASTER_SERVICE_1`
, max(CASE WHEN t2.name = 'Визажист'
THEN t1.value ELSE null END) as `MASTER_SERVICE_2`
FROM wp_bp_xprofile_data as t1
INNER JOIN wp_bp_xprofile_fields as t2
on t1.field_id = t2.id
INNER JOIN wp_users t_users
ON t_users.ID = t1.user_id
#where user_id = 3
group by t1.user_id
";
if( !$mysqli->query( $query ) )
{
printf("Error: %s\n<br />", $mysqli->error);
}
$create_q = "";
$res = $mysqli->query( $query);
$fp = fopen('file.csv', 'w+'); // Создание csv файла
while ( $row = $res->fetch_assoc())
{
// Некоторые значения хранятся в сериализированном виде. Преобразуем в массив.
$tmp1 = unserialize($row["MASTER_SERVICE_1"]) ? unserialize($row["MASTER_SERVICE_1"]) : array();
$tmp2 = unserialize($row["MASTER_SERVICE_2"]) ? unserialize($row["MASTER_SERVICE_2"]) : array();
// в Битриксе в сер виде хранятся значения множественных свойств.
$tmp = array_merge( $tmp1, $tmp2);
$pathName = "./uploads-portfolio/avatars/".$row["UF_OLD_USER_ID"]."/";
$entries = scandir( $pathName );
$pattern = "#[\w\d]*-bpfull\.(png|jpg)$#";
foreach($entries as $entry)
{
if ( preg_match($pattern, $entry))
{
$row["PERSONAL_PHOTO"] = "/".$row["UF_OLD_USER_ID"]."/".$entry;
}
}
$tmp = array_unique( $tmp );
// У меня UF_MASTER_SERVICE поль свойство множественного значения
$row["UF_MASTER_SERVICE"] = serialize($tmp);
fputcsv($fp, $row, ";", '"');
}
AddEventHandler("main", "OnAfterUserAdd", "__afterUserAdd");
function __afterUserAdd( $arParams )
{
if(defined("USER_IMPORT_EXECUTION_TIME"))
{
// Adding multiply property for imported User
// MY_MASTER_SERVICE - название колонки с множественным свойством
// RESULT - ИД только, что созданного пользователя
$mysqli = new mysqli("localhost", "root", "", "bitrix_db");
$sql = "UPDATE b_uts_user SET UF_MASTER_SERVICE = '"
.$arParams["MY_MASTER_SERVICE"]
."' WHERE VALUE_ID =".$arParams["RESULT"];
$result = $mysqli->query( $sql);
if( !$result )
{
echo $mysqli->error;
}
}
}
There is a description of how to do it here dev.1c-bitrix.ru/community/webdev/user/42405/blog/...
Or marketplace.1c-bitrix.ru/solutions/yenisite.migrator
A table with users from WP is added to the Bitrix database.
Further, either by hand directly into the database queries (joins / subqueries), or write a small script.
Express777 : what additional saints are we talking about? In my opinion, there are too many fields in b_user. Can you give an example?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question