| 1 |
<?php |
<?php |
| 2 |
// $Id: drupalvb.batch.inc,v 1.1.2.1 2009/05/29 10:23:19 sun Exp $ |
// $Id: drupalvb.batch.inc,v 1.1.2.2 2009/06/05 15:03:20 sun Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 16 |
// Need to re-index display order because vB chokes on negative values. |
// Need to re-index display order because vB chokes on negative values. |
| 17 |
$displayorder = 1; |
$displayorder = 1; |
| 18 |
|
|
| 19 |
|
// Root forums in Drupal should be moved into a category in vBulletin, |
| 20 |
|
// otherwise the administration page gets cluttered. |
| 21 |
|
$forumid = 1; |
| 22 |
|
$main_category = (fetch_foruminfo($forumid) ? $forumid : -1); |
| 23 |
|
|
| 24 |
// Fetch one level of the term hierarchy. |
// Fetch one level of the term hierarchy. |
| 25 |
$forums = taxonomy_get_tree(variable_get('forum_nav_vocabulary', ''), $parent, -1, 1); |
$forums = taxonomy_get_tree(variable_get('forum_nav_vocabulary', ''), $parent, -1, 1); |
| 26 |
foreach ($forums as $forum) { |
foreach ($forums as $forum) { |
| 37 |
$vbforum->set('daysprune', -1); |
$vbforum->set('daysprune', -1); |
| 38 |
$parentid = array_shift($forum->parents); |
$parentid = array_shift($forum->parents); |
| 39 |
if ($parentid > 0) { |
if ($parentid > 0) { |
| 40 |
|
// Regular forums are placed at their parent. |
| 41 |
$parentid = drupalvb_get_vb_id('forums', $parentid); |
$parentid = drupalvb_get_vb_id('forums', $parentid); |
| 42 |
} |
} |
| 43 |
elseif ($forum->container) { |
elseif ($forum->container) { |
| 44 |
|
// Containers are placed at the root level. |
| 45 |
$parentid = -1; |
$parentid = -1; |
| 46 |
} |
} |
| 47 |
else { |
else { |
| 48 |
// Move all root forums to vB's Main category (if available). |
// Root forums are moved into a category. |
| 49 |
$forumid = 1; |
$parentid = $main_category; |
|
$parentid = (fetch_foruminfo($forumid) ? $forumid : -1); |
|
| 50 |
} |
} |
| 51 |
$vbforum->set('parentid', $parentid); |
$vbforum->set('parentid', $parentid); |
| 52 |
|
|
| 53 |
// Geez, vB has no defaults for forum options... |
// Geez, vB has absolutely no defaults for forum options... |
| 54 |
$vbforum->set_bitfield('options', 'cancontainthreads', !$forum->container); |
$vbforum->set_bitfield('options', 'cancontainthreads', !$forum->container); |
| 55 |
$vbforum->set_bitfield('options', 'active', TRUE); |
$vbforum->set_bitfield('options', 'active', TRUE); |
| 56 |
$vbforum->set_bitfield('options', 'allowposting', !$forum->container); |
$vbforum->set_bitfield('options', 'allowposting', !$forum->container); |
| 124 |
if (!$account->uid) { |
if (!$account->uid) { |
| 125 |
return; |
return; |
| 126 |
} |
} |
| 127 |
$userid = drupalvb_create_user($account, (array)$account); |
$userid = drupalvb_synchronize_user($account); |
| 128 |
if (!$userid) { |
if (!$userid) { |
| 129 |
$context['results']['errors'][] = t('Failed creating user @name', array('@name' => $account->name)); |
$context['results']['errors'][] = t('Failed creating user @name', array('@name' => $account->name)); |
| 130 |
return; |
return; |
| 191 |
if (!$userid) { |
if (!$userid) { |
| 192 |
// Create account first. |
// Create account first. |
| 193 |
$account = user_load(array('uid' => $comment->uid)); |
$account = user_load(array('uid' => $comment->uid)); |
| 194 |
$userid = drupalvb_create_user($account, (array)$account); |
if (!$account->uid) { |
| 195 |
|
unset($vbpost); |
| 196 |
|
continue; |
| 197 |
|
} |
| 198 |
|
$userid = drupalvb_synchronize_user($account); |
| 199 |
if (!$userid) { |
if (!$userid) { |
| 200 |
$context['results']['errors'][] = t('Failed mapping user @name', array('@name' => $account->name)); |
$context['results']['errors'][] = t('Failed mapping user @name', array('@name' => $account->name)); |
| 201 |
|
unset($vbpost); |
| 202 |
continue; |
continue; |
| 203 |
} |
} |
| 204 |
} |
} |
| 252 |
'file' => $path . '/drupalvb.batch.inc', |
'file' => $path . '/drupalvb.batch.inc', |
| 253 |
); |
); |
| 254 |
$forums = array(); |
$forums = array(); |
| 255 |
$result = drupalvb_db_query("SELECT forumid FROM {forum} WHERE (options & " . $vbulletin->bf_misc_forumoptions['countposts'] . ")"); |
$result = drupalvb_db_query("SELECT forumid FROM {forum} WHERE (options & " . $vbulletin->bf_misc_forumoptions['countposts'] . ")"); |
| 256 |
while ($forum = db_fetch_array($result)) { |
while ($forum = db_fetch_array($result)) { |
| 257 |
$forums[] = $forum['forumid']; |
$forums[] = $forum['forumid']; |
| 258 |
} |
} |
| 259 |
$forums = implode(',', $forums); |
$forums = implode(',', $forums); |
| 260 |
|
|
| 261 |
foreach (array_keys($context['results']['userids']) as $userid) { |
foreach (array_keys($context['results']['userids']) as $userid) { |
| 306 |
$existing = array('userid' => $userid); |
$existing = array('userid' => $userid); |
| 307 |
$vbuser->set_existing($existing); |
$vbuser->set_existing($existing); |
| 308 |
$stats = db_fetch_array(drupalvb_db_query("SELECT MAX(p.postid) AS lastpostid, MAX(p.dateline) AS lastpost, COUNT(*) AS posts |
$stats = db_fetch_array(drupalvb_db_query("SELECT MAX(p.postid) AS lastpostid, MAX(p.dateline) AS lastpost, COUNT(*) AS posts |
| 309 |
FROM {post} p |
FROM {post} p |
| 310 |
INNER JOIN {thread} t ON t.threadid = p.threadid |
INNER JOIN {thread} t ON t.threadid = p.threadid |
| 311 |
WHERE p.userid = %d AND t.forumid IN (%s) AND t.visible = 1 AND p.visible = 1", $userid, $forums)); |
WHERE p.userid = %d AND t.forumid IN (%s) AND t.visible = 1 AND p.visible = 1", $userid, $forums)); |
| 312 |
$vbuser->set('posts', $stats['posts']); |
$vbuser->set('posts', $stats['posts']); |
| 313 |
$vbuser->set_ladder_usertitle($stats['posts']); |
$vbuser->set_ladder_usertitle($stats['posts']); |
| 314 |
$vbuser->set('lastpost', $stats['lastpost']); |
$vbuser->set('lastpost', $stats['lastpost']); |
| 315 |
$vbuser->set('lastpostid', $stats['lastpostid']); |
$vbuser->set('lastpostid', $stats['lastpostid']); |
| 316 |
$vbuser->save(); |
$vbuser->save(); |
| 317 |
|
|
| 318 |
$context['message'] = t('Updating user information'); |
$context['message'] = t('Updating user information'); |
| 319 |
} |
} |
| 359 |
require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc'; |
require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc'; |
| 360 |
|
|
| 361 |
$account = user_load(array('uid' => $uid)); |
$account = user_load(array('uid' => $uid)); |
| 362 |
if ($account && !drupalvb_create_user($account, (array)$account)) { |
if ($account->uid) { |
| 363 |
// Username already exists, update. |
drupalvb_synchronize_user($account); |
| 364 |
drupalvb_update_user($account, (array)$account); |
$context['message'] = t('Exported user @username', array('@username' => $account->name)); |
| 365 |
|
} |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
/** |
| 369 |
|
* Update privatemsg counts in vBulletin. |
| 370 |
|
*/ |
| 371 |
|
function drupalvb_export_privatemsg($recipient, $pmtotal, $pmunread, &$context) { |
| 372 |
|
require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc'; |
| 373 |
|
|
| 374 |
|
// Verify that recipient exists in vB. |
| 375 |
|
$userid = drupalvb_get_vb_id('users', $recipient); |
| 376 |
|
if (!$userid) { |
| 377 |
|
$account = user_load(array('uid' => $recipient)); |
| 378 |
|
if (!$userid = drupalvb_synchronize_user($account)) { |
| 379 |
|
return; |
| 380 |
|
} |
| 381 |
} |
} |
| 382 |
|
|
| 383 |
|
// Update counts for user. |
| 384 |
|
$vbuser = &drupalvb_datamanager_init('User'); |
| 385 |
|
$existing = array('userid' => $userid); |
| 386 |
|
$vbuser->set_existing($existing); |
| 387 |
|
$vbuser->set('pmtotal', $pmtotal); |
| 388 |
|
$vbuser->set('pmunread', $pmunread); |
| 389 |
|
$vbuser->save(); |
| 390 |
} |
} |
| 391 |
|
|
| 392 |
function drupalvb_export_finished($success, $results, $operations) { |
function drupalvb_export_finished($success, $results, $operations) { |