Seite 1 von 1

v1.4.4 mit poll mod aus phpBBmod 1.3.3 auf v2.0.0 upgraden

Verfasst: 03.03.2005 12:37
von spacetrace
wenn man phpBB1.4.4 mit phpBBmod 1.3.3 auf phpBB2.0.0 upgradet (was der einzige weg ist um auf ein höheres 2.0.x upzugraden) dann gehen die poll daten verloren.
ich habe hier ien script geschrieben, das man nach dem updaten auf 2.0.0 laufen lassen kann um die daten aus den poll-tabellen in die vote-tabellen zu konvertieren
(so gut es geht:
die userdaten gehen verloren, da die vote-funktion den user nicht mitspeichert, sondern nur ob ein user gevotet hat, aber nicht was er gevoted hat.
die ip wird leer gelassen, hier könnte jemand noch eine verbesserung des scriptes programmieren, ich brauchte das blos nicht
und die vote-zeit auf unendlich gesetzt)

Code: Alles auswählen

<?
// this script adapts the database for phpBB1.4.4 with the poll mod from phpBBmod 1.3.3
// after you upgraded to phpBB V.2.0.0
// by Ruben Barkow
// work:
// http://www.eclabs.de
// 
// private onlinegame project:
// http://www.spacetrace.org

// adapt these settings to you database:
$host="localhost";
$database="phpBB";
$database_user="phpBBuser";
$database_pass="phpBBpass";
$tableprefix=""; // empty or for example "phpbb_"

// if $demo_mode is TRUE then no queries will be sent to the database only the sql inserts are shown, that would be made
$demo_mode=FALSE;

$cid = mysql_connect($host,$database_user,$database_pass);
mysql_select_db($database,$cid);


# something in the user table is wrong after converting from phpBB1.4.4 to 2.0.0
# (the error effects, that noone can register a new user)
$stmt="ALTER TABLE `$tableprefix"."users` ADD `user_timezone` DECIMAL( 5, 2 ) DEFAULT '0.00' NOT NULL AFTER `user_posts`";
echo "<br><br>use this query only if your usertable is wrong after converting from phpBB1.4.4 to 2.0.0:<br><i>".$stmt.";</i><br>";
#unmark this only if your usertable is wrong
#if (!$demo_mode) if (!mysql_query($stmt)) echo mysql_error();

# insert the vote descriptions 
$stmt="INSERT INTO $tableprefix"."vote_desc (
SELECT t.poll_id, t.topic_id, pt.title, UNIX_TIMESTAMP( pt.date ) , 0
FROM poll_topics AS pt, topics AS t
WHERE t.poll_id = pt.poll_id 
)";
echo "<br><br>insert the vote descriptions :<br>".$stmt.";<br>";
if (!$demo_mode) if (!mysql_query($stmt)) echo mysql_error();

$stmt="SELECT * FROM `$tableprefix"."poll_topics` ";
echo "<br><br>".$stmt."<br>generated inputs from that:<br>";
if (!mysql_query($stmt)) echo mysql_error();

$r=mysql_query($stmt);
while($row=mysql_fetch_assoc($r)){
  $choices=split(",", $row["choices"]);
  foreach($choices as $i=>$c){
  	$stmt="INSERT INTO `$tableprefix"."vote_results` ( `vote_id` , `vote_option_id` , `vote_option_text` , `vote_result` )
		VALUES ('".$row["poll_id"]."', '".($i+1)."', '".$c."', '0')";
	echo $stmt.";<br>";
	if (!$demo_mode) if (!mysql_query($stmt)) echo mysql_error();
  }
}

// select all votes and update the vote_results
$stmt="SELECT pt.poll_id, pd.choice+1 AS vote_option_id, SUBSTRING_INDEX(SUBSTRING_INDEX(pt.choices, ',', pd.choice+1),',',-1), pd.choice+1
FROM $tableprefix"."poll_topics AS pt, `$tableprefix"."poll_data` AS pd
WHERE pt.poll_id = pd.poll_id";
echo $stmt.";<br>";
$r=mysql_query($stmt);
while($row=mysql_fetch_assoc($r)){
  $choices=split(",", $row["choices"]);
  foreach($choices as $i=>$c){
  	$stmt="UPDATE `$tableprefix"."vote_results` 
		SET `vote_result` = vote_result+1 
		WHERE `vote_id` = '".$row["poll_id"]."' 
				AND `vote_option_id` = '".$row["vote_option_id"]."'";
	echo $stmt.";<br>";
	if (!$demo_mode) if (!mysql_query($stmt)) echo mysql_error();
  }
}

# update topics, so the poll is activated
$stmt="update $tableprefix"."topics set topic_vote = 1 where poll_id>0";
echo "<br><br>update topics, so the poll is activated:<br>".$stmt.";<br>";
if (!$demo_mode) if (!mysql_query($stmt)) echo mysql_error();