Script för sammanslagning av flera phpbb 2.0.22 forum.

Frågor kring MODdar (modifikationer) för phpBB 2.0.x.

Moderatorer: Moderatorgrupp, Supportgrupp

houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Du hade rätt...
Hittar inget spontant...
Sökte på scriptnamnet och fick detta:

Kod: Markera allt

/Users/admin/Desktop/temp-000000.log:314205:  217.211.56.158 - - [29/Jul/2007:23:02:08 +0200] "GET /forum/m/merge_phpbb.php HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11 (KHTML, like Gecko) Version/3.0.2 Safari/522.12"
Säger det dig något alls?
mvh
Janne A.
Användarens profilbild
tumba25
Hedersmedlem
Hedersmedlem
Inlägg: 2097
Blev medlem: 2007-04-18 09:38
Svar: 0
Ort: Kokkola, Finland.

Inlägg av tumba25 »

Jupp, det var ju access-loggen. Finns det ingen log som heter error-log eller liknande. Det är den som är intressant i sammanhanget.

/J
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Nej ingen specifik error log säger One support....
Nåt mer vi kan göra? Svårt detta.... :(

mvh
Janne A.
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Tiden börjar rinna ut för mig med detta....
Finns det professionell hjälp att få via detta forum, betald?
Jag kan då kola med skolan om de är ok med detta...men jag får inte till detta själv...
mvh
Janne A.
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Hej igen,

Har flytatt hela klabbet till min lokala dator, där jag har error log...puh...

Får ett fel i php_error loggen:

Kod: Markera allt

[04-Aug-2007 10:11:07] PHP Parse error:  syntax error, unexpected T_STRING, expecting ')' in /Library/Application Support/living-e/MAMP PRO/mamp/m/mer.php on line 37
Line 37 är raden med "config"
ser inget fel..?

Kod: Markera allt

// These tables can be dropped from DB2 (not used in this script)
$drop_tables = array(
   "config",
   "banlist",
   "disallow",
   "search_results",
   "search_wordlist",
   "search_wordmatch",
   "sessions",
   "smilies",
Ser du något som jag kan prova?

mvh
Janne A.
Användarens profilbild
tumba25
Hedersmedlem
Hedersmedlem
Inlägg: 2097
Blev medlem: 2007-04-18 09:38
Svar: 0
Ort: Kokkola, Finland.

Inlägg av tumba25 »

Visa lite mer av skriptet både före och efter. Rad 37 enligt ditt första inlägg är

Kod: Markera allt

include($phpbb_root_path . 'extension.inc');
.

Jag får fel på rad 129 enligt ditt första inlägg

Kod: Markera allt

array("attach_quota", "user_id")
den raden ska sluta med ett kommatecken.

Kolla också i början på skriptet så inte ordet "only" är på en egen rad som inte är kommentarsmarkerad.

/J
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Äntligen delvis framgång..... :)
Scriptet mergar nu allt utom det vi adderat, för att merga Smartor's album... :oops:
Får nu ett SQL error...

Nåt tips vad som ä r fel nu,... enl. meddelandet runt line 309?
mvh
Janne A.

Felet som jag ser i browsern när jag kör scriptet browser:

Kod: Markera allt

Merging table : album

album OK
Merging album_comment table:
Merging table : album_comment

album_comment

SQL Error : 1062 Duplicate entry '1' for key 1

INSERT INTO afff_se.phpbbm1_album_comment (comment_id, comment_pic_id, comment_user_id, comment_username, comment_user_ip, comment_time, comment_text, comment_edit_time, comment_edit_count, comment_edit_user_id) SELECT comment_id, comment_pic_id, comment_user_id, comment_username, comment_user_ip, comment_time, comment_text, comment_edit_time, comment_edit_count, comment_edit_user_id from afff_se.2006phpbb_album_comment

Line : 309
File : /Library/Application Support/living-e/MAMP PRO/mamp/m/MergeScript_wAlbum.php
Scriptet som annars nu fungerar:

Kod: Markera allt

<?php

$dbms = 'mysql';
$phpbb_root_path = '../m/';

$dbhost = 'localhost';

$dbuser = 'root';
$dbpasswd = 'secretword';

// Name and prefix for the database that should keep the original IDs

$dbname1 = 'afff_se';
$table_prefix1 = 'phpbbm1_';

// Name and prefix for the database that is going to be added
// to DB1.
$dbname2 = 'afff_se';
$table_prefix2 = '2006phpbb_';


# NO NEED TO MODIFY CODE BELOW
# MODIFY ONLY IF U KNOW WHAT U R DOING


define('IN_PHPBB', true);
// Use DB1 for the initial config table etc.
$dbname = $dbname1;
$table_prefix = $table_prefix1;
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);


