'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('Private forums') .'

'; $output .= '

'. t('Setup the private forums as explained in the documentation') .'

'; // Redirection from old URL: $output .= '

'. t('Redirection from phpBB2 forum URL to new Drupal forum 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('Remove BBcode module') .'

'; $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('Configure BBcode module') .'

'; $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 .= '

'. t('Avatars') .'

'; $output .= t('

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 = '
  1. '; $output .= t('You may want to check the documentation before starting.'); $output .= '
  2. '; $output .= '
  3. '; $output .= l(t('Configure the migration'), 'admin/settings/phpbb2drupal'); $output .= '
  4. '; $output .= '
  5. '; $output .= l(t('Execute the migration'), 'admin/phpbb2drupal/migrate'); $output .= '
  6. '; $output .= '
  7. '; $output .= l(t('Post migration configuration'), 'admin/phpbb2drupal/postconfiguration'); $output .= '
  8. '; $output .= '
  9. '; $output .= t('Cleanup (Accessing this link will delete all the saved phpbb2drupal settings and temporary tables: click only when you\'re done with all the above.)', array('%cleanuplink' => url('admin/phpbb2drupal/cleanup'))); $output .= '
  10. '; $output .= '
  11. '. t('If your data migration has proceeded smoothly, please post a "thank you" note in this forum topic at drupal.org.'); $output .= '
  12. '; $output .= '
