Skip to content

Instantly share code, notes, and snippets.

@stefansl
Last active January 29, 2021 14:45
Show Gist options
  • Save stefansl/769da916af864f4428a1 to your computer and use it in GitHub Desktop.
Save stefansl/769da916af864f4428a1 to your computer and use it in GitHub Desktop.
Importscript frontend users Typo3 -> Contao. Will not work in every installation. Use it as help for your script
<html>
<head>
<title>member import - Typo3->Contao</title>
<meta charset="utf-8">
</head>
<body>
<?php
/*
* Config
*/
$defaultLanguage = 'de_DE';
$t3_usergroup = '3'; // the usergroups UID in Typo3
$oldDatabase = 'my_old_database';
$newDatabase = 'my_new_database';
define( 'TL_MODE', 'FE' );
require __DIR__ . '/system/initialize.php';
/*
* Importscript
*/
$oldDB = \Contao\Database::getInstance( array( 'dbDatabase' => $oldDatabase ) );
$newDB = \Contao\Database::getInstance( array( 'dbDatabase' => $newDatabase ) );
$memberGroupQuery = "SELECT * FROM fe_groups WHERE deleted=0";
$memberGroupResult = $oldDB->execute( $memberGroupQuery );
$memberGroups = $memberGroupResult->fetchAllAssoc();
//dump($memberGroups);
foreach ($memberGroups as $group) {
dump( $group['title'] );
$arrImportGroup = array(
'tstamp' => $group['tstamp'],
'name' => $group['title'],
'jumpTo' => 0
);
$importGroupSql = "INSERT INTO tl_member_group %s";
$importGroupResult = $newDB->prepare($importGroupSql)->set($arrImportGroup)->execute();
$importGroupId = $importGroupResult->insertId;
$memberQuery = "SELECT * FROM fe_users WHERE usergroup=%s AND deleted=0 AND usergroup='" . $t3_usergroup . "'";
$memberResult = $oldDB->prepare( $memberQuery )->execute( $group['uid'] );
$members = $memberResult->fetchAllAssoc();
//\Contao\MemberModel::setRow($arrData);
foreach ($members as $member) {
$serialzedGroup = serialize( array( (string) $importGroupId ) );
$hash = Encryption::hash( $member['password'] );
$language = (!empty($member['language'])) ? $member['language'] : $defaultLanguage;
$gender = ($member['gender'] == 0) ? 'male' : 'female';
if (str_word_count( $member['name'] ) == 2 && empty($member['first_name']) && empty($member['last_name'])) {
$arrName = explode( ' ', $member['name'] );
$member['first_name'] = $arrName[0];
$member['last_name'] = $arrName[1];
}
$member['last_name'] = (empty($member['last_name'])) ? $member['name'] : $member['last_name'];
$arrImportMember = array(
'tstamp' => $member['tstamp'],
'username' => $member['username'],
'password' => $hash,
'groups' => $serialzedGroup,
'disable' => ($member['disable'] != '0') ? $member['disable'] : '',
'login' => 1,
'start' => ($member['starttime'] != '0') ? $member['starttime'] : '',
'stop' => ($member['endtime'] != '0') ? $member['endtime'] : '',
//'customno' => $member['name'], // custom contao field
'street' => $member['address'],
'phone' => $member['telephone'],
'fax' => $member['fax'],
'email' => $member['email'],
'dateAdded' => $member['crdate'],
'postal' => $member['zip'],
'city' => $member['city'],
'country' => $member['country'],
'website' => $member['www'],
'company' => $member['company'],
'lastLogin' => ($member['lastlogin'] != '0') ? $member['lastlogin'] : '',
'currentLogin' => ($member['is_online'] != '0') ? $member['is_online'] : '',
'gender' => $gender,
'firstname' => $member['first_name'],
'lastname' => $member['last_name'],
'dateOfBirth' => ($member['date_of_birth'] != '0') ? $member['date_of_birth'] : '',
'language' => $language,
'loginCount' => 3,
'locked' => 0,
'createdOn' => 0,
);
$importMemberSql = "INSERT INTO tl_member %s";
$importMemberResult = $newDB->prepare($importMemberSql)->set($arrImportMember)->execute();
$importMemberId = $importMemberResult->insertId;
dump( $importMemberId );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment