mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Import tweaks
This commit is contained in:
parent
750ac914a2
commit
c56a7f9a67
@ -177,6 +177,11 @@ class import_main_ui extends e_admin_ui
|
||||
$this->checked_class_list = implode(',',$_POST['classes_select']);
|
||||
}
|
||||
|
||||
if(vartrue($_POST['createUserExtended'])) //TODO
|
||||
{
|
||||
$this->createUserExtended = true;
|
||||
}
|
||||
|
||||
if($_POST['selectedTables'])
|
||||
{
|
||||
$this->selectedTables = $_POST['selectedTables'];
|
||||
@ -493,28 +498,41 @@ class import_main_ui extends e_admin_ui
|
||||
$text .= "
|
||||
<tr>
|
||||
<td >$importType ".LAN_CONVERT_24."</td>
|
||||
<td >";
|
||||
<td>";
|
||||
|
||||
$defCheck = (count($proObj->supported)==1) ? true : false;
|
||||
foreach ($this->importTables as $k => $v)
|
||||
{
|
||||
if(in_array($k, $proObj->supported)) // display only the options supported.
|
||||
{
|
||||
$text .= $frm->checkbox('selectedTables['.$k.']', $k, $defCheck)." ".$v['message'];
|
||||
$text .= $frm->checkbox('selectedTables['.$k.']', $k, $defCheck,array('label'=>$v['message']));
|
||||
|
||||
|
||||
//$text .= "<input type='checkbox' name='import_block_{$k}' id='import_block_{$k}' value='1' {$defCheck} /> ".$v['message'];
|
||||
$text .= "<br />";
|
||||
// $text .= "<br />";
|
||||
}
|
||||
}
|
||||
$text .= "</td></tr>";
|
||||
}
|
||||
|
||||
|
||||
$text .= "<tr><td>".LAN_CONVERT_38."</td>
|
||||
<td><input type='checkbox' name='import_delete_existing_data' value='1'".(varset($_POST['import_delete_existing_data']) ? " checked='checked'" : '')."/>
|
||||
<span class='smallblacktext'>".LAN_CONVERT_39."</span></td>
|
||||
</tr>";
|
||||
$text .= "
|
||||
<tr>
|
||||
<td>".LAN_CONVERT_38."</td>
|
||||
<td>".$frm->checkbox('import_delete_existing_data', 1,$_POST['import_delete_existing_data'], array('label'=>' ','title'=>LAN_CONVERT_39))."</td>
|
||||
</tr>";
|
||||
|
||||
//TODO
|
||||
/*
|
||||
if(in_array('users',$proObj->supported))
|
||||
{
|
||||
$text .= "<tr>
|
||||
<td>Create Extended User Fields</td>
|
||||
<td>".$frm->checkbox('createUserExtended', 1,'', array('label'=>' ','title'=>'Will automatically add missing user-fields when found.'))."
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
*/
|
||||
|
||||
if(varset($proObj->defaultClass) !== false)
|
||||
{
|
||||
@ -669,7 +687,7 @@ class import_main_ui extends e_admin_ui
|
||||
// break;
|
||||
}
|
||||
|
||||
if ($this->deleteExisting)
|
||||
if ($this->deleteExisting == true)
|
||||
{
|
||||
$exporter->emptyTargetDB(); // Clean output DB - reasonably safe now
|
||||
}
|
||||
@ -709,93 +727,6 @@ class import_main_ui extends e_admin_ui
|
||||
|
||||
return true;
|
||||
|
||||
/// - old BELOW ----------------------------------------
|
||||
|
||||
/*
|
||||
foreach ($this->importTables as $k => $v)
|
||||
{
|
||||
if (isset($this->selectedTables[$k]))
|
||||
{
|
||||
$loopCounter = 0;
|
||||
$errorCounter = 0;
|
||||
|
||||
if (is_readable($v['classfile']))
|
||||
{
|
||||
require_once($v['classfile']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mes->addError(LAN_CONVERT_45.': '.$v['classfile']); // can't read class file.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (varset($_POST["import_block_{$k}"],0) == 1)
|
||||
{
|
||||
//if (IMPORT_DEBUG) echo "Importing: {$k}<br />";
|
||||
$mes->addDebug("Importing: ".$k);
|
||||
|
||||
$result = $converter->setupQuery($k,!$this->deleteExisting);
|
||||
|
||||
if ($result !== TRUE)
|
||||
{
|
||||
$mes->addError(LAN_CONVERT_44.' '.$k); // couldn't set query
|
||||
// $msg .= "Prefix = ".$converter->DBPrefix;
|
||||
break;
|
||||
}
|
||||
|
||||
$exporter = new $v['classname']; // Writes the output data
|
||||
|
||||
switch ($k) // Do any type-specific default setting
|
||||
{
|
||||
case 'users' :
|
||||
$exporter->overrideDefault('user_class',$checked_class_list);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->deleteExisting)
|
||||
{
|
||||
$exporter->emptyTargetDB(); // Clean output DB - reasonably safe now
|
||||
}
|
||||
|
||||
while ($row = $converter->getNext($exporter->getDefaults(),$mode))
|
||||
{
|
||||
$loopCounter++;
|
||||
$result = $exporter->saveData($row);
|
||||
if ($result !== TRUE)
|
||||
{
|
||||
$errorCounter++;
|
||||
$line_error = $exporter->getErrorText($result);
|
||||
// if ($msg) $msg .= "<br />";
|
||||
$msg = str_replace(array('--ERRNUM--','--DB--'),array($line_error,$k),LAN_CONVERT_46).$loopCounter;
|
||||
$mes->addError($msg); // couldn't set query
|
||||
}
|
||||
}
|
||||
|
||||
$converter->endQuery();
|
||||
|
||||
unset($exporter);
|
||||
|
||||
|
||||
$msg = str_replace(array('--LINES--','--USERS--', '--ERRORS--','--BLOCK--'),
|
||||
array($loopCounter,$loopCounter-$errorCounter,$errorCounter, $k),LAN_CONVERT_47);
|
||||
$mes->addSuccess($msg); // couldn't set query
|
||||
}
|
||||
else
|
||||
{
|
||||
$mes->addDebug("Error: _POST['import_block_{$k}'] = ".$_POST['import_block_{$k}']); // cou
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mes->addDebug("\$this->selectedTables doesn't contain key: ".$k); // cou
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// $msg = LAN_CONVERT_29;
|
||||
return true;
|
||||
// $abandon = FALSE;
|
||||
}
|
||||
|
||||
@ -842,7 +773,7 @@ class import_main_ui extends e_admin_ui
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// Source DB types (i.e. CMS types) supported. Key of each element is the 'short code' for the type
|
||||
$import_class_names = array(); // Title
|
||||
@ -1076,7 +1007,7 @@ if(isset($_POST['do_conversion']))
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
|
||||
function rssImport()
|
||||
|
@ -308,4 +308,4 @@ class base_import_class
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
@ -36,28 +36,34 @@ class user_import
|
||||
|
||||
// Every field must be in exactly one of the arrays $userDefaults, $userSpecial, $userMandatory
|
||||
var $userDefaults = array(
|
||||
'user_id' => 0,
|
||||
'user_customtitle' => '',
|
||||
'user_sess' => '', // Photo
|
||||
'user_email' => '',
|
||||
'user_signature' => '',
|
||||
'user_image' => '', // Avatar
|
||||
'user_hideemail' => 1,
|
||||
'user_lastvisit' => 0,
|
||||
'user_id' => 0,
|
||||
'user_name' => '',
|
||||
'user_loginname' => '',
|
||||
'user_password' => '',
|
||||
'user_customtitle' => '',
|
||||
'user_sess' => '', // Photo
|
||||
'user_email' => '',
|
||||
'user_signature' => '',
|
||||
'user_image' => '', // Avatar
|
||||
'user_hideemail' => 1,
|
||||
'user_join' => 0,
|
||||
'user_realm' => 0,
|
||||
'user_pwchange' => 0,
|
||||
'user_lastvisit' => 0,
|
||||
'user_currentvisit' => 0,
|
||||
'user_lastpost' => 0,
|
||||
'user_chats' => 0,
|
||||
'user_comments' => 0,
|
||||
'user_ip' => '',
|
||||
'user_ban' => 0,
|
||||
'user_prefs' => '',
|
||||
'user_lastpost' => 0,
|
||||
'user_chats' => 0,
|
||||
'user_comments' => 0,
|
||||
'user_ip' => '',
|
||||
'user_ban' => 0,
|
||||
'user_prefs' => '',
|
||||
// 'user_viewed' => '',
|
||||
'user_visits' => 0,
|
||||
'user_admin' => 0,
|
||||
'user_login' => '', // User real name
|
||||
'user_class' => '',
|
||||
'user_perms' => '',
|
||||
'user_xup' => ''
|
||||
'user_visits' => 0,
|
||||
'user_admin' => 0,
|
||||
'user_login' => '', // User real name
|
||||
'user_class' => '',
|
||||
'user_perms' => '',
|
||||
'user_xup' => ''
|
||||
);
|
||||
|
||||
|
||||
@ -68,59 +74,45 @@ class user_import
|
||||
var $userMandatory = array(
|
||||
'user_name', 'user_loginname', 'user_password'
|
||||
);
|
||||
|
||||
|
||||
// Predefined fields which may appear in the extended user fields
|
||||
var $userExtended = array(
|
||||
'user_language',
|
||||
'user_country',
|
||||
'user_location',
|
||||
'user_aim',
|
||||
'user_icq',
|
||||
'user_yahoo',
|
||||
'user_msn',
|
||||
'user_homepage',
|
||||
'user_birthday',
|
||||
'user_timezone',
|
||||
'user_plugin_forum_posts'
|
||||
);
|
||||
|
||||
// Array is set up with those predefined extended fields which are actually in use
|
||||
|
||||
// Array is set up with the predefined extended fields which are actually in use
|
||||
var $actualExtended = array();
|
||||
|
||||
|
||||
// Constructor
|
||||
function user_import()
|
||||
{
|
||||
global $sql;
|
||||
$this->userDB = new db; // Have our own database object to write to the user table
|
||||
|
||||
// Create list of predefined extended user fields which are present
|
||||
if($ret = getcachedvars("userdata_{$uid}"))
|
||||
{
|
||||
foreach ($this->userExtended as $v)
|
||||
{
|
||||
if (isset($ret[$v])) $this->actualExtended[] = $v;
|
||||
}
|
||||
}
|
||||
$this->actualExtended = e107::getUserExt()->getFieldNames(); // Create list of predefined extended user fields which are present
|
||||
}
|
||||
|
||||
|
||||
// Empty the user DB - by default leaving only the main admin.
|
||||
function emptyTargetDB($inc_admin = FALSE)
|
||||
{
|
||||
$delClause = '';
|
||||
|
||||
if ($inc_admin === TRUE)
|
||||
{
|
||||
$this->blockMainAdmin = FALSE;
|
||||
$this->blockMainAdmin = FALSE;
|
||||
$delClause = '';
|
||||
$extClause = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->blockMainAdmin = TRUE;
|
||||
$delClause = 'user_id != 1';
|
||||
$this->blockMainAdmin = TRUE;
|
||||
$delClause = 'user_id != 1 AND user_perms != "0" ';
|
||||
$extClause = 'user_extended_id != 1';
|
||||
}
|
||||
|
||||
if($this->userDB->delete('user',$delClause))
|
||||
{
|
||||
e107::getMessage()->addDebug("Emptied User table");
|
||||
}
|
||||
|
||||
if($this->userDB->delete('user_extended',$extClause))
|
||||
{
|
||||
e107::getMessage()->addDebug("Emptied User-extended table");
|
||||
}
|
||||
$this->userDB->delete('user',$delClause);
|
||||
$this->userDB->delete('user_extended',$delClause);
|
||||
}
|
||||
|
||||
|
||||
@ -162,20 +154,25 @@ class user_import
|
||||
}
|
||||
|
||||
$extendedFields = array();
|
||||
$userFields = array_keys($this->userDefaults);
|
||||
|
||||
foreach ($userRecord as $k => $v)
|
||||
{
|
||||
if (in_array($k,$this->userExtended))
|
||||
if (!in_array($k, $userFields)) // Not present in e107_user table.
|
||||
{
|
||||
if (in_array($k,$this->actualExtended))
|
||||
if (in_array($k,$this->actualExtended)) // Present in e107_user_extended table.
|
||||
{
|
||||
$extendedFields[$k] = $v; // Pull out any extended field values which are needed
|
||||
}
|
||||
else
|
||||
{
|
||||
e107::getMessage()->addDebug("Removing user-field due to missing user-extended field {$k} ");
|
||||
}
|
||||
|
||||
unset($userRecord[$k]); // And always delete from the original data record
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($userRecord as $k => $v) // Check only valid fields being passed
|
||||
{
|
||||
if (!array_key_exists($k,$this->userDefaults) && !in_array($k,$this->userSpecial) && !in_array($k,$this->userMandatory) ) //
|
||||
@ -226,7 +223,7 @@ class user_import
|
||||
{
|
||||
$extendedFields['user_extended_id'] = varset($userRecord['user_id'],0) ? $userRecord['user_id'] : $result;
|
||||
|
||||
if($this->userDB->insert('user_extended',$extendedFields) === false)
|
||||
if($this->userDB->replace('user_extended',$extendedFields) === false)
|
||||
{
|
||||
e107::getMessage()->addDebug("Failed to insert extended fields: ".print_a($extendedFields));
|
||||
return 6;
|
||||
|
@ -35,7 +35,7 @@ require_once('import_classes.php');
|
||||
class phpbb2_import extends base_import_class
|
||||
{
|
||||
|
||||
public $title = 'PHPBB Version 2';
|
||||
public $title = 'phpBB Version 2';
|
||||
public $description = 'Should do most versions, and Dragonfly';
|
||||
public $supported = array('users');
|
||||
public $mprefix = 'phpbb_';
|
||||
@ -55,7 +55,7 @@ class phpbb2_import extends base_import_class
|
||||
switch ($task)
|
||||
{
|
||||
case 'users' :
|
||||
$result = $this->ourDB->db_Select_gen("SELECT * FROM {$this->DBPrefix}users WHERE `user_active` = 1");
|
||||
$result = $this->ourDB->gen("SELECT * FROM {$this->DBPrefix}users WHERE `user_active` = 1");
|
||||
if ($result === FALSE) return FALSE;
|
||||
break;
|
||||
case 'forumdefs' :
|
||||
|
@ -19,12 +19,10 @@ require_once('import_classes.php');
|
||||
class phpbb3_import extends base_import_class
|
||||
{
|
||||
|
||||
public $title = 'PHPBB Version 3';
|
||||
public $description = 'Experimental';
|
||||
public $title = 'phpBB Version 3';
|
||||
public $description = 'Import phpBB3 Users and Forums';
|
||||
public $supported = array('users','forum','forumthread','forumpost','forumtrack');
|
||||
public $mprefix = 'phpbb_';
|
||||
|
||||
|
||||
|
||||
var $catcount = 0; // Counts forum IDs
|
||||
var $id_map = array(); // Map of PHPBB forum IDs ==> E107 forum IDs
|
||||
@ -40,7 +38,7 @@ class phpbb3_import extends base_import_class
|
||||
switch ($task)
|
||||
{
|
||||
case 'users' :
|
||||
$result = $this->ourDB->gen("SELECT * FROM {$this->DBPrefix}users ");
|
||||
$result = $this->ourDB->gen("SELECT * FROM {$this->DBPrefix}users ORDER BY user_id ASC ");
|
||||
if ($result === FALSE) return FALSE;
|
||||
break;
|
||||
|
||||
@ -78,68 +76,100 @@ class phpbb3_import extends base_import_class
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->copyUserInfo = true; // !$blank_user;
|
||||
$this->currentTask = $task;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$this->copyUserInfo = true; // !$blank_user;
|
||||
$this->currentTask = $task;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert salted password to e107 style (they use the same basic coding)
|
||||
*/
|
||||
function convertPassword($password)
|
||||
{
|
||||
if ((substr($password ,0,3) == '$H$') && (strlen($password) == 34))
|
||||
{
|
||||
return substr_replace($password, '$E$',0,3);
|
||||
}
|
||||
else // Probably an old md5 password
|
||||
{
|
||||
return $password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function convertBirthday($date)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
|
||||
if(trim($date) == '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
list($d,$m,$y) = explode("-",$date);
|
||||
return $tp->leadingZeros($y,4)."-".$tp->leadingZeros($m,2)."-".$tp->leadingZeros($d,2);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
// Internal functions below here
|
||||
//------------------------------------
|
||||
|
||||
// Copy data read from the DB into the record to be returned.
|
||||
|
||||
/**
|
||||
* Copy data read from the DB into the record to be returned.
|
||||
* $target - e107_users table
|
||||
* $source - phpbb_user table : https://wiki.phpbb.com/Table.phpbb_users
|
||||
*/
|
||||
function copyUserData(&$target, &$source)
|
||||
{
|
||||
// if ($this->copyUserInfo)
|
||||
$target['user_id'] = $source['user_id'];
|
||||
$target['user_name'] = $source['username'];
|
||||
$target['user_loginname'] = $source['username'];
|
||||
|
||||
if ((substr($source['user_password'],0,3) == '$H$') && (strlen($source['user_password']) == 34)) // Convert salted password to E107 style (they use the same basic coding)
|
||||
{
|
||||
$target['user_password'] = substr_replace($source['user_password'], '$E$',0,3);
|
||||
}
|
||||
else // Probably an old md5 password
|
||||
{
|
||||
$target['user_password'] = $source['user_password'];
|
||||
}
|
||||
|
||||
$target['user_email'] = $source['user_email'];
|
||||
$target['user_signature'] = $this->proc_bb($source['user_sig'],'phpbb,bblower');
|
||||
$target['user_hideemail'] = $source['user_allow_viewemail'];
|
||||
$target['user_join'] = $source['user_regdate'];
|
||||
// $target['user_forums'] = $source['user_posts'];
|
||||
$target['user_admin'] = 0; // $source['user_level'];
|
||||
$target['user_lastvisit'] = $source['user_lastvisit'];
|
||||
$target['user_ban'] = $source['user_type'];
|
||||
|
||||
switch ($source['user_avatar_type'])
|
||||
{
|
||||
default:
|
||||
$target['user_image'] = $source['user_avatar'];
|
||||
}
|
||||
|
||||
// $target['user_plugin_forum_viewed'];
|
||||
$target['user_id'] = $source['user_id'];
|
||||
$target['user_name'] = $source['username'];
|
||||
$target['user_loginname'] = $source['username'];
|
||||
$target['user_password'] = $this->convertPassword($source['user_password']);
|
||||
$target['user_email'] = $source['user_email'];
|
||||
$target['user_signature'] = $this->proc_bb($source['user_sig'],'phpbb,bblower');
|
||||
$target['user_image'] = $source['user_avatar'];
|
||||
$target['user_hideemail'] = $source['user_allow_viewemail'];
|
||||
$target['user_join'] = $source['user_regdate'];
|
||||
$target['user_lastvisit'] = $source['user_lastvisit'];
|
||||
$target['user_currentvisit'] = 0;
|
||||
$target['user_admin'] = 0; // $source['user_level'];
|
||||
$target['user_lastpost'] = $source['user_lastpost_time'];
|
||||
$target['user_chats'] = '';
|
||||
$target['user_comments'] = '';
|
||||
$target['user_ip'] = $source['user_ip'];
|
||||
$target['user_ban'] = $source['user_type'];
|
||||
$target['user_prefs'] = '';
|
||||
$target['user_visits'] = '';
|
||||
$target['user_admin'] = 0;
|
||||
$target['user_login'] = '';
|
||||
$target['user_class'] = '';
|
||||
$target['user_perms'] = '';
|
||||
$target['user_realm'] = '';
|
||||
$target['user_pwchange'] = $source['user_passchg'];
|
||||
$target['user_xup'] = '';
|
||||
|
||||
// Extended Fields.
|
||||
|
||||
$target['user_plugin_forum_viewed'] = 0;
|
||||
$target['user_plugin_forum_posts'] = $source['user_posts'];
|
||||
$target['user_timezone'] = $source['user_timezone']; // source is decimal(5,2)
|
||||
$target['user_language'] = e107::getLanguage()->convert($source['user_lang']); // convert from 2-letter to full.
|
||||
$target['user_location'] = $source['user_from'];
|
||||
$target['user_icq'] = $source['user_icq'];
|
||||
$target['user_aim'] = $source['user_aim'];
|
||||
$target['user_yahoo'] = $source['user_yim'];
|
||||
$target['user_msn'] = $source['user_msnm'];
|
||||
$target['user_homepage'] = $source['user_website'];
|
||||
$target['user_birthday'] = $this->convertBirthday($source['user_birthday']);
|
||||
$target['user_occupation'] = $source['user_occ'];
|
||||
$target['user_interests'] = $source['user_interests'];
|
||||
|
||||
$target['user_timezone'] = $source['user_timezone']; // source is decimal(5,2)
|
||||
$target['user_language'] = $source['user_lang']; // May need conversion
|
||||
$target['user_location'] = $source['user_from'];
|
||||
$target['user_icq'] = $source['user_icq'];
|
||||
$target['user_aim'] = $source['user_aim'];
|
||||
$target['user_yahoo'] = $source['user_yim'];
|
||||
$target['user_msn'] = $source['user_msnm'];
|
||||
$target['user_homepage'] = $source['user_website'];
|
||||
// $target['user_'] = $source[''];
|
||||
// $target[] = $source['user_active]; // PHPBB2
|
||||
// $target['user_lastpost'] = $source['user_lastpost_time']; // PHPBB3
|
||||
|
||||
return $target;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user