// These tables can be dropped from DB2 (not used in this script)
$drop_tables = array(
   "config",
   "banlist", // This one could be converted
   "disallow",
   "search_results",
   "search_wordlist",
   "search_wordmatch",
   "sessions",
   "smilies",
   "themes",
   "themes_name",
   "words"
   );
   
// All tables in DB2 that should shift ID.
//  - table that needs shifting (categories)
//  - id in table (cat_id)
//    nested array:
//    - table that depends on id (forums)
//    - id that corresponds to id in original table (cat_id)
$shift_tables = array(
   "categories" => array(
      "cat_id", 
      array(
         array("forums", "cat_id")
      )
   ),
   "forums" => array(
      "forum_id",
      array(
         array("posts", "forum_id"),
         array("topics", "forum_id"),
         array("forum_prune", "forum_id"),
         array("auth_access", "forum_id")
      )
   ),
   "forum_prune" => array(
      "prune_id",
      array()
   ),
   "groups" => array(
      "group_id",
      array(
         array("user_group", "group_id"),
         array("auth_access", "group_id")
      )
   ),
   "posts" => array(
      "post_id",
      array(
         array("posts_text", "post_id"),
         array("topics", "topic_first_post_id"),
         array("topics", "topic_last_post_id")
      )
   ),
   "privmsgs" => array(
      "privmsgs_id",
      array(
         array("privmsgs_text", "privmsgs_text_id"),
         array("users", "user_last_privmsg")
      )
   ),
   "topics" => array(
      "topic_id",
      array(
         array("posts", "topic_id"),
         array("topics_watch", "topic_id"),
         array("vote_desc", "topic_id")
      )
   ),
   "users" => array(
      "user_id",
      array(
         array("user_group", "user_id"),
         array("groups", "group_moderator"),
         array("posts", "poster_id"),
         array("topics", "topic_poster"),
         array("privmsgs", "privmsgs_to_userid"),
         array("privmsgs", "privmsgs_from_userid"),
         array("topics_watch", "user_id"),
         array("vote_voters", "vote_user_id"),
         array("album", "pic_user_id"),
         array("album_comment", "comment_user_id"),
         array("album_comment", "comment_edit_user_id"),
         array("album_rate", "rate_user_id")
      )
   ),
   "album" => array(
      "pic_id",
      array(
         array("album_comment", "comment_pic_id"),
         array("album_rate", "rate_pic_id")
      )
   ),
   "album_cat" => array(
      "cat_id",
      array(
         array("album", "pic_cat_id")
      )
   ),
   "ranks" => array(
      "rank_id",
      array(
         array("users", "user_rank")
      )
   ),
   "vote_desc" => array(
      "vote_id",
      array(
         array("vote_voters", "vote_id"),
         array("vote_results", "vote_id")
      )
   )
);

$bla_tables = array(
   "auth_access",
   "user_group",
   "posts_text",
   "privmsgs_text",
   "topics_watch",
   "vote_results",
   "vote_voters"
   );


// Traverse the shift_tables array

foreach($shift_tables as $key => $value)
{
   $table = $key;
   $merge_tables[$table] = 0; // keep an array with all tables that need merging
   $column = $value[0]; // Column with ID that needs to be shifted
   $ref = $value[1]; // Tables that are using the mentioned ID.
   print "Shifting IDs in table $table<br />\n";
   $max = shift_ids($table, $column);
   flush();
   // Do the dependent tables
   foreach($ref as $key => $value)
   {
      $d_table = $value[0];
      $merge_tables[$d_table] = 0;
      $d_column = $value[1];
      print "&nbsp; Altering dependent table: $d_table : $d_column (offset = $max)<br />\n";
      flush();
      shift_ids($d_table, $d_column, $max);
   }
   
   print "<br />\n";
   flush();
}

