diff -urp ./drupalvb/drupalvb.inc.php ./drupalvb-patch/drupalvb.inc.php --- ./drupalvb/drupalvb.inc.php 2007-01-30 21:46:50.000000000 -0500 +++ ./drupalvb-patch/drupalvb.inc.php 2007-02-20 22:39:13.000000000 -0500 @@ -120,9 +120,8 @@ function _drupalvb_clear_cookies() { //Function to create an entry in the vB database user table function _drupalvb_create_vb_user($username, $password, $email, $silent = FALSE){ //Double check to make sure we're not duplicating an entry... - $result = db_query(_drupalvb_prefix("SELECT userid FROM {user} WHERE username = '%s'", $username)); - - if (db_fetch_array($result)) { + $result = db_query(_drupalvb_prefix("SELECT userid FROM {user} WHERE username = '%s'"), $username); + if(db_fetch_array($result)){ //The user existed somehow, so send the error and kick it out with a fail // Added by valcker: Skip pre-existing users without a message when exporting @@ -322,4 +321,4 @@ function _drupalvb_get_options() { function _drupalvb_prefix($sql) { $vbulletin = _drupalvb_vb_init(FALSE, TRUE, FALSE); return strtr($sql, array('{' => $vbulletin->config['Database']['tableprefix'], '}' => '')); -} \ No newline at end of file +} diff -urp ./drupalvb/drupalvb.module ./drupalvb-patch/drupalvb.module --- ./drupalvb/drupalvb.module 2007-01-30 21:46:50.000000000 -0500 +++ ./drupalvb-patch/drupalvb.module 2007-02-20 22:38:51.000000000 -0500 @@ -466,6 +466,7 @@ function drupalvb_admin_overview() { // Actions $items = null; $items[] = l(t('Export Drupal users to vBulletin'), 'drupalvb/actions/export'); + $items[] = l(t('Import vBulletin users to Drupal'), 'drupalvb/actions/import'); $output .= theme_item_list($items, t('Actions')); //Block configuration links @@ -671,19 +672,52 @@ function _drupalvb_export_drupal_users() } /** + * Added by kkronyak: Import all vBulletin users to Drupal + */ +function _drupalvb_import_vbulletin_users() { + //Turn off automatic vB if on since we know these accounts exist in vB! + global $conf; + $autocreate = variable_get('drupalvb_acct_generation', TRUE); + $conf['drupalvb_acct_generation'] = FALSE; + + db_set_active('vbulletin'); + $result = db_query(_drupalvb_prefix("SELECT username as name, password as pass, email as mail, userid FROM {user};")); + db_set_active('default'); + $count = 0; + while($vbuser = db_fetch_array($result)){ + if(!user_load(array('name' => $vbuser['name']))){ + if($vbuser['name'] && $vbuser['mail'] && $vbuser['pass']){ + unset($vbuser['userid']); + user_save(NULL, $vbuser); + }else{ + watchdog("drupalvb", "Invalid user data! Unable to import vBulletin userid: " . $vbuser['userid'], WATCHDOG_ERROR); + } + } + } + + $conf['drupalvb_acct_generation'] = $autocreate; +} + +/** * Added by valcker: An action handler for Drupal vB */ function drupalvb_action_handler($op = NULL) { if (is_null($op)) { drupal_set_message(t('Attempted to perform an unknown action.')); - drupal_goto('admin/drupalvb'); + drupal_goto('admin/settings/drupalvb'); } switch ($op) { case 'export': _drupalvb_export_drupal_users(); drupal_set_message(t('Drupal users exported to vBulletin database.')); - drupal_goto('admin/drupalvb'); + drupal_goto('admin/settings/drupalvb'); + break; + case 'import': + _drupalvb_import_vbulletin_users(); + drupal_set_message(t('vBulletin users imported to Drupal database.')); + drupal_goto('admin/settings/drupalvb'); + break; } }