From 6f3cf4463c97df4e1780f5e28bb10e21a70c6fc4 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Mon, 1 Mar 2010 20:49:12 +0200 Subject: updated --- gl2drupal.php | 170 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 48 deletions(-) diff --git a/gl2drupal.php b/gl2drupal.php index e9b0b22..952eebc 100755 --- a/gl2drupal.php +++ b/gl2drupal.php @@ -2,19 +2,23 @@ 'DBhost', @@ -34,13 +38,13 @@ foreach ($args as $k => $v) { } $dbpw = $opts['p']; -$dbhost = $opts['h']; +$dbhost = $opts['h'] . ":/Applications/MAMP/tmp/mysql/mysql.sock"; $dbuser = $opts['u']; $drupal_db = $opts['d']; $geeklog_db = $opts['g']; - $gl_tbl_prefix = "gl_"; -$db = mysql_connect($dbhost, $dbuser, $dbpw) or die(mysql_error() . "\n"); + +$db = mysql_connect($dbhost, $dbuser, $dbpw) or exit(mysql_error() . "\n"); // Add users mysql_query("DELETE FROM {$drupal_users}.users"); @@ -103,6 +107,7 @@ mysql_query("ALTER TABLE {$geeklog_db}.{$gl_tbl_prefix}stories DROP PRIMARY KEY" $sql = "ALTER TABLE {$geeklog_db}.{$gl_tbl_prefix}stories ADD `idx` INT AUTO_INCREMENT PRIMARY KEY"; mysql_query($sql); +// Clear all previous content mysql_query("DELETE FROM {$drupal_db}.node"); $sql =<< First comment to the second comment * 02.00.00/ -> Second comment to the first comment of the second comment */ + +// Clear all old comments mysql_query("DELETE FROM {$drupal_db}.comments"); $sql =<< $v) { - $thread .= str_pad($k) - } +// foreach($t as $k => $v) { +// $thread .= str_pad($k) +// } // $thread = $index . str_repeat(".{$index}", $indent) . '/'; $thread = implode('.', $t) . '/'; $comment = mysql_real_escape_string($row['comment']); @@ -243,10 +269,10 @@ while ($row = mysql_fetch_array($result)) VALUES ({$row['pid']}, {$row['idx']}, {$row['uid']}, '$subject', '$comment', '{$row['ipaddress']}', {$row['date']}, 0, 1, '{$thread}', '{$row['username']}', '{$row['email']}')"; - -// query($insert, "Inserting comment thread $thread"); - + query($insert, "Inserting comment thread $thread"); +echo "{$thread}\n"; } +//exit(); // Remap Anonymous user $sql = "UPDATE {$drupal_db}.comments SET `uid` = 0 WHERE `uid` = 1"; @@ -267,7 +293,7 @@ INSERT INTO {$drupal_db}.node_comment_statistics GROUP BY {$gl_tbl_prefix}stories.idx) EOS; -query( $sql, "Generating story comment counts" ); +query($sql, "Generating story comment counts"); // Restore forum comment coounts // Without this forum posts don't show up at all @@ -438,4 +464,52 @@ function result( $action ) { return "$out $result\n"; } +/** + * Flatten a modified pre-order traversal structure + * into the Drupal form. + * @param [string] $lft + * @param (string) $rht + * @param (string) $indent + * @param (string) $current the current path + * @return (string) a "node's" full path in Drupal notation + */ +function flatpot($lft, $rht, $indent, $current = '') +{ + $sql = "SELECT lft, rht, indent + FROM gl_comments + WHERE lft < $lft AND rht > $rht + ORDER BY lft ASC"; + $result = mysql_query($sql); + while ($row = mysql_fetch_assoc($result)) { + $path = $current . + $out .= flatpot($row['lft'], $row['rht'], $row['indent'], $path); + } + return $out; +} + +/** + * Generate vancode. + * + * Consists of a leading character indicating length, followed by N digits + * with a numerical value in base 36. Vancodes can be sorted as strings + * without messing up numerical order. + * + * It goes: + * 00, 01, 02, ..., 0y, 0z, + * 110, 111, ... , 1zy, 1zz, + * 2100, 2101, ..., 2zzy, 2zzz, + * 31000, 31001, ... + */ +function int2vancode($i = 0) { + $num = base_convert((int)$i, 10, 36); + $length = strlen($num); + return chr($length + ord('0') - 1) . $num; +} + +/** + * Decode vancode back to an integer. + */ +function vancode2int($c = '00') { + return base_convert(substr($c, 1), 36, 10); +} ?> \ No newline at end of file -- cgit v1.2.3