foreach($merge_tables as $table => $value)
{
   print "Merging $table table: ";
   if(merge_tables($table))
   {
      print " OK<br />\n";
   }
   else
   {
      print " FAILED!<br />\n";
   }
}

print "Merging users (username and either password or email are the same).<br />";
$sql = "
   SELECT
      u1.user_id as id1, 
      u2.user_id as id2, 
      u1.username
   FROM
      " . USERS_TABLE . " u1,
      " . USERS_TABLE . " u2
   WHERE
      u1.username = u2.username
      && (u1.user_password = u2.user_password
         || u1.user_email = u2.user_email)
      && u1.user_id != u2.user_id
      && u1.user_id < u2.user_id";
if(!$result = $db->sql_query($sql))
{
    message_die(GENERAL_ERROR, 'Could not query for double user records.', '', __LINE__, __FILE__, $sql);
}

print "<table cellpadding='0' cellspacing='0'>";
while($row = $db->sql_fetchrow($result))
{
   print "<tr><td> ".$row['id1']."&nbsp;</td><td> ".$row['id2']."&nbsp;</td><td> ".$row['username']."&nbsp;</td><td> ";
   merge_users($row['id1'], $row['id2']);
   print " </td></tr>\n";
}
print "</table>";


function merge_users($user_id1, $user_id2)
{
   global $db;
   global $shift_tables;
   global $table_prefix1;
   
   $user_deps = $shift_tables['users'][1];

   // The users table should be skipped and the user_posts column should be updated.
   
   foreach($user_deps as $key => $value)
   {
      $d_table = $value[0];
      $d_column = $value[1];
      $sql = "UPDATE $table_prefix1$d_table SET $d_column = $user_id1 WHERE $d_column = $user_id2";
      if(!$result = $db->sql_query($sql))
      {
          message_die(GENERAL_ERROR, 'Could not update user_id.', '', __LINE__, __FILE__, $sql);
      }
   }
   
   $sql = "DELETE FROM " . $table_prefix1 . "users WHERE user_id = $user_id2";
   if(!$result = $db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not delete user2.', '', __LINE__, __FILE__, $sql);
   }

   print "OK";
   return;
}

function double_users()
{
   global $db;
   global $table_prefix1;

   $users_table = $table_prefix1 . "users";

   $sql = "SELECT user_id, ";
}

function merge_tables($table)
{

echo "<H1>Merging table : $table </H1>";

   global $db;
   global $dbname1, $table_prefix1, $dbname2, $table_prefix2;

   
   $sql = "SHOW FIELDS FROM $table_prefix1$table";
   if(!$result = $db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not get field info from $table.', '', __LINE__, __FILE__, $sql);
   }
   
   $fields = array();
   while($row = $db->sql_fetchrow($result))
   {
      $fields[] = $row['Field'];
   }
   $fieldlist = implode($fields, ', ');
   

   if($table == 'users')
   {
      $where = " WHERE $dbname2.$table_prefix2" . $table . ".user_id > 0";
   }
   else
   {
      $where = '';
   }

   echo "$table";
   
   $sql = "INSERT INTO $dbname1.$table_prefix1".$table." ($fieldlist) SELECT $fieldlist from $dbname2.$table_prefix2" . $table . $where;
   if(!$db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not merge $table.', '', __LINE__, __FILE__, $sql);
   }

   return TRUE;
}


