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