migrator.php-pa
changeset 8 47dd15d8bb8c
parent 7 ac0ca51809b1
child 9 d55459cd1712
equal deleted inserted replaced
7:ac0ca51809b1 8:47dd15d8bb8c
     1 <?php
       
     2 // +--------------------------------------------------------------------+
       
     3 // | PowerAdmin								|
       
     4 // +--------------------------------------------------------------------+
       
     5 // | Copyright (c) 1997-2002 The PowerAdmin Team			|
       
     6 // +--------------------------------------------------------------------+
       
     7 // | This source file is subject to the license carried by the overal	|
       
     8 // | program PowerAdmin as found on http://poweradmin.sf.net		|
       
     9 // | The PowerAdmin program falls under the QPL License:		|
       
    10 // | http://www.trolltech.com/developer/licensing/qpl.html		|
       
    11 // +--------------------------------------------------------------------+
       
    12 // | Authors: Roeland Nieuwenhuis <trancer <AT> trancer <DOT> nl>	|
       
    13 // |          Sjeemz <sjeemz <AT> sjeemz <DOT> nl>			|
       
    14 // +--------------------------------------------------------------------+
       
    15 //
       
    16 // File: migrator.php
       
    17 // Description: Migrates PowerAdmin 1.1.2 to the new 1.2 format
       
    18 
       
    19 if(!@include_once("inc/config.inc.php"))
       
    20 {
       
    21         error("You have to create a config.inc.php!");
       
    22 }
       
    23 require_once("inc/database.inc.php");
       
    24 
       
    25 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'error');
       
    26 function error($msg)
       
    27 {
       
    28         // General function for printing critical errors.
       
    29         include_once("inc/header.inc.php");
       
    30         ?>
       
    31         <P><TABLE CLASS="error"><TR><TD CLASS="error"><H2>Oops! An error occured!</H2>
       
    32         <BR>
       
    33         <FONT STYLE="font-weight: Bold">
       
    34 	<?
       
    35 		if(is_object($msg))
       
    36 		{	
       
    37 			switch($msg->code)
       
    38 			{
       
    39 				case -19:
       
    40 					echo "<P>It seems you already have your PowerAdmin migrated because the tables cant be 
       
    41 						altered. Another problem can be that you dont ALTER right on your database, 
       
    42 						check this if you think your database doesnt have the proper format yet!</P>";
       
    43 					break;
       
    44 				case -18:
       
    45 					echo "<P>One of the tables required doesnt exist, please run 
       
    46 						test_setup.php.</P>PEAR::DB Error: " . $msg->getDebugInfo();
       
    47 					break;
       
    48 				default:
       
    49 					echo "Unknown error, sorry: PEAR::DB Returned: " . $msg->getDebugInfo();
       
    50 					break;
       
    51 			}
       
    52 		}
       
    53 		else
       
    54 		{
       
    55 			echo $msg;
       
    56 		}
       
    57 	?>
       
    58 
       
    59 	<BR><BR><a href="javascript:history.go(-1)">&lt;&lt; back</a></FONT><BR></TD></TR></TABLE></P>
       
    60         <?
       
    61         include_once("inc/footer.inc.php");
       
    62         die();
       
    63 }
       
    64 
       
    65 
       
    66 function message($msg)
       
    67 {
       
    68     include_once("inc/header.inc.php");
       
    69     ?>
       
    70     <P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2>Success!</H2>
       
    71     <BR>
       
    72 	<FONT STYLE="font-weight: Bold">
       
    73 	<P>
       
    74 	<?
       
    75     if($msg)
       
    76     {
       
    77         echo nl2br($msg);
       
    78     }
       
    79     else
       
    80     {
       
    81         echo "Successful!";
       
    82     }
       
    83     ?>
       
    84     </P>
       
    85     <BR>
       
    86     <P>
       
    87     <a href="javascript:history.go(-1)">&lt;&lt; back</a></FONT>
       
    88     </P>
       
    89     </TD></TR></TABLE></P>
       
    90     <?
       
    91     include_once("inc/footer.inc.php");
       
    92 }
       
    93 
       
    94 $zoneresult = $db->getCol("select id from zones");
       
    95 
       
    96 foreach($zoneresult as $zr)
       
    97 {
       
    98 	// Look up the domain_id
       
    99 	$zonename = $db->getOne("select name from zones where zones.id=" . $zr);
       
   100         // do a count, if the record already exists in the domains table, dont insert it
       
   101 	$dom_count = $db->query("select id from domains where name='$zonename'");
       
   102         if($dom_count->numRows() == 0)
       
   103         {
       
   104                 $dom_id = $db->nextID("domains");
       
   105         	$db->query("INSERT INTO domains(id, name, type) VALUES('$dom_id', '$zonename', 'NATIVE')");
       
   106 	        $db->query("UPDATE records SET domain_id=$dom_id where domain_id=$zr");
       
   107         	$db->query("UPDATE zones SET name=$dom_id where id=$zr");
       
   108         }
       
   109         else
       
   110         {
       
   111 		$row = $dom_count->fetchRow();
       
   112 		
       
   113                 $db->query('UPDATE records SET domain_id=' . $row["id"] . " where domain_id=$zr");
       
   114                 $db->query('UPDATE zones SET name=' . $row['id'] . " where id=$zr");
       
   115         }
       
   116 }
       
   117 
       
   118 if(!DB::isError($zoneresult))
       
   119 {
       
   120 	$db->query("ALTER TABLE zones CHANGE name domain_id INT(11) NOT NULL");
       
   121 
       
   122 	message("Done updating your tables, enjoy your new PowerAdmin! 
       
   123 	Please remove this file from your webdirectory!");
       
   124 }
       
   125 else
       
   126 {
       
   127 	error("You seem to have no information in the table zones");
       
   128 }
       
   129 ?>