// Shift all ID's in column $id in table $table in 
// database 2 by MAX($id) or (if not 0) by $offset
function shift_ids($table, $id, $offset = 0)
{
   global $db;
   global $dbname1, $table_prefix1;
   global $dbname2, $table_prefix2;

   // Offset hasn't been given, we're going to figure it out ourselfs
   if($offset == 0)
   {
      if(!$offset = getmax($dbname1, $table_prefix1.$table, $id))
      {
         // Empty table, no need to shift IDs
         print "Empty table? Skipping...<br />\n";
         return;
      }
   }

   // What's the max_id in the current table?
   $max2 = getmax($dbname2, $table_prefix2.$table, $id);
   $max2 = intval($max2); // Make sure that max2 contains a number, make it 0 if this table is empty.

// First we add the offset + the max of the current table
   // Treat values of 0 and lower as special values.
   $sql = "UPDATE $dbname2." . $table_prefix2 . $table . " SET $id = $id + $max2 + $offset WHERE $id > 0";
   print "$sql<br />\n";
   if(!$result = $db->sql_query($sql) )
   {
       message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
   }
   
   // Then we subtract the max of the current table again.
   // We do this to prevent problems with key constrains from happening
   // i.e. if we do id=id+20 on key 1 when key 21 already exists we would get an error
   $sql = "UPDATE $dbname2." . $table_prefix2 . $table . " SET $id = $id - $max2 WHERE $id > 0";
   print "$sql<br />\n";
   if(!$result = $db->sql_query($sql) )
   {
       message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
   }

   return $offset;
}

function getmax($dbname, $table, $id)
{
   global $db;
      $sql = "SELECT MAX($id) as max_id FROM $dbname." . $table;
      if(!$result = $db->sql_query($sql) )
      {
          message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
      }
      if($max = $db->sql_fetchrow($result))
      {
         return($max['max_id']);
      }
      else
      {
         // Probably no rows where returned.. Empty table.
         return FALSE;
      }
}


function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
   global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header;
   global $userdata, $user_ip, $session_length;
   global $starttime;

   $sql_store = $sql;
   
   //
   // Get SQL error if we are debugging. Do this as soon as possible to prevent 
   // subsequent queries from overwriting the status of sql_error()
   //
   $sql_error = $db->sql_error();

   $debug_text = '';

   if ( $sql_error['message'] != '' )
   {
      $debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
   }

   if ( $sql_store != '' )
   {
      $debug_text .= "<br /><br />$sql_store";
   }

   if ( $err_line != '' && $err_file != '' )
   {
      $debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
   }

   print $debug_text;

   exit;
}

echo "Done";

?>
Användarens profilbild
tumba25
Hedersmedlem
Hedersmedlem
Inlägg: 2097
Blev medlem: 2007-04-18 09:38
Svar: 0
Ort: Kokkola, Finland.

Inlägg av tumba25 »

Comment_id med värdet 1 förekommer i båda tabellerna och du kan inte ha 2 med samma id. Den borde öka det värdet automagiskt, så om det id't inte används i någon annan tabell kan du nog ta bort det.

Du kan kolla med phpMyAdmin om det står auto_increment. Om den inte gör det får du ändra i skriptet så den får en unik id. Samma om id't används i någon annan tabell.

/J
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Fjäsikens att det skall vara så svårt detta.... :(

Nu funkar i alla fall scriptet...bara inte Smartor's ALbum delen av det...

Jag förstår vad du säger, men saknar grundkunskaper för att lösa det själv...
Kan du kanske ge mig en indikation på hur omfattande problemet är?

mvh
Janne A.
Användarens profilbild
tumba25
Hedersmedlem
Hedersmedlem
Inlägg: 2097
Blev medlem: 2007-04-18 09:38
Svar: 0
Ort: Kokkola, Finland.

Inlägg av tumba25 »

Det är ett allvarligt fel kan man säga. Du kan inte ha 2 tabellrader med samma id. Det är det som måste lösas, hur stor grej det är beror lite på...

Om Smartors Album bara använder en tabell i databasen är det inte ett stort problem. Då behöver du bara se till att id't är på auto_increment och sen kan du ta bort id't från SQL-satsen.

Om Albumet använder flera tabeller behöver du ta reda på om Id't används i flera tabeller som referens. I så fall måste du se till att referensen också ändras när du ändrar id't.

Om du inte har den redan så börja med att installera phpMyAdmin. Version 2.9.2 verkar vara den som funkar bäst.

/J
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

OK, tack.

Vi försöker laga detta och återkommer om vi får till det, eller inte... :wink:

mvh
Janne A.
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Framgång till slut.. :)

Detta script fungerade nu för oss...
Hoppas någon annan får nytta av det.
Tack till Tomas Lidén som fixade sista felen... :wink:

