'. t('You cannot migrate the data now. Please complete the setup first', array('@settings' => url('admin/settings/phpbb2drupal'))) .'

'; } // if (variable_get('phpbb2drupal_import_user_successful', 0)) { $output = 'phpBB 2 Drupal Migration Form'; $output .= drupal_get_form('phpbb2drupal_migrate_users_form'); // }else{ // $output = 'Users have been imported already!'; // } return $output; } function phpbb2drupal_migrate_users_form() { _phpbb2drupal_db_connect() ; /* $new = array('cleanup' => 'Clean up'); $PHPBB2DRUPAL_FUNCTIONS = array_merge( $PHPBB2DRUPAL_FUNCTIONS, $new); */ $form['import'] = array( '#type' => 'hidden', '#value' => 'users', ); $form[] = array( '#type' => 'submit', '#value' => t('Import Users'), ); return $form; } function phpbb2drupal_migrate_users_form_submit($form, $form_state) { switch ($form_state['values']['import']) { case 'users': if (variable_get('phpbb2drupal_import_user_successful', 0)) { drupal_set_message(t('Users already imported successfully')); return; }else{ phpbb2drupal_import_users_run_once(); phpbb2drupal_import_users_batch(); } } } /** * User Import Functions */ function phpbb2drupal_import_users_run_once() { if (variable_get('phpbb2drupal_import_user_started', 0) == 0) { // create temporary tables db_set_active('default'); // create profile fields for icq, aim, msn...etc $querybase = 'INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES '; $query = $querybase ."('YIM', 'user_yim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('AIM', 'user_aim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('icq', 'user_icq', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('Website', 'user_website', '', 'Contact', '', 'url', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('Location', 'user_from', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('Occupation', 'user_occ', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); $query = $querybase ."('Interests', 'user_interests', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')"; db_query($query); //Add the admin user to the temporary tables. $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', ''))); db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid); variable_set('phpbb2drupal_import_user_started', 1); } } function phpbb2drupal_import_users_batch() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $import_spammers = variable_get('phpbb2drupal_import_spammers', 1); $files_path = variable_get('file_directory_path', 'files'); $pictures_path = variable_get('user_picture_path', 'pictures'); db_set_active('phpbb'); $user_count = db_result(db_query('SELECT COUNT(user_id) FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre)); db_set_active('default'); $batch = array( 'operations' => array('phpbb2drupal_import_users_op', array($user_count)), 'finished' => 'phpbb2drupal_import_users_finished', 'title' => t('Importing Users'), 'init_message' => t('User import is starting.'), 'progress_message' => t('@current out of @total users processed.'), 'error_message' => t('User Import has encountered an error.'), ); batch_set($batch); // If this function was called from a form submit handler, stop here, // FAPI will handle calling batch_process(). } function phpbb2drupal_import_users_op($user_count, &$context) { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); db_set_active('phpbb'); $user_ids[] = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre); db_set_active('default'); if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['phpbbuser'] = $user_ids[0]; $context['sandbox']['max'] = $user_count; } db_set_active('phpbb'); $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $context['sandbox']['phpbbuser']->user_id)); // If we don't want to import users who have never posted, break this while loop here. if ($import_spammers == 1 || $user->user_posts != 0 ) { // Make sure the user is has not already been imported db_set_active('default'); $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $user->user_id)); if ($count > 0) { $user->user_active = 0; } $user->user_aim = strtr($user->user_aim, array('+' => ' ')); # PHPBB stores spaces as +, replace with ' ' $user->user_yim = strtr($user->user_yim, array('+' => ' ')); $user->user_timezone = $user->user_timezone * 60 * 60; # Drupal stores timezones in seconds // remove the bbcode_uid from post_text $user->user_sig = preg_replace("/:$user->user_sig_bbcode_uid/", '', $user->user_sig); // if the $user->user_avatar_type is not their own image, delete it // drupal doesn't have pre-defined avatars. if we were to import it // then multiple people would share the same avatar image and if one user // were to changes their avatar then it would change it for everybody else. if ($user->user_avatar_type > 1) { $user->user_avatar = ''; } $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : ''; // remove the :bbcode_uid from signature $signature = preg_replace("/:$post->bbcode_uid/", '', $user->user_sig); $signature = _phpbb2drupal_strip_bbcode($signature); $signature = _phpbb2drupal_text_encode($signature); if (variable_get('phpbb2drupal_regdate_us_english', 0)) { $user_regdate = strtotime($user->user_regdate); $user_lastvisit = strtotime($user->user_lastvisit); $user_session_time = strtotime($user->user_session_time); } else { $user_regdate = $user->user_regdate; $user_lastvisit = $user->user_lastvisit; $user_session_time = $user->user_session_time; } $data = array( 'name' => substr($user->username, 0, 60), 'pass' => substr($user->user_password, 0, 32), 'mail' => substr($user->user_email, 0, 64), 'signature' => substr($signature, 0, 255), 'created' => $user_regdate, 'access' => $user_session_time, 'login' => $user_lastvisit, 'status' => $user->user_active, 'timezone' => $user->user_timezone, 'picture' => $user->user_avatar, 'init' => substr($user->user_email, 0, 64), 'roles' => array(0 => 2), # Authenticated User 'user_website' => $user->user_website, 'user_from' => $user->user_from, 'user_icq' => $user->user_icq, 'user_aim' => $user->user_aim, 'user_yim' => $user->user_yim, 'user_msnm' => $user->user_msnm, 'user_occ' => $user->user_occ, 'user_interests' => $user->user_interest ); if (variable_get('phpbb2drupal_import_pm', 0)) { $data['privatemsg_allow'] = 1; } $data['interests'] = _phpbb2drupal_text_encode($data['interests']); db_set_active('default'); $drupal_user = phpbb2drupal_user_save($data, array('account', 'Personal', 'Contact')); // populate the temporary user table db_set_active('default'); db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES ( %d, %d )', $user->user_id , $drupal_user->uid); db_set_active('phpbb'); } $context['message'] = t('Now processing %user', array('%user' => $drupal_user->name)); $context['sandbox']['progress']++; $context['sandbox']['phpbbuser'] = $user_ids[$context['sandbox']['progress']]; if ($context['sandbox']['progress'] != $context['sandbox']['max']) { $context['finished'] = 0; } } function phpbb2drupal_import_users_finished($success, $operations) { if ($success) { // set the user import successful flag in the variable table db_set_active('default'); variable_set('phpbb2drupal_import_user_successful', '1'); $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user}')); $message = t('Successfully Imported %count Users', array('%count' => $count)); }else { $error_operation = reset($operations); $message = 'An error occurred while processing '. $error_operation[0] .' with arguments :'. print_r($error_operation[0], TRUE); } drupal_set_message($message); }