Location: PHPKode > projects > L-Forum > l-forum/admin/upgrade.php
<?

include "../config.php";
include "../lib/init.inc";

auth();

$head = str_replace("__TITLE__", $lang['administration'], $design['head']);

echo $head;

include "../themes/".$theme."/header.inc";
echo "<div class=header>Upgrading database</div><br>\n<table border=0>";
echo "<tr><td>Downloading old L-Forum data</td><td>";
flush();
$max = 0;
$q = new Query("select * from articles");
while($r = $q->row()){
   $downloaded_data[] = $r;
   if($r['id']>$max)
      $max = $r['id'];
}
echo "[<font color=\"green\">OK</font>]</td></tr>\n";
echo "<tr><td>Dropping old table</td><td>";
$q = new Query("drop table articles");
if($db_type=="postgres")
   $q = new Query("drop sequence articles_id_seq");
echo "[<font color=\"green\">OK</font>]</td></tr>\n";
$queries = file("base_".$db_type.".sql");
$count = count($queries);
for($i=0; $i<$count; $i++){
   if($i==1 || $i==3)
      continue;
   echo "<tr><td>";
   switch($i){
      case 0:
         echo "Creating table 'articles'";
         break;
      case 2:
         echo "Setting permissions for table 'articles'";
         break;
      case 4:
         echo "Setting permissions for sequence 'articles_id_seq'";
         break;
   }
   flush();
   echo "</td><td>";
   $q = new Query($queries[$i]);
   echo "[<font color=Green>OK</font>]</td></tr>";
   flush();
}
echo "<tr><td>Restoring data</td><td>";
flush();
$cnt = count($downloaded_data);
for($i = 0; $i < $cnt; $i++){
   $qry = "insert into articles(id, time, author, email, subject, body, is_parent, subs, parent, level, root, ip, views, forum, moderation_state, attach) values(".
         $downloaded_data[$i]['id'].", ".
         "'".addslashes($downloaded_data[$i]['time'])."', ".
         "'".addslashes($downloaded_data[$i]['author'])."', ".
         "'".addslashes($downloaded_data[$i]['email'])."', ".
         "'".addslashes($downloaded_data[$i]['subject'])."', ".
         "'".addslashes($downloaded_data[$i]['body'])."', ";
   if($db_type == "postgres")
      $qry .= "'";
   $qry .= $downloaded_data[$i]['is_parent'];
   if($db_type == "postgres")
      $qry .= "'"; 
   $qry .= ", '".$downloaded_data[$i]['subs']."', ".
         $downloaded_data[$i]['parent'].", ".
         $downloaded_data[$i]['level'].", ".
         $downloaded_data[$i]['root'].", ".
         "'".$downloaded_data[$i]['ip']."', ".
         $downloaded_data[$i]['views'].", ".
         $downloaded_data[$i]['forum'].", ". "0, ".
         "'".$downloaded_data[$i]['attach']."')";
   $q = new Query($qry);
}
echo "[<font color=\"green\">OK</font>]</td></tr>\n";
flush();
if($db_type=="postgres"){
   echo "<tr><td>Recreating sequence</td><td>";
   flush();
   $q = new Query("drop sequence articles_id_seq");
   $q = new Query("create sequence articles_id_seq start $max");
   echo "[<font color=\"green\">OK</font>]</td></tr>\n";
   flush();
}
echo "</table>";
include "../themes/".$theme."/footer.inc";

echo $design['footer'];

?>

Return current item: L-Forum