Janne A.

Kod: Markera allt

<?php
// modifications by Imladris - for merging forums with Attachment Mod 
// and Smartor's Album Mod added by Tomas Lidén
// from: http://www.phpbb.com/phpBB/viewtopic.php?p=1426672#1426672
$dbms = 'mysql';
$phpbb_root_path = '../forums/';

$dbhost = 'localhost';

$dbuser = 'root or something';
$dbpasswd = 'a secret word';

// Name and prefix for the database that should keep the original IDs

$dbname1 = 'first db';
$table_prefix1 = 'firsttable_';

// Name and prefix for the database that is going to be added
// to DB1.
$dbname2 = 'second db';
$table_prefix2 = 'secondtable_';


# NO NEED TO MODIFY CODE BELOW
# MODIFY ONLY IF U KNOW WHAT U R DOING


define('IN_PHPBB', true);
// Use DB1 for the initial config table etc.
$dbname = $dbname1;
$table_prefix = $table_prefix1;
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);


// These tables can be dropped from DB2 (not used in this script)
$drop_tables = array(
   "config",
   "banlist", // This one could be converted
   "disallow",
   "search_results",
   "search_wordlist",
   "search_wordmatch",
   "sessions",
   "smilies",
   "themes",
   "themes_name",
   "words"
   );
   
// All tables in DB2 that should shift ID.
//  - table that needs shifting (categories)
//  - id in table (cat_id)
//    nested array:
//    - table that depends on id (forums)
//    - id that corresponds to id in original table (cat_id)
$shift_tables = array(
   "categories" => array(
      "cat_id", 
      array(
         array("forums", "cat_id")
      )
   ),
   "forums" => array(
      "forum_id",
      array(
         array("posts", "forum_id"),
         array("topics", "forum_id"),
         array("forum_prune", "forum_id"),
         array("auth_access", "forum_id")
      )
   ),
   "forum_prune" => array(
      "prune_id",
      array()
   ),
   "groups" => array(
      "group_id",
      array(
         array("user_group", "group_id"),
         array("auth_access", "group_id")
      )
   ),
   "posts" => array(
      "post_id",
      array(
         array("posts_text", "post_id"),
         array("topics", "topic_first_post_id"),
         array("topics", "topic_last_post_id")
      )
   ),
   "privmsgs" => array(
      "privmsgs_id",
      array(
         array("privmsgs_text", "privmsgs_text_id"),
         array("users", "user_last_privmsg")
      )
   ),
   "topics" => array(
      "topic_id",
      array(
         array("posts", "topic_id"),
         array("topics_watch", "topic_id"),
         array("vote_desc", "topic_id")
      )
   ),
   "users" => array(
      "user_id",
      array(
         array("user_group", "user_id"),
         array("groups", "group_moderator"),
         array("posts", "poster_id"),
         array("topics", "topic_poster"),
         array("privmsgs", "privmsgs_to_userid"),
         array("privmsgs", "privmsgs_from_userid"),
         array("topics_watch", "user_id"),
         array("vote_voters", "vote_user_id"),
         array("album", "pic_user_id"),
         array("album_comment", "comment_user_id"),
         array("album_comment", "comment_edit_user_id"),
         array("album_rate", "rate_user_id")
      )
   ),
   "album" => array(
      "pic_id",
      array(
         array("album_comment", "comment_pic_id"),
         array("album_rate", "rate_pic_id")
      )
   ),
   "album_comment" => array(
      "comment_id",
      array()
   ),
   "album_cat" => array(
      "cat_id",
      array(
         array("album", "pic_cat_id")
      )
   ),
   "ranks" => array(
      "rank_id",
      array(
         array("users", "user_rank")
      )
   ),
   "vote_desc" => array(
      "vote_id",
      array(
         array("vote_voters", "vote_id"),
         array("vote_results", "vote_id")
      )
   )
);

$bla_tables = array(
   "auth_access",
   "user_group",
   "posts_text",
   "privmsgs_text",
   "topics_watch",
   "vote_results",
   "vote_voters"
   );


// Traverse the shift_tables array