'; // process will die() if the link to the phpBB2 database is wrong: $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'] = ''; return $out; } /** * Check if the sql tables are installed. * * @return array * $out['html'] = formatted html. * $out['result'] = boolean. */ function _phpbb2drupal_check_tables( $tables = array(), $db = 'default' , $prefix = 1) { _phpbb2drupal_db_connect() ; db_set_active($db); $out['html'] = ''; db_set_active('default'); return $out; } function phpbb2drupal_migrate() { if (!variable_get('phpbb2drupal_ready', 0)) { return '

'. 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 "

Topic $result->topic_id has already been imported

"; #flush(); db_set_active('phpbb'); continue; } db_set_active('phpbb'); /*$query = db_query("SELECT * FROM {topics} t INNER JOIN {posts} p ON t.topic_id = p.topic_id INNER JOIN {posts_text} pt ON p.post_id = pt.post_id WHERE t.topic_id = %d ORDER BY p.post_id LIMIT 1", $result->topic_id); /**/ $query = db_query('SELECT * FROM %stopics t INNER JOIN %sposts p ON t.topic_id = p.topic_id INNER JOIN %sposts_text pt ON p.post_id = pt.post_id WHERE p.post_id = t.topic_first_post_id AND t.topic_id = %d',$pre, $pre, $pre, $result->topic_id); // check if the topic is a valid topic. if not, continue on if (db_num_rows($query)) { $topic = db_fetch_object($query); } else { drupal_set_message(t('Could not find post details of topic: %topic_id', array('%topic_id' => $result->topic_id))); continue; } db_set_active('default'); $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster)); $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id)); if ($topic->topic_poster == 2) { // is the admin $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', ''))); $uid = $user->uid; } else if ($topic->topic_poster == -1) { $uid = 0; } if ($topic->topic_type == 1) { $sticky = 1; // sticky $promote = 0; } else if ($topic->topic_type == 2) { $sticky = 1; $promote = 0; // display on the front page, i.e. promote } else { $sticky = 0; $promote = 0; } if ($topic->topic_status == 1) { // LOCKED $comment = 1; // read-only } else { // UNLOCKED & WATCH NOTIFIED $comment = 2; // read-write } // remove the bbcode_uid from post_text $topic->post_text = preg_replace("/:$topic->bbcode_uid/", '', $topic->post_text); $topic->post_text = _phpbb2drupal_strip_bbcode($topic->post_text); $topic->post_text = _phpbb2drupal_text_encode($topic->post_text); $teaser = node_teaser($topic->post_text); //construct the node $node = array( 'type' => 'forum', 'title' => $topic->topic_title, 'uid' => $uid, 'status' => 1, // published or not - always publish 'promote' => $promote, 'created' => $topic->topic_time, 'changed' => $topic->post_edit_time, 'comment' => $comment, 'moderate' => 0, 'body' => $topic->post_text, 'sticky' => $sticky, 'format' => $input_format, 'teaser' => $teaser, ); $node['title'] = _phpbb2drupal_text_encode($node['title']); if ($topic->topic_status == 2) { db_set_active('phpbb'); $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id)); db_set_active('default'); $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id)); $node['tid'] = $moved_tid; // which forum it used to be part of } else { $node['tid'] = $tid; } $node = (object)$node; // node_save requires an object form db_set_active('default'); node_save($node); taxonomy_node_save($node->nid, array($tid)); if (!$node->nid) { drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id))); } // Handle attachments if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) { if ($topic->topic_attachment == 1) { db_set_active('default'); $file_path = variable_get('file_directory_path', 'files'); db_set_active('phpbb'); $files = db_query('SELECT * FROM %sattachments a INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id INNER JOIN %sposts p ON a.post_id = p.post_id WHERE p.topic_id = %d ORDER BY a.attach_id', $pre, $pre, $pre, $topic->topic_id); while ($file = db_fetch_object($files)) { db_set_active('default'); $fid = db_next_id('{files}_fid'); db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, $node->nid, substr($file->real_filename0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize); db_set_active('phpbb'); } } } db_set_active('default'); db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid); db_set_active('phpbb'); } // while ($result = db_fetch_object($topic_ids)) db_set_active('default'); // set the topic import successful flag in the variable table variable_set('phpbb2drupal_import_topic_successful', '1'); $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_topic}')); drupal_set_message(t('Successfully Imported %count topics', array('%count' => $count))); } /** * Imports phpBB polls into drupal */ function phpbb2drupal_import_polls() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $input_format = variable_get('phpbb2drupal_input_format', 0); db_set_active('default'); // check if the poll database has been successfully imported if (variable_get('phpbb2drupal_import_polls_successful', 0)) { drupal_set_message(t('Polls already imported successfully')); return; } if (!variable_get('phpbb2drupal_import_polls_started', 0)) { variable_set('phpbb2drupal_import_poll_started', 1); } // Get all polls from PHPBB db_set_active('phpbb'); $topics = db_query('SELECT * FROM %stopics t WHERE topic_vote = 1 ORDER BY topic_id', $pre); $topic_count = db_num_rows($topics); drupal_set_message(t('Found %poll_count polls: Beginning Import', array('%poll_count' => $topic_count))); // insert into polls while ($topic = db_fetch_object($topics)) { // 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', $topic->topic_id)); if ($count > 0) { drupal_set_message(t('Poll %topic_id has already been imported', array('%topic_id' => $result->topic_id))); db_set_active('phpbb'); continue; } // get the polls db_set_active('phpbb'); $query = db_query('SELECT * FROM %svote_desc vd WHERE topic_id = %d ORDER BY vote_id', $pre, $topic->topic_id); if (db_num_rows($query)) { $poll = db_fetch_object($query); } else { drupal_set_message(t('Could not find details of poll: %topic_id', array('%topic_id' => $topic->topic_id))); continue; } // get vote results $query = db_query('SELECT * FROM %svote_results WHERE vote_id = %d ORDER BY vote_option_id', $pre, $poll->vote_id); if (db_num_rows($query)) { $choice = array(); while ($result = db_fetch_object($query)) { $choice[] = array( 'chtext' => _phpbb2drupal_text_encode($result->vote_option_text), 'chvotes' => _phpbb2drupal_text_encode($result->vote_result), ); } } else { drupal_set_message(t('Could not find vote_results details of poll: %vote_id', array('%vote_id' => $poll->vote_id))); continue; } db_set_active('default'); $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster)); $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id)); if ($topic->topic_poster == 2) { // is the admin $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', ''))); $uid = $user->uid; } else if ($topic->topic_poster == -1) { $uid = 0; } if ($topic->topic_type == 1) { $sticky = 1; // sticky $promote = 0; } else if ($topic->topic_type == 2) { $sticky = 0; $promote = 1; // display on the front page, i.e. promote } else { $sticky = 0; $promote = 0; } if ($topic->topic_status == 1) { // LOCKED $comment = 1; // read-only } else { // UNLOCKED & WATCH NOTIFIED $comment = 2; // read-write } //construct the node $node = array( 'type' => 'poll', 'title' => $poll->vote_text, 'uid' => $uid, 'status' => 1, // published or not - always publish 'promote' => $promote, 'created' => $topic->topic_time, 'changed' => $topic->topic_time, 'comment' => $comment, 'moderate' => 0, 'body' => '', 'format' => $input_format, 'sticky' => $sticky, // 'teaser' => $teaser ); $node['title'] = _phpbb2drupal_text_encode($node['title']); // handle moved nodes if ($topic->topic_status == 2) { db_set_active('phpbb'); $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id)); db_set_active('default'); $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id)); $node['tid'] = $moved_tid; // which forum it used to be part of } else { $node['tid'] = $tid; } // Add poll node information $node['runtime'] = $poll->vote_length; $node['active'] = (time() > ($poll->start + $poll->length)) ? 0 : 1; $node['choice'] = $choice; $node = (object)$node; // node_save requires an object form db_set_active('default'); node_save($node); taxonomy_node_save($node->nid, array($tid)); if (!$node->nid) { drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id))); } // get voter information db_set_active('phpbb'); $query = db_query('SELECT vote_user_id FROM %svote_voters WHERE vote_id = %d ORDER BY vote_id', $pre, $poll->vote_id); // manually update the poll table to store the uid of those who voted if (db_num_rows($query)) { db_set_active('phpbb'); while ($result = db_fetch_object($query)) { db_set_active('default'); $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $result->vote_user_id)); $result = db_query('INSERT INTO {poll_votes} (nid, uid, hostname) VALUES (%d, %d, \'NA\')', $node->nid, $uid); db_set_active('phpbb'); } } db_set_active('default'); db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid); phpbb2_drupal_poll_insert($node); db_set_active('phpbb'); } db_set_active('default'); // set the topic import successful flag in the variable table variable_set('phpbb2drupal_import_poll_successful', '1'); drupal_set_message(t('Successfully imported polls')); } /** * PHPBB Posts --> Drupal Comments */ function phpbb2drupal_import_posts() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0); db_set_active('default'); // check if the post database has been successfully imported if (variable_get('phpbb2drupal_import_post_successful', 0)) { drupal_set_message(t('Posts already imported successfully')); return; } if (!variable_get('phpbb2drupal_import_post_started', 0)) { db_set_active('default'); //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_post}'); /*db_query("CREATE TABLE {phpbb2drupal_temp_post} ( post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, cid int(10) DEFAULT '0' NOT NULL, KEY post_id (post_id))" ); */ db_set_active('default'); variable_set('phpbb2drupal_import_post_started', 1); } db_set_active('phpbb'); $topic_ids = db_query('SELECT topic_id, topic_vote, topic_first_post_id, topic_last_post_id FROM %stopics WHERE topic_replies > 0 ORDER BY topic_id', $pre); $topic_count = db_num_rows($topic_ids); drupal_set_message(t('Found %post_count posts: Beginning Import', array('%post_count' => $topic_count))); $errors = 0; $loops = 0; // Import the posts into drupal while ($obj = db_fetch_object($topic_ids)) { $loops++; // skip first post if the post is not a poll // stupid phpbb... make the way you store topics consistent for crying out loud db_set_active('phpbb'); if ($obj->topic_vote == 0) { $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d AND post_id <> %d ORDER BY post_id', $pre, $obj->topic_id, $obj->topic_first_post_id); } else { $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d ORDER BY post_id', $pre, $obj->topic_id); } unset($obj); while ($result = db_fetch_object($post_ids)) { $loops++; db_set_active('phpbb'); /* $query = db_query("SELECT * FROM {posts} p INNER JOIN {posts_text} pt ON p.post_id = pt.post_id WHERE p.post_id = %d", $result->post_id); //*/ $query = db_query('SELECT * FROM %sposts p, %sposts_text pt WHERE p.post_id = pt.post_id AND p.post_id = %d', $pre, $pre, $result->post_id); // make sure the post is valid if (db_num_rows($query)) { $post = db_fetch_object($query); } else { $errors++; drupal_set_message(t("Couldn't find post text for %post_id", array('%post_id' => $result->post_id))); continue; } // skip if the post has already been imported db_set_active('default'); $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post->post_id)); if ($count > 0) { $errors++; drupal_set_message(t('Post %post_id was already inserted', array('%post_id' => $post->post_id))); db_set_active('phpbb'); continue; } db_set_active('default'); $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $post->poster_id)); $pid = db_result(db_query('SELECT MAX(pid) FROM {comments} WHERE nid = %d', $nid)); // get the node ID. The title may be useful further down if the comment doesn't have its own title. $node = (db_fetch_object(db_query('SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid WHERE topic_id = %d', $post->topic_id))); $nid = $node->nid; $pid = (is_null($pid)) ? 0 : $pid; if ($post->poster_id == 2) { // is the admin $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', ''))); $uid = $user->uid; } else if ($post->poster_id == -1) { // anonymous $uid = 0; } $hostname = phpbb2drupal_decode_ip($post->poster_ip); // remove the :bbcode_uid from post_text $post->post_text = preg_replace("/:$post->bbcode_uid/", '', $post->post_text); $post->post_text = _phpbb2drupal_strip_bbcode($post->post_text); $post->post_text = _phpbb2drupal_text_encode($post->post_text); $post->post_subject = _phpbb2drupal_text_encode($post->post_subject); //construct the node $comment = array( 'pid' => $pid, 'nid' => $nid, 'uid' => $uid, 'subject' => $post->post_subject, 'comment' => $post->post_text, 'hostname' => $hostname, 'timestamp' => $post->post_time ); // if the title field is empty, use the node title as default. if (empty($comment['subject'])) { $comment['subject'] = $node->title; } db_set_active('default'); $cid = phpbb2drupal_comment_save($comment); if (!$cid) { $errors++; drupal_set_message(t('Failed importing %post_id', array('%post_id' => $post->post_id))); } // Handle attachments if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) { if ($post->post_attachment == 1) { db_set_active('default'); $file_path = variable_get('file_directory_path', 'files'); db_set_active('phpbb'); $files = db_query('SELECT * FROM %sattachments a INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id WHERE a.post_id = %d', $pre, $pre, $post->post_id); while ($file = db_fetch_object($files)) { db_set_active('default'); $fid = db_next_id('{files}_fid'); db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, 0, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize); db_query('INSERT INTO {comment_files} (cid, fid) VALUES (%d, %d)', $cid, $fid); db_set_active('phpbb'); } } } db_set_active('default'); db_query('INSERT INTO {phpbb2drupal_temp_post} (post_id, cid) VALUES (%d, %d)', $post->post_id, $cid); db_set_active('phpbb'); } } // set the post import successful flag in the variable table db_set_active('default'); variable_set('phpbb2drupal_import_post_successful', '1'); drupal_set_message(t('Successfully Imported %imported posts', array('%imported' => $imported))); drupal_set_message(t('The were %loops loops executed', array('%loops' => $loops))); drupal_set_message(t('There %errors errors while importing posts', array('%errors' => $errors))); } /** * Clean UP */ function phpbb2drupal_import_cleanup() { $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_'); # # Update Drupal sequence # db_set_active('default'); $term_data_tid = db_result(db_query('SELECT MAX(tid) FROM {term_data}')); $comments_cid = db_result(db_query('SELECT MAX(cid) FROM {comments}')); $node_nid = db_result(db_query('SELECT MAX(nid) FROM {node}')); $users_uid = db_result(db_query('SELECT MAX(uid) FROM {users}')); db_query("DELETE FROM {sequences} WHERE name='term_data_tid'"); db_query("DELETE FROM {sequences} WHERE name='comments_cid'"); db_query("DELETE FROM {sequences} WHERE name='node_nid'"); db_query("DELETE FROM {sequences} WHERE name='users_uid'"); db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', '%s')", $term_data_tid); db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', '%s')", $comments_cid); db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', '%s')", $node_nid); db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', '%s')", $users_uid); if (variable_get('phpbb2drupal_import_attachments', 0)) { $files_fid = db_result(db_query('SELECT MAX(fid) FROM {files}')); if (!$files_fid) { //may be NULL $files_fid = 0; } db_query("DELETE FROM {sequences} WHERE name='files_fid'"); db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', '%s')", $files_fid); } // don't DROP: the data is used for redirects from old forum. #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_user}"); #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}"); #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}"); #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_post}"); variable_del('phpbb2drupal_import_user_successful'); variable_del('phpbb2drupal_import_user_started'); variable_del('phpbb2drupal_import_category_successful'); variable_del('phpbb2drupal_replace_url_successful'); variable_del('phpbb2drupal_import_category_started'); variable_del('phpbb2drupal_import_topic_successful'); variable_del('phpbb2drupal_import_topic_started'); variable_del('phpbb2drupal_import_post_successful'); variable_del('phpbb2drupal_import_post_started'); variable_del('phpbb2drupal_ready'); variable_del('phpbb2drupal_regdate_us_english'); variable_del('phpbb2drupal_input_format'); variable_del('phpbb2drupal_db_url'); variable_del('phpbb2drupal_tested'); variable_del('phpbb2drupal_same_db'); variable_del('phpbb2drupal_table_prefix'); variable_del('phpbb2drupal_time_limit'); variable_del('phpbb2drupal_import_spammers'); variable_del('phpbb2drupal_import_attachments'); variable_del('phpbb2drupal_import_polls'); variable_del('phpbb2drupal_import_pm'); variable_del('phpbb2drupal_import_poll_started'); variable_del('phpbb2drupal_import_poll_successful'); variable_del('phpbb2drupal_import_pm_successful'); variable_del('phpbb2drupal_admin_user'); variable_del('phpbb2drupal_encode'); variable_del('phpbb2drupal_encoding_phpbb'); variable_del('phpbb2drupal_encoding_drupal'); db_query('DELETE FROM {cache}'); } /** * Helper Functions */ function phpbb2drupal_user_save($phpBB_user, $category = array()) { if (!($user = user_load(array('name' => $phpBB_user['name'])))) { $account = new StdClass(); $account->uid = FALSE; $user = user_save($account, $phpBB_user); //Drupal overrides the phpBB user registration date when creating a Drupal account. //so we need to update it here. $user = user_save($user, array('created' => $phpBB_user['created'])); // Update the password: just import the md5() hash straight into Drupal without // passing through the Drupal function user_save() which would re-hash the hash. $result = db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $phpBB_user['pass'], $user->uid); } $phpBB_user['uid'] = $user->uid; db_set_active('default'); phpbb2drupal_profile_save_profile($phpBB_user, $user, $category); // add user profile information return $user; } function phpbb2drupal_profile_save_profile(&$edit, &$user, $category) { $result = db_query('SELECT fid, name, type, category, weight FROM {profile_fields} WHERE register = 1 ORDER BY category, weight'); while ($field = db_fetch_object($result)) { if (_profile_field_serialize($field->type)) { $edit[$field->name] = serialize($edit[$field->name]); } db_query('DELETE FROM {profile_values} WHERE fid = %d AND uid = %d', $field->fid, $user->uid); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); // Mark field as handled (prevents saving to user->data). $edit[$field->name] = NULL; } } function phpbb2drupal_comment_save($edit) { db_set_active('default'); // Here we are building the thread field. See the comment // in comment_render(). if ($edit['pid'] == 0) { // This is a comment with no parent comment (depth 0): we start // by retrieving the maximum thread level. $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid'])); // Strip the "/" from the end of the thread. $max = rtrim($max, '/'); $thread = int2vancode(vancode2int($max)+1) . '/'; } else { // This is comment with a parent comment: we increase // the part of the thread value at the proper depth. // Get the parent comment: $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid'])); // Strip the "/" from the end of the parent thread. $parent->thread = (string) rtrim((string) $parent->thread, '/'); // Get the max value in _this_ thread. $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid'])); if ($max == '') { // First child of this parent. $thread = $parent->thread .'.'.int2vancode(1).'/'; } else { // Strip the "/" at the end of the thread. $max = rtrim($max, '/'); // We need to get the value at the correct depth. $parts = explode('.', $max); $parent_depth = count(explode('.', $parent->thread)); $last = $parts[$parent_depth]; // Finally, build the thread field for this new comment. $thread = $parent->thread .'.'.int2vancode(vancode2int($last) + 1) .'/'; } } $edit['cid'] = db_next_id('{comments}_cid'); $status = 0; // 1 - not published, 0 - published $format = variable_get('phpbb2drupal_input_format', 0); $score = 0; // 0 default value, comments get higher score depending on the author's roles $users = serialize(array(0 => 1)); // default value for everybody!! db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], substr($edit['subject'], 0, 64), $edit['comment'], $format, substr($edit['hostname'], 0, 128), $edit['timestamp'], $status, $score, $users, substr($thread, 0, 255), substr($edit['name'], 0, 60), substr($edit['mail'], 0, 64), substr($edit['homepage'], 0, 255)); _comment_update_node_statistics($edit['nid']); return $edit['cid']; } /** * function for inserting polls into drupal */ function phpbb2_drupal_poll_insert($node) { if (!variable_get('phpbb2drupal_import_polls', 0)) { return 1; } if (!user_access('administer nodes')) { // Make sure all votes are 0 initially foreach ($node->choice as $i => $choice) { $node->choice[$i]['chvotes'] = 0; } $node->active = 1; } db_query('INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)', $node->nid, $node->runtime, $node->active); foreach ($node->choice as $choice) { if ($choice['chtext'] != '') { db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, substr($choice['chtext'], 0, 128), $choice['chvotes'], $i++); } } } /** * PHPBB function for decoding the user ip */ function phpbb2drupal_decode_ip($int_ip) { $hexipbang = explode('.', chunk_split($int_ip, 2, '.')); return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]); } /** * If requested, strips all bbcode from text. */ function _phpbb2drupal_strip_bbcode($text) { if (variable_get('phpbb2drupal_bbcode', 0)) { $input_format = variable_get('phpbb2drupal_input_format', 0); $text = bbcode_filter('process', 0 , $input_format, $text); } return $text; } /** * function to properly encode strings. */ function _phpbb2drupal_text_encode($text) { if (!variable_get('phpbb2drupal_encode', 0)) { return $text; } $text = mb_convert_encoding($text, variable_get('phpbb2drupal_encoding_drupal', 'utf-8'), variable_get('phpbb2drupal_encoding_phpbb', 'iso-8859-1')); return $text; } // grep replace functions. function _phpbb2drupal_replace_links_topic($matches) { //print_r($matches); $result = db_result(db_query('SELECT nid FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $matches[1])); $link = 'node/'. $result . $matches[2]; return $link; } function _phpbb2drupal_replace_links_post($matches) { //print_r($matches); $result = db_fetch_object(db_query('SELECT c.cid, c.nid FROM {phpbb2drupal_temp_post} p JOIN {comments} c ON c.cid = p.cid WHERE post_id = %d', $matches[1])); $link = 'node/'. $result->nid . '#comment-' . $result->cid . $matches[3]; return $link; } function _phpbb2drupal_replace_links_forum($matches) { //print_r($matches); $result = db_fetch_object(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $matches[1])); $link = 'forum/'. $result->tid . $matches[2] ; return $link; } /** * Replace all types of links. */ function _phpbb2drupal_replace_links($html) { $html = preg_replace_callback('{forum/viewtopic.php\?p=(\d+)#(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|"|\]])}i', '_phpbb2drupal_replace_links_post', $html); $html = preg_replace_callback('{forum/viewtopic.php\?t=(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|"|\]])}i', '_phpbb2drupal_replace_links_topic', $html); $html = preg_replace_callback('{forum/viewforum.php\?f=(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|"|\]])}i', '_phpbb2drupal_replace_links_forum', $html); // TODO look at removing $1. it looks like dead code. $html = preg_replace('{forum/index.php[^"|\'|>|\s|\]]*(["|\'|<|>|\s|\\|"|\]])}i', "forum$1", $html); // You can use the line below to test locally the url's when you are testing: //$html = preg_replace("{www.reuniting.info}i", "127.0.0.1/drupal", $html); return $html; } /** * Replace URLs to old phpBB forum to new Drupal forum */ function phpbb2drupal_replace_url() { db_set_active('default'); // transform nodes: // As the topics have just been imported, there is only one vid for each nid, // so the query works as it is. $result = db_query('SELECT ptt.nid, n.body, n.teaser FROM {phpbb2drupal_temp_topic} AS ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid'); while ($node = db_fetch_object($result)) { $node->body = _phpbb2drupal_replace_links($node->body); $node->teaser = _phpbb2drupal_replace_links($node->teaser); db_query("UPDATE {node_revisions} SET body= '%s', teaser = '%s' WHERE nid = %d", $node->body, $node->teaser, $node->nid); } // transform comments: $result = db_query('SELECT c.cid, c.comment FROM {phpbb2drupal_temp_post} AS p LEFT JOIN {comments} AS c ON p.cid = c.cid'); while ($comment = db_fetch_object($result)) { $comment->comment = _phpbb2drupal_replace_links($comment->comment); db_query("UPDATE {comments} SET comment= '%s' WHERE cid = %d", $comment->comment, $comment->cid); } variable_set('phpbb2drupal_replace_url_successful', '1'); }