'admin/phpbb2drupal', 'title' => t('phpBB to Drupal'), 'access' => user_access('migrate phpBB'), 'callback' => 'phpbb2drupal_main', 'type'=> MENU_NORMAL_ITEM, ); $items[] = array( 'path' => 'admin/phpbb2drupal/postconfiguration', 'title' => t('Post Migration Configuration'), 'access' => user_access('migrate phpBB'), 'callback' => 'phpbb2drupal_postconfiguration', 'type'=> MENU_NORMAL_ITEM, ); $items[] = array( 'path' => 'admin/phpbb2drupal/cleanup', 'title' => t('Cleanup'), 'access' => user_access('migrate phpBB'), 'callback' => 'phpbb2drupal_cleanup', 'type'=> MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/phpbb2drupal/migrate', 'title' => t('Execute Migration'), 'access' => user_access('migrate phpBB'), 'callback' => 'phpbb2drupal_migrate', 'type'=> MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/phpbb2drupal/reset', 'title' => t('Reset phpBB2 database URL'), 'access' => user_access('migrate phpBB'), 'callback' => 'phpbb2drupal_reset', 'type'=> MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/settings/phpbb2drupal', 'title' => t('phpBB2Drupal Settings'), 'access' => user_access('migrate phpBB'), 'callback' => 'drupal_get_form', 'callback arguments' => array('phpbb2drupal_admin_settings'), ); } return $items; } /** * Implementation of hook_perm() */ function phpbb2drupal_perm() { return array('migrate phpBB'); } /** * Callback admin/phpbb2drupal/reset */ function phpbb2drupal_reset() { global $db_url; variable_set('phpbb2drupal_db_url', $db_url); variable_set('phpbb2drupal_ready', 0); return '
'. t('The phpBB2 database URL has been reset. You may now go back to the configuration page.', array('%configlink' => url('admin/settings/phpbb2drupal'))) .'
'; } /** * Callback admin/phpbb2drupal/cleanup */ function phpbb2drupal_cleanup() { return phpbb2drupal_import_cleanup() . ''. t('Drupal database cleaned.') .'
'; } /** * Callback admin/phpbb2drupal/postconfiguration */ function phpbb2drupal_postconfiguration() { // Private forums. $output = ''. t('Setup the private forums as explained in the documentation') .'
'; // Redirection from old URL: $output .= ''. t('Enable the phpbb_redirect.module. This way, users accessing URLs from your old phpBB2 installation will be redirected to your new Drupal forum. (note that currently the module assumes that the phpbb forum was located in the forum/ subdirectory of your Drupal installation).') .'
'; // BBcode $bbcode = variable_get('phpbb2drupal_bbcode', 0); if ($bbcode) { $output .= ''. t("The bbcode has been cleaned from the posts. You shouldn't need the bbcode module anymore. You can disable it.") .'
'; } else { $output .= ''. t('Most probably, there are many phpBB forum postings formatted in BBcode. During the import procedure, the BBcode has been cleaned so that it can work with the Drupal bbcode.module. Please install and configure the BBcode module so that the forum topics display properly. See the BBcode module documentation for details.') .'
'; } //Avatars $output .= 'Manually copy the avatars from the phpbb2/images/avatars/ directory to the drupal/files/pictures/ directory.
Also, in admin > settings > users, you need to enable picture support.
Finally, in admin > themes > configure, you need to allow "User Picture in posts/comments".
'); return $output; } /** * Callback admin/phpbb2drupal */ function phpbb2drupal_main() { $output = ''. t('If the phpBB2 data is in another data base, but you made a mistake while setting up the data base url, you may be unable to access the setting page due to some limitations of the core of Drupal. Click here to reset the database url.', array('%reseturl' => url('admin/phpbb2drupal/reset'))) .'
'; return $output; } /** * Set database connection for phpBB * * @return * 1 if can connect to phpbb database. * * BEWARE: if you test using db_connect and the connection * fails, the process will die() which is a bit too much since we only * want to test. Therefore, the test part of the code is not used, now. */ function _phpbb2drupal_db_connect($test= 0) { global $db_url; $same = variable_get('phpbb2drupal_same_db', 1); if (!$same) { $db_url2['phpbb'] = variable_get('phpbb2drupal_db_url', $db_url); $db_url2['default'] = $db_url; $GLOBALS['db_url'] =& $db_url2; if ($test) { if (!db_connect($db_url2['phpbb'])) { return 0; } } } return 1; } /** * Callback admin/phpbb2drupal/configure */ function phpbb2drupal_admin_settings() { global $conf ; global $db_url; $stage = variable_get('phpbb2drupal_config_stage', 0); //We'll be checking that the setup is complete. //If it is not complete, the migration will not go ahead. $ready_for_migration = 1; // Checking that the migration has been tested on a copy first. $form['test'] = array( '#type' => 'fieldset', '#title' => t('Test on copy first'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $output = ''; if (!variable_get('phpbb2drupal_tested', 0)) { $form['test']['#collapsed']= FALSE; $output = ''; $ready_for_migration = 0; } $output .= t('The migration will modify and even destroy some data. You must test this module on a copy of your data first, several times if necessary. Only use this module on your live data when you are familiar with the procedure and you\'re confident everything will run smoothly.
Also, you should make a full backup of your database just prior to permorming the migration on the live data. It is better to turn off both the phpBB board and the Drupal site during the migration.
'); if (!variable_get('phpbb2drupal_tested', 0)) { $output .= ''; } $form['test']['intro'] = array('#value' => $output); $output = ''; $form['test']['phpbb2drupal_tested'] = array( '#type' => 'checkbox', '#title' => t('I am running a trial migration on a disposable copy of the database OR I have already done so and I am running this on my live site, confident that the migration will proceed smoothly'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_tested', 0), '#description' => '', ); // Input format settings $form['input'] = array( '#type' => 'fieldset', '#title' => t('Input Format settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $output = ''. t('Select which input format should the imported messages be set:', array('%link' => url('admin/filters'))) .'
'; $form['input']['intro'] = array('#value' => $output); $output = ''; $input_formats = array(0 => t('not set yet')); $sql = 'SELECT format, name FROM {filter_formats}'; $result = db_query($sql); while ($format = db_fetch_array($result)) { $input_formats[$format['format']]= $format['name']; } $input_format = variable_get('phpbb2drupal_input_format', 0); $form['input']['phpbb2drupal_input_format'] = array( '#type' => 'radios', '#title' => t('Input format'), '#default_value' => $input_format, '#options' => $input_formats, ); if (!$input_format) { $ready_for_migration = 0; $form['input']['#collapsed']= FALSE; } $output .= ''. t('This setting will be applied to all posts and private messages.') .'
'; $form['input']['result'] = array('#value' => $output); // BBcode settings $form['bbcode'] = array( '#type' => 'fieldset', '#title' => t('BBcode settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $output = t('pbpBB2 posts are often formatted in BBcode. During the import process, BBcode can be handled in two diffent ways:
Which one do you choose?
Also, make sure to choose the proper input filter, for it will affect how the post is displayed. For example, if you choose to strip the bbcode altogether and use HTML instead, some HTML tags will be stripped by the "filtered HTML" input format, unless you add those tags in the list of allowed tags. Using "Full HTML" is recommanded for the imported posts when doing away with bbcode.
'); $form['bbcode']['intro'] = array('#value' => $output); $form['bbcode']['phpbb2drupal_bbcode'] = array( '#type' => 'radios', '#title' => t('BBcode handling'), '#default_value' => variable_get('phpbb2drupal_bbcode', 0), '#options' => array(t('Leave BBcode as is.'), t('Transform BBcode into HTML.')), '#description' => '', ); $output = ''; $result7 = _phpbb2drupal_check_module('bbcode'); $output .= $result7['html']; $link_input_format_enable = url('admin/filters/'.$input_format); $link_input_format_configure = url('admin/filters/'.$input_format.'/configure'); if (variable_get('phpbb2drupal_bbcode', 0)) { if ($result7['result'] == 0) { $ready_for_migration = 0; $form['bbcode']['#collapsed']= FALSE; $output .= ''; $output .= t('The bbcode module is required to transform BBcode into HTML. You first need to enable the bbcode module', array('%adminmodules' => url('admin/modules'))); $output .= '
'; } $sql = 'SELECT * FROM {filters} WHERE module = \'bbcode\' AND format = %d'; $result = db_query($sql, $input_format); if (!db_num_rows($result)) { $form['bbcode']['#collapsed']= FALSE; $output .= ''. t('You need to enable bbcode in the selected input format THEN click on configure to see bbcode options', array('%formatenable' => $link_input_format_enable, '%formatconfigure' => $link_input_format_configure)) .'
'; } $output .= ''. t('For best results, all four BBcode configure options should be disabled.', array('%bbcodeconfig' => url('admin/filters/'. $input_format .'/configure'))) .'
'; } else { if ($result7['result'] == 0) { $form['bbcode']['#collapsed']= FALSE; $output .= ''. t('The bbcode module is only recommanded. You may enable the bbcode module after having installed it.', array('%adminmodules' => url('admin/modules'))) .'
'; } $output .= t('Don\'t forget to enable bbcode in the selected input format (admin > input formats > configure) and enable bbcode for the format selected for the imported posts. Then click on configure to see bbcode options
You may want to enable it for other input formats, too.
', array('%formatenable' => $link_input_format_enable, '%formatconfigure' => $link_input_format_configure)); } $output .= ''. t('This setting will be applied to all posts, private messages and the users\' signature.') .'
'; $form['bbcode']['result'] = array('#value' => $output); // Drupal Modules settings $form['modules'] = array( '#type' => 'fieldset', '#title' => t('Drupal modules'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $output = ''; $result1 = _phpbb2drupal_check_module('forum'); $output .= $result1['html']; $result2 = _phpbb2drupal_check_module('node'); $output .= $result2['html']; $result3 = _phpbb2drupal_check_module('comment'); $output .= $result3['html']; $result4 = _phpbb2drupal_check_module('user'); $output .= $result4['html']; $result5 = _phpbb2drupal_check_module('profile'); $output .= $result5['html']; $result6 = _phpbb2drupal_check_module('taxonomy'); $output .= $result6['html']; $output .= '
'; if ($result1['result'] == 0 || $result2['result'] == 0 || $result3['result'] == 0 || $result4['result'] == 0 || $result5['result'] == 0 || $result6['result'] == 0) { $ready_for_migration = 0; $form['modules']['#collapsed']= FALSE; $output .= ''; $output .= t('Some of the modules are not enabled. Got to the admin/modules page to enable them', array('%adminmodules' => url('admin/modules'))); $output .= '
'; } $form['modules']['result'] = array('#value' => $output); $output = ''; // Where is phpbb2? $form['phpbb2'] = array( '#type' => 'fieldset', '#title' => t('Location of phpBB2 data'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['phpbb2']['phpbb2drupal_same_db'] = array( '#type' => 'checkbox', '#title' => t('phpbb is on the same database as drupal'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_same_db', 1), '#description' => '', ); if (variable_get('phpbb2drupal_same_db', 1) != 1) { $url = variable_get('phpbb2drupal_db_url', $db_url); if ($url == $db_url) { $output = ''. t('Set the address of the phpBB database according to the following format:
mysql://phpbb_username:phpbb_password@localhost/phpbb_database') .''; $ready_for_migration = 0; $form['phpbb2']['#collapsed']= FALSE; } $form['phpbb2']['phpbb2drupal_db_url'] = array( '#type' => 'textfield', '#title' => t('phpBB2 database location'), '#default_value' => variable_get('phpbb2drupal_db_url', $db_url), '#size' => 80, '#maxlength' => 255, '#description' => '', ); } $output = t('
Note that due to a limitation within Drupal core, we cannot import messages from one database type to another database type. E.g, we cannot import phpBB from a myqsl DB, to a postgresql DB. You need to import the data into the same type of database first (import all the phpBB data, as is, from mysql to postgresql.
If both phpBB and Drupal are on postgresql, see this issue.
'); $form['phpbb2']['note'] = array('#value' => $output); // phpBB2 table prefix $output = ''; $form['phpbb2']['phpbb2drupal_table_prefix'] = array( '#type' => 'textfield', '#title' => t('phpBB2 table prefix'), '#default_value' => variable_get('phpbb2drupal_table_prefix', 'phpbb_'), '#size' => 20, '#maxlength' => 255, '#description' => t('What prefix is used for your phpBB2 tables?'), ); $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $tables = array($pre.'categories', $pre.'forums', $pre.'posts', $pre.'posts_text', $pre.'topics', $pre.'users'); $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['phpbb2']['#collapsed']= FALSE; $output .= ''; $output .= t("Some tables couldn't be found. Please correct the errors so that the phpBB2 tables can be accessed."); $output .= ''; } $form['phpbb2']['result'] = array('#value' => $output); // Misc. $form['misc'] = array( '#type' => 'fieldset', '#title' => t('Misc. settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Time limit $output = ''; //Registration date format $form['misc']['phpbb2drupal_regdate_us_english'] = array( '#type' => 'checkbox', '#title' => t('Convert Registration Date'), '#default_value' => variable_get('phpbb2drupal_regdate_us_english', 0), '#return_value' => 1, '#description' => t('If you find out that the registration date for ALL your users is over 36 years ago, maybe your DB stores the registration date in the English US format (like: "Sep 11, 2001") instead as a linux timestamp (like: "1152568884"). If so, check this box.'), ); $form['misc']['phpbb2drupal_time_limit'] = array( '#type' => 'textfield', '#title' => t('Time limit'), '#default_value' => variable_get('phpbb2drupal_time_limit', 1200), '#size' => 7, '#maxlength' => 10, '#description' => t('How long, in seconds, will the migration take?'), ); $form['misc']['info'] = array( '#value' => ''. t('1200 = 20 minutes should be enough for most boards. It worked well for a board with 300,000 rows. Beware: if your site is cohosted and safe-mode is on, then this value will have no effect.') .'
', ); // USERS settings $form['users'] = array( '#type' => 'fieldset', '#title' => t('User import'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // User to map admin user too $drupal_admin = user_load(array('uid' => 1)); $form['users']['phpbb2drupal_admin_user'] = array( '#title' => t('User to map phpBB admin'), '#type' => 'textfield', '#autocomplete_path' => 'user/autocomplete', '#default_value' => variable_get('phpbb2drupal_admin_user', $drupal_admin->name ), ); // Import users who have never posted? $form['users']['phpbb2drupal_import_spammers'] = array( '#type' => 'checkbox', '#title' => t('Import users who have never posted?'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_import_spammers', 1), '#description' => '', ); //Polls $form['polls'] = array( '#type' => 'fieldset', '#title' => t('Polls import'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['polls']['phpbb2drupal_import_polls'] = array( '#type' => 'checkbox', '#title' => t('Import polls?'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_import_polls', 0), '#description' => '', ); if (variable_get('phpbb2drupal_import_polls', 0) == 1) { //poll modules $result = _phpbb2drupal_check_module('poll'); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['polls']['#collapsed'] = FALSE; $output .= ''; $output .= t('Please enable the poll module.') ; $output .= ''; } $form['polls']['info'] = array('#value' => $output); } //Attachements $output =''; $form['attachements'] = array( '#type' => 'fieldset', '#title' => t('Attachements import'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['attachements']['phpbb2drupal_import_attachments'] = array( '#type' => 'checkbox', '#title' => t('Import attachments?'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_import_attachments', 0), '#description' => '', ); if (variable_get('phpbb2drupal_import_attachments', 0) == 1) { // Comment attachments module $result = _phpbb2drupal_check_module('comment_upload'); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['attachements']['#collapsed']= FALSE; $output .= ''; $output .= t('The comment_upload.module is not enabled. You can go to the module Home Page to download it. After having installed it, go to the admin/module page to enable it', array('%adminmodules' => url('admin/modules'))); $output .= ''; } //comment_files tables. $result = _phpbb2drupal_check_tables(array('comment_files')); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['attachements']['#collapsed']= FALSE; $output .= ''; $output .= t("The comment_files table couldn't be found. Please make sure you have properly installed the comment_upload.mysql on your Drupal database."); $output .= '
'; } $form['attachements']['info'] = array('#value' => $output); $output = ''; } // Encoding $form['encoding'] = array( '#type' => 'fieldset', '#title' => 'Encoding setting', '#collapsible' => TRUE, '#collapsed' => TRUE, ); //DEBUG http://php.net/extension_loaded if (!extension_loaded('mbstring') && variable_get('phpbb2drupal_encode', '1')) { $ready_for_migration = 0; $form['encoding']['#collapsed']= FALSE; $output .= ''; $output .= t("The php mbstring module is not installed on this server: the posts' encoding cannot be changed during the migration."); $output .= '
'; } $encodings = array( 'utf-8' => 'utf-8', 'iso-8859-1' => 'iso-8859-1', 'UCS-4' => 'UCS-4', 'UCS-4BE' => 'UCS-4BE', 'UCS-4LE' => 'UCS-4LE', 'UCS-2' => 'UCS-2', 'UCS-2BE' => 'UCS-2BE', 'UCS-2LE' => 'UCS-2LE', 'UTF-32' => 'UTF-32', 'UTF-32BE' => 'UTF-32BE', 'UTF-32LE' => 'UTF-32LE', 'UTF-16' => 'UTF-16', 'UTF-16BE' => 'UTF-16BE', 'UTF-16LE' => 'UTF-16LE', 'UTF-7' => 'UTF-7', 'UTF7-IMAP' => 'UTF7-IMAP', 'ASCII' => 'ASCII', 'EUC-JP' => 'EUC-JP', 'SJIS' => 'SJIS', 'eucJP-win' => 'eucJP-win', 'SJIS-win' => 'SJIS-win', 'ISO-2022-JP' => 'ISO-2022-JP', 'JIS' => 'JIS', 'ISO-8859-2' => 'ISO-8859-2', 'ISO-8859-3' => 'ISO-8859-3', 'ISO-8859-4' => 'ISO-8859-4', 'ISO-8859-5' => 'ISO-8859-5', 'ISO-8859-6' => 'ISO-8859-6', 'ISO-8859-7' => 'ISO-8859-7', 'ISO-8859-8' => 'ISO-8859-8', 'ISO-8859-9' => 'ISO-8859-9', 'ISO-8859-10' => 'ISO-8859-10', 'ISO-8859-13' => 'ISO-8859-13', 'ISO-8859-14' => 'ISO-8859-14', 'ISO-8859-15' => 'ISO-8859-15', 'byte2be' => 'byte2be', 'byte2le' => 'byte2le', 'byte4be' => 'byte4be', 'byte4le' => 'byte4le', 'BASE64' => 'BASE64', 'HTML-ENTITIES' => 'HTML-ENTITIES', '7bit' => '7bit', '8bit' => '8bit', 'EUC-CN' => 'EUC-CN', 'CP936' => 'CP936', 'HZ' => 'HZ', 'EUC-TW' => 'EUC-TW', 'CP950' => 'CP950', 'BIG-5' => 'BIG-5', 'EUC-KR' => 'EUC-KR', 'UHC (CP949)' => 'UHC (CP949)', 'ISO-2022-KR' => 'ISO-2022-KR', 'Windows-1251 (CP1251)' => 'Windows-1251 (CP1251)', 'Windows-1252 (CP1252)' => 'Windows-1252 (CP1252)', 'CP866 (IBM866)' => 'CP866 (IBM866)', 'KOI8-R' => 'KOI8-R', ); $form['encoding']['phpbb2drupal_encode'] = array( '#type' => 'checkbox', '#title' => t('Change encoding of text strings during the import'), '#default_value' => variable_get('phpbb2drupal_encode', '1'), ); $output .= ''. t('This setting is useful when the phpBB2 encoding is not the same as the Drupal encoding. You server must have the php mbstring module installed.') .'
'; $form['encoding']['info'] = array( '#value' => $output ); $form['encoding']['phpbb2drupal_encoding_phpbb'] = array( '#type' => 'select', '#title' => t('phpBB2 encoding'), '#default_value' => variable_get('phpbb2drupal_encoding_phpbb', 'iso-8859-1'), '#options' => $encodings, ); $form['encoding']['phpbb2drupal_encoding_drupal'] = array( '#type' => 'select', '#title' => t('Drupal encoding'), '#default_value' => variable_get('phpbb2drupal_encoding_drupal', 'utf-8'), '#options' => $encodings, ); // Private messages $output = ''; $form['pm'] = array( '#type' => 'fieldset', '#title' => t('Private Messages'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['pm']['phpbb2drupal_import_pm'] = array( '#type' => 'checkbox', '#title' => t('Import private messages?'), '#return_value' => 1, '#default_value' => variable_get('phpbb2drupal_import_pm', 0), '#description' => '', ); if (variable_get('phpbb2drupal_import_pm', 0) == 1) { // Private messages module $output = ''. t('If you want to use the private message module, make sure to configure it properly (admin > settings> private messages) and allow user to view their own private messages (admin > access control).') .'
'; $result = _phpbb2drupal_check_module('privatemsg'); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['pm']['#collapsed']= FALSE; $output .= ''; $output .= t('The private message module is not enabled. You can go to the module Home Page to download it. After having installed it, go to the admin/module page to enable it.', array('%adminmodules' => url('admin/modules'))); $output .= '
'; } $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $tables = array($pre.'privmsgs', $pre.'privmsgs_text'); $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['pm']['#collapsed']= FALSE; $output .= ''; $output .= t("Couldn't find the phpBB privatemsg tables."); $output .= '
'; } //private messages tables. $result = _phpbb2drupal_check_tables(array('privatemsg', 'privatemsg_folder', 'privatemsg_archive')); $output .= $result['html']; if ($result['result'] != 1) { $ready_for_migration = 0; $form['pm']['#collapsed']= FALSE; $output .= ''; $output .= t("Some tables couldn't be found. Please make sure you have properly installed the privatemsg.mysql on your Drupal data base."); $output .= '
'; } $form['pm']['info'] = array('#value' => $output); } $output =''; // Are we ready for migration? $form['migration'] = array( '#type' => 'fieldset', '#title' => 'Migration', '#collapsible' => TRUE, '#collapsed' => TRUE, ); variable_set('phpbb2drupal_ready', $ready_for_migration); if ($ready_for_migration) { $form['migration']['#collapsed']= FALSE; $output .= ''. t('Check again all the settings above, and if everything is ok, you can now proceed with the migration', array('%migratelink' => url('admin/phpbb2drupal/migrate'))) .'
'; } else { $output = ''. t('You are not ready for the migration yet. Check the settings above.') .'
'; } $form['migration']['info'] = array('#value' => $output); return system_settings_form($form); } /** * Check if the module is enabled. * * @return array * $out['html'] = formatted html. * $out['result'] = boolean. */ function _phpbb2drupal_check_module($module) { $out['html'] = ''. t('You cannot migrate the data now. Please complete the setup first', array('%settings' => url('admin/settings/phpbb2drupal'))) .'
'; } $output = 'Phpbb 2 Drupal Migration Form'; $output .= drupal_get_form('phpbb2drupal_migrate_form'); return $output; } function phpbb2drupal_migrate_form() { _phpbb2drupal_db_connect() ; // Causes problems with form api redirect //ini_set('display_errors', TRUE); // Adjust how long you want the script to run... if (!ini_get('safe_mode')) { set_time_limit(variable_get('phpbb2drupal_time_limit', 0)); } $PHPBB2DRUPAL_FUNCTIONS = array( 'users' => t('Import Users'), 'categories' => t('Import Categories'), 'topics' => t('Import Topics'), 'polls' => t('Import Polls'), 'posts' => t('Import Posts'), ); if (variable_get('phpbb2drupal_import_pm', 0)) { $PHPBB2DRUPAL_FUNCTIONS['pm'] = t('Import Private Messages'); } $PHPBB2DRUPAL_FUNCTIONS['url'] = t('Transform URLs'); /* $new = array('cleanup' => 'Clean up'); $PHPBB2DRUPAL_FUNCTIONS = array_merge( $PHPBB2DRUPAL_FUNCTIONS, $new); */ $form['import'] = array( '#type' => 'select', '#title' => t('Next import to perform'), '#default_value' => $_SESSION['phpbb2drupal_selected'], '#options' => $PHPBB2DRUPAL_FUNCTIONS, ); $form[] = array( '#type' => 'submit', '#value' => t('Import'), ); return $form; } function phpbb2drupal_migrate_form_submit($form_id, $form_values) { switch ($form_values['import']) { case 'users': phpbb2drupal_import_users(); if (!variable_get('phpbb2drupal_import_user_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'users'; } else { $_SESSION['phpbb2drupal_selected'] = 'categories'; } break; case 'categories': phpbb2drupal_import_categories(); if (!variable_get('phpbb2drupal_import_category_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'categories'; } else { $_SESSION['phpbb2drupal_selected'] = 'topics'; } break; case 'topics': phpbb2drupal_import_topics(); if (!variable_get('phpbb2drupal_import_topic_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'topics'; } else { $_SESSION['phpbb2drupal_selected'] = 'polls'; } break; case 'polls': phpbb2drupal_import_polls(); if (!variable_get('phpbb2drupal_import_poll_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'polls'; } else { $_SESSION['phpbb2drupal_selected'] = 'posts'; } break; case 'posts': phpbb2drupal_import_posts(); if (!variable_get('phpbb2drupal_import_post_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'posts'; } else { $_SESSION['phpbb2drupal_selected'] = 'pm'; } break; case 'pm': phpbb2drupal_import_pm(); if (!variable_get('phpbb2drupal_import_pm_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'pm'; } else { $_SESSION['phpbb2drupal_selected'] = 'url'; } break; case 'url': phpbb2drupal_replace_url(); if (!variable_get('phpbb2drupal_replace_url_successful', 0)) { $_SESSION['phpbb2drupal_selected'] = 'url'; } else { drupal_set_message('Congratulations. Import Finished'); drupal_set_message('Please visit the ' . l('Post migration configuration', 'admin/phpbb2drupal/postconfiguration'). ' page'); unset($_SESSION['phpbb2drupal_selected']); } break; default: $_SESSION['phpbb2drupal_selected'] = 'users'; break; } } /** * Private Message Import Functions */ function phpbb2drupal_import_pm() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $format = variable_get('phpbb2drupal_input_format', 0); if (variable_get('phpbb2drupal_import_pm_successful', 0) == 1) { return; } db_set_active('phpbb'); $query = "SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid, p.privmsgs_subject, pt.privmsgs_text, pt.privmsgs_bbcode_uid, p.privmsgs_date, CASE WHEN p.privmsgs_type = 1 THEN 1 WHEN p.privmsgs_type = 5 THEN 1 ELSE 0 END as newmsg, p.privmsgs_ip, 0, 0, 0 FROM %sprivmsgs p LEFT JOIN %sprivmsgs_text AS pt ON p.privmsgs_id = pt.privmsgs_text_id"; $messages = db_query($query, $pre, $pre); db_set_active('default'); while ($pm = db_fetch_object($messages)) { $query = 'SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d'; $from_result = db_query($query, $pm->privmsgs_from_userid); $from = db_result($from_result); $to_result = db_query($query, $pm->privmsgs_to_userid); $to = db_result($to_result); // don't import private messages from or to users who are not imported. if ($from and $to) { // remove the bbcode_uid from post_text $pm->privmsgs_text = preg_replace("/:$pm->privmsgs_bbcode_uid/", '', $pm->privmsgs_text); $pm->privmsgs_text = _phpbb2drupal_strip_bbcode($pm->privmsgs_text); $pm->privmsgs_text = _phpbb2drupal_text_encode($pm->privmsgs_text); $pm->privmsgs_text = _phpbb2drupal_replace_links($pm->privmsgs_text); $pm->privmsgs_subject = _phpbb2drupal_text_encode($pm->privmsgs_subject); $query = "INSERT INTO {privatemsg} ( id, author, recipient, subject, message, timestamp, newmsg, hostname, folder, author_del, recipient_del, format ) VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', 0, 0, 0 , %d)"; $result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject, 0, 64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip, 0, 255), $format); } } variable_set('phpbb2drupal_import_pm_successful', 1); return ''. t('Private Message Import successful') .'
'; } /** * User Import Functions */ function phpbb2drupal_import_users() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); // check if the user database has been successfully imported db_set_active('default'); if (variable_get('phpbb2drupal_import_user_successful', 0)) { drupal_set_message(t('Users already imported successfully')); return; } 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); variable_set('phpbb2drupal_import_user_started', 1); } db_set_active('default'); $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); $files_path = variable_get('file_directory_path', 'files'); $pictures_path = variable_get('user_picture_path', 'pictures'); // Insert the users into drupal db_set_active('phpbb'); $user_ids = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre); $user_count = db_num_rows($user_ids); if (!$user_count) { drupal_set_message(t('There were no users found: Aborting script'), 'error'); return t('There were no users found: Aborting script.'); } drupal_set_message(t('Found %user_count users: Beginning Import', array('%user_count' => $user_count + 1))); $import_spammers = variable_get('phpbb2drupal_import_spammers', 1); while ($result = db_fetch_object($user_ids)) { db_set_active('phpbb'); $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id)); // Make sure the user is not on the banlist /* db_set_active('phpbb'); $banned = db_result(db_query("SELECT COUNT(*) FROM {banlist} WHERE ban_userid = %d", $user->user_id)); if ($banned) { db_set_active('phpbb'); continue; }*/ // 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'); } } // 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}')); drupal_set_message(t('Successfully Imported %count Users', array('%count' => $count))); } /** * Create Forum Containers and Forums */ function phpbb2drupal_import_categories() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); // check if the forum database has been successfully imported db_set_active('default'); if (variable_get('phpbb2drupal_import_category_successful', 0)) { drupal_set_message(t('Categories already imported successfully')); return; } // forum mapping temporary tables if (variable_get('phpbb2drupal_import_category_started', 0) == 0) { db_set_active('default'); //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}'); //db_query("CREATE TABLE {phpbb2drupal_temp_forum} ( forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL, tid integer UNSIGNED DEFAULT '0' NOT NULL, KEY forum_id (forum_id))"); variable_set('phpbb2drupal_import_category_started', 1); } // Retrieve the vocabulary vid named "Forum" $forum_vid = _forum_get_vid(); drupal_set_message(t('Forum vid: %forum_vid', array('%forum_vid' => $forum_vid))); // Get Categories/Forums from PHPBB db_set_active('phpbb'); $category_results = db_query('SELECT * FROM %scategories ORDER BY cat_order', $pre); $cat_count = db_num_rows($category_results); drupal_set_message(t('Found %cat_count categories: Beginning Import', array('%cat_count' => $cat_count))); $forum_count = 0; while ($category_result = db_fetch_array($category_results)) { $cat_id = $category_result['cat_id']; $forums_results = db_query('SELECT * FROM %sforums WHERE cat_id = %d', $pre, $cat_id); $forum_count += db_num_rows($forums_results); $phpbb2_forums = array(); # reinitialize the temp var not to include it multiple times while ($forum_result = db_fetch_object($forums_results)) { //$phpbb2_categories[$category_result->cat_id]['forums'][] = $forums_result; $phpbb2_forums[$forum_result->forum_id] = $forum_result; } $phpbb2_categories[$cat_id] = array_merge($category_result, array('forums' => $phpbb2_forums)); } drupal_set_message(t('Found %forum_count forums: Beginning Import', array('%forum_count' => $forum_count))); // Insert the Containers / Forum into Drupal db_set_active('default'); // Insert the Containers $container_order = -10; foreach ($phpbb2_categories as $container) { $edit = array( 'name' => $container['cat_title'], 'vid' => $forum_vid, 'description' => '', 'weight' => $container_order, ); $edit['name'] = _phpbb2drupal_text_encode($edit['name']); taxonomy_save_term($edit); // serialize the forum containers $containers = variable_get('forum_containers', array()); $containers[] = $edit['tid']; variable_set('forum_containers', $containers); // Insert the Forums $forum_order = -10; foreach ($container['forums'] as $forum) { // Make sure the forum/term is has not already been imported if (!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum->forum_id))) { $forum_edit = array( 'name' => $forum->forum_name, 'vid' => $forum_vid, 'description' => $forum->forum_desc, 'weight' => $forum_order, 'parent' => array($edit['tid']), ); $forum_edit['name'] = _phpbb2drupal_text_encode($forum_edit['name']); $forum_edit['description'] = _phpbb2drupal_text_encode($forum_edit['description']); taxonomy_save_term($forum_edit); $forum_order++; $tid = $forum_edit['tid']; db_set_active('default'); db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)', $forum->forum_id, $tid); } } $container_order++; } db_set_active('default'); // set the forums import successful flag in the variable table variable_set('phpbb2drupal_import_category_successful', '1'); $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_forum}')); drupal_set_message(t('Successfully Imported %count forums.', array('%count' => $count))); } /** * Imports PHPBB topics to Drupal equivalent forum nodes */ function phpbb2drupal_import_topics() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0); $input_format = variable_get('phpbb2drupal_input_format', 0); // check if the post database has been successfully imported db_set_active('default'); if (variable_get('phpbb2drupal_import_topic_successful', 0)) { drupal_set_message(t('Topics already imported successfully')); return; } if (!variable_get('phpbb2drupal_import_topic_started', 0)) { db_set_active('default'); //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}'); //db_query("CREATE TABLE {phpbb2drupal_temp_topic} ( topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, nid integer UNSIGNED DEFAULT '0' NOT NULL, KEY topic_id (topic_id))"); variable_set('phpbb2drupal_import_topic_started', 1); } // Get All topics from PHPBB db_set_active('phpbb'); // topic_status == 2, Moved topics are duplicates don't import $topic_ids = db_query('SELECT topic_id FROM %stopics WHERE topic_vote <> 1 ORDER BY topic_id', $pre); $topic_count = db_num_rows($topic_ids); drupal_set_message(t('Found %topic_count topics: Beginning Import', array('%topic_count' => $topic_count))); // Import the topics into drupal $counter = 0; db_set_active('phpbb'); while ($result = db_fetch_object($topic_ids)) { // check if this topic has been imported already just to be sure db_set_active('default'); $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $result->topic_id)); if ($count > 0) { #print "