foreach($shift_tables as $key => $value)
{
   $table = $key;
   $merge_tables[$table] = 0; // keep an array with all tables that need merging
   $column = $value[0]; // Column with ID that needs to be shifted
   $ref = $value[1]; // Tables that are using the mentioned ID.
   print "Shifting IDs in table $table<br />\n";
   $max = shift_ids($table, $column);
   flush();
   // Do the dependent tables
   foreach($ref as $key => $value)
   {
      $d_table = $value[0];
      $merge_tables[$d_table] = 0;
      $d_column = $value[1];
      print "&nbsp; Altering dependent table: $d_table : $d_column (offset = $max)<br />\n";
      flush();
      shift_ids($d_table, $d_column, $max);
   }
   
   print "<br />\n";
   flush();
}

foreach($merge_tables as $table => $value)
{
   print "Merging $table table: ";
   if(merge_tables($table))
   {
      print " OK<br />\n";
   }
   else
   {
      print " FAILED!<br />\n";
   }
}

print "Merging users (username and either password or email are the same).<br />";
$sql = "
   SELECT
      u1.user_id as id1, 
      u2.user_id as id2, 
      u1.username
   FROM
      " . USERS_TABLE . " u1,
      " . USERS_TABLE . " u2
   WHERE
      u1.username = u2.username
      && (u1.user_password = u2.user_password
         || u1.user_email = u2.user_email)
      && u1.user_id != u2.user_id
      && u1.user_id < u2.user_id";
if(!$result = $db->sql_query($sql))
{
    message_die(GENERAL_ERROR, 'Could not query for double user records.', '', __LINE__, __FILE__, $sql);
}

print "<table cellpadding='0' cellspacing='0'>";
while($row = $db->sql_fetchrow($result))
{
   print "<tr><td> ".$row['id1']."&nbsp;</td><td> ".$row['id2']."&nbsp;</td><td> ".$row['username']."&nbsp;</td><td> ";
   merge_users($row['id1'], $row['id2']);
   print " </td></tr>\n";
}
print "</table>";


function merge_users($user_id1, $user_id2)
{
   global $db;
   global $shift_tables;
   global $table_prefix1;
   
   $user_deps = $shift_tables['users'][1];

   // The users table should be skipped and the user_posts column should be updated.
   
   foreach($user_deps as $key => $value)
   {
      $d_table = $value[0];
      $d_column = $value[1];
      $sql = "UPDATE $table_prefix1$d_table SET $d_column = $user_id1 WHERE $d_column = $user_id2";
      if(!$result = $db->sql_query($sql))
      {
          message_die(GENERAL_ERROR, 'Could not update user_id.', '', __LINE__, __FILE__, $sql);
      }
   }
   
   $sql = "DELETE FROM " . $table_prefix1 . "users WHERE user_id = $user_id2";
   if(!$result = $db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not delete user2.', '', __LINE__, __FILE__, $sql);
   }

   print "OK";
   return;
}

function double_users()
{
   global $db;
   global $table_prefix1;

   $users_table = $table_prefix1 . "users";

   $sql = "SELECT user_id, ";
}

function merge_tables($table)
{

echo "<H1>Merging table : $table </H1>";

   global $db;
   global $dbname1, $table_prefix1, $dbname2, $table_prefix2;

   
   $sql = "SHOW FIELDS FROM $table_prefix1$table";
   if(!$result = $db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not get field info from $table.', '', __LINE__, __FILE__, $sql);
   }
   
   $fields = array();
   while($row = $db->sql_fetchrow($result))
   {
      $fields[] = $row['Field'];
   }
   $fieldlist = implode($fields, ', ');
   

   if($table == 'users')
   {
      $where = " WHERE $dbname2.$table_prefix2" . $table . ".user_id > 0";
   }
   else
   {
      $where = '';
   }

   echo "$table";
   
   $sql = "INSERT INTO $dbname1.$table_prefix1".$table." ($fieldlist) SELECT $fieldlist from $dbname2.$table_prefix2" . $table . $where;
   if(!$db->sql_query($sql))
   {
       message_die(GENERAL_ERROR, 'Could not merge $table.', '', __LINE__, __FILE__, $sql);
   }

   return TRUE;
}


