i'm logged in as admin with "root" as my username. the error says username doesn't exist
this is the topics_to_add.csv file
Code: Select all
<?php
/*
* @name add_topics.php
* @package phpBB3 Portal XL
* @version $Id: add_topics.php, v 0.1.0 2008/09/25 22:50:53
*
* @copyright (c) 2007, 2008 Peter Lykkegaard
* @license http://opensource.org/licenses/lgpl-3.0.html GNU Lesser General Public License (LGPLv3)
*
* Adapted from topic at phpbb
* Joomlaboard 1.1.2 to PHPBB3 (and Joomla/Jfusion)
* http://www.phpbb.com/community/viewtopic.php?f=65&t=1009785
*
* move posts from csv to phpbb3
* layout of CSV file:
* forum_id,
* topic_id,
* post_id,
* username,
* subject,
* message,
* post_time
*
*/
set_time_limit(0);
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
// get user info by username
function getUserId($id) {
global $db;
return $db->sql_fetchrow(
$db->sql_query(
'select * from phpbb_users where username_clean="'.strtolower($id).'"'
)
);
}
// get thread info by title
// We need to truncate the string in order to do a propber in the phpbb3 database
function getThreadByTitle($subject) {
global $db;
return $db->sql_fetchrow(
$db->sql_query(
'select * from phpbb_posts where post_subject = "'.utf8_normalize_nfc(truncate_string($subject)).'"'
)
);
}
// check for duplicates (not used in this script)
function checkForDupe($id,$md5text) {
global $db;
$res = $db->sql_fetchrow(
$db->sql_query(
'select post_id from phpbb_posts where post_checksum = "'.$md5text.'" and forum_id = "'.$id.'"'
)
);
return $res['post_id'];
}
// log any errors to custom table (not used)
function logError($id,$dupe='-',$reason='-') {
global $db;
$db->sql_query('
insert into jos_sb_error_ids(id,dupe_id,reason) values("'.$id.'","'.$dupe.'","'.$reason.'")'
);
}
$row = 1;
// Read the CSV file from root
$handle = fopen("topics_to_add.csv", "r");
while (($data = fgetcsv($handle, 5000, ";")) !== FALSE) {
$num = count($data);
// echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
// echo $data[$c] . "<br />\n";
$topics_data[$topics_counter][$c] = $data[$c];
}
$topics_counter++;
}
fclose($handle);
// traverse through the array we have read from file
foreach ($topics_data as &$row_data)
{
// echo 'username: ' . $row_data[3] . '<br />';
// Get userId based on username - assuming that username will be unique in phpbb3
$uinfo = getUserId($row_data[3]);
// initiate the user class
$user->data['user_id'] = $uinfo['user_id'];
$user->data['user_colour'] = $uinfo['user_colour'];
$user->data['username'] = $uinfo['username'] != '' ? $uinfo['username'] : '';
if(!$user->data['username']) {
echo 'ERROR: User does not exist<br />';
// logError($row['id'],null,'Original User was not found:'.$row['name']);
continue;
}
// we need to run the authentication otherwisr the post is not getting approved automatically
$auth->acl($user->data);
// trim any leading or trailing spaces and normalize the input data
$subject = utf8_normalize_nfc(trim($row_data[4]));
// add notification with old post_time etc on top of the message
$message = '[i][size=85]Oprettet ' . $row_data[6] . ', ' .
'importeret fra hjemmeskolen.dk af [url=http://192.168.1.64/memberlist.php?mode=viewprofile&u=2][color=#AA0000][b]admin[/b][/color][/url][/size][/i]
' . trim($row_data[5]);
$message = utf8_normalize_nfc($message);
// variables to hold the parameters for submit_post
$poll = $uid = $bitfield = $options = '';
generate_text_for_storage($subject, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
// build the data array before posting
$data = array(
'forum_id' => $row_data[0],
'icon_id' => false,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $message,
'message_md5' => md5($message),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'post_edit_locked' => 0,
'topic_approved' => true,
'topic_title' => $subject,
'notify_set' => false,
'notify' => false,
'post_time' => '0',
'forum_name' => '',
'enable_indexing' => true,
);
// not used -------------------------------------------------
// $id = checkForDupe($cats[$row['catid']],md5($my_text));
// if($id >= 1) {
// echo 'dupe';
// logError($row['id'],$id,'Duplicate');
// continue;
// }
// not used -------------------------------------------------
// if reply_id is 0 then assume it is a post
if($row_data[2] == 0) {
// Remove comments to submit the data
// submit_post('post', $subject, $uinfo['username_clean'], POST_NORMAL, $poll, $data);
echo 'post: ' . $subject . '<p />';
}
else {
// this is a reply
$thread = getThreadByTitle(trim($row_data[4]));
$data['topic_id'] = $thread['topic_id'];
if(!$thread['topic_id']) {
echo 'ERROR: No Parent Found<br />';
echo $row['id'],'--','No Parent thread found : '.$row_data[4] . '<br />';
continue;
}
// Remove comments to submit the data
// submit_post('reply', $subject, $uinfo['username_clean'], POST_NORMAL, $poll, $data);
echo 'reply: ' . $subject . '<p />';
}
} // Done foreach
echo 'FINISHED';
?>