// Shift all ID's in column $id in table $table in 
// database 2 by MAX($id) or (if not 0) by $offset
function shift_ids($table, $id, $offset = 0)
{
   global $db;
   global $dbname1, $table_prefix1;
   global $dbname2, $table_prefix2;

   // Offset hasn't been given, we're going to figure it out ourselfs
   if($offset == 0)
   {
      if(!$offset = getmax($dbname1, $table_prefix1.$table, $id))
      {
         // Empty table, no need to shift IDs
         print "Empty table? Skipping...<br />\n";
         return;
      }
   }

   // What's the max_id in the current table?
   $max2 = getmax($dbname2, $table_prefix2.$table, $id);
   $max2 = intval($max2); // Make sure that max2 contains a number, make it 0 if this table is empty.

// First we add the offset + the max of the current table
   // Treat values of 0 and lower as special values.
   $sql = "UPDATE $dbname2." . $table_prefix2 . $table . " SET $id = $id + $max2 + $offset WHERE $id > 0";
   print "$sql<br />\n";
   if(!$result = $db->sql_query($sql) )
   {
       message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
   }
   
   // Then we subtract the max of the current table again.
   // We do this to prevent problems with key constrains from happening
   // i.e. if we do id=id+20 on key 1 when key 21 already exists we would get an error
   $sql = "UPDATE $dbname2." . $table_prefix2 . $table . " SET $id = $id - $max2 WHERE $id > 0";
   print "$sql<br />\n";
   if(!$result = $db->sql_query($sql) )
   {
       message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
   }

   return $offset;
}

function getmax($dbname, $table, $id)
{
   global $db;
      $sql = "SELECT MAX($id) as max_id FROM $dbname." . $table;
      if(!$result = $db->sql_query($sql) )
      {
          message_die(GENERAL_ERROR, 'Could not fetch max(id).', '', __LINE__, __FILE__, $sql);
      }
      if($max = $db->sql_fetchrow($result))
      {
         return($max['max_id']);
      }
      else
      {
         // Probably no rows where returned.. Empty table.
         return FALSE;
      }
}


function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
   global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header;
   global $userdata, $user_ip, $session_length;
   global $starttime;

   $sql_store = $sql;
   
   //
   // Get SQL error if we are debugging. Do this as soon as possible to prevent 
   // subsequent queries from overwriting the status of sql_error()
   //
   $sql_error = $db->sql_error();

   $debug_text = '';

   if ( $sql_error['message'] != '' )
   {
      $debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
   }

   if ( $sql_store != '' )
   {
      $debug_text .= "<br /><br />$sql_store";
   }

   if ( $err_line != '' && $err_file != '' )
   {
      $debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
   }

   print $debug_text;

   exit;
}

echo "Done";

?>
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Ropade hej för tidigt är jag rädd...:cry:

Det verkar vara ett fel i attachment mod delen av detta script som gör att bifogade filer inte följer med i sammanslagningen.
...och vad värre är dessutom korrumperar den gamla db:n , usch... :twisted:
(ja, jag har backuper)

Allt annat funkar...så vitt jag kan se...

Någon som kan se vad som är fel i den delen av scriptet?

mvh
Janne A.
Användarens profilbild
tumba25
Hedersmedlem
Hedersmedlem
Inlägg: 2097
Blev medlem: 2007-04-18 09:38
Svar: 0
Ort: Kokkola, Finland.

Inlägg av tumba25 »

Massor. Den borde inte röra db'n för forumet som ska läggas till men den gör alla ändringar där innan den lägger till den.

Skulle vara bättre att göra ändringarna när infot kopieras.

/J
houser
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 145
Blev medlem: 2005-09-20 00:05
Svar: 0

Inlägg av houser »

Ger upp på detta nu...suck....ingen mer tid....

Hoppas att phpbb3 kommer att ha en upgrade/merge i en framtida funktion
vid install som gör att man kan addera ett till phpbb2 in ett phpbb3.
Gör ett nytt försök till nästa termin...

Hoppas kan man väl alltid.... :roll:

mvh
Janne A.
Skriv svar

Vilka är online

Användare som besöker denna kategori: 1 och 0 gäst