diff -r 2cd8c1649ba9 -r 58094faf794d migrator.php-pa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/migrator.php-pa Tue Apr 10 22:40:43 2007 +0000
@@ -0,0 +1,129 @@
+ trancer nl> |
+// | Sjeemz sjeemz nl> |
+// +--------------------------------------------------------------------+
+//
+// File: migrator.php
+// Description: Migrates PowerAdmin 1.1.2 to the new 1.2 format
+
+if(!@include_once("inc/config.inc.php"))
+{
+ error("You have to create a config.inc.php!");
+}
+require_once("inc/database.inc.php");
+
+PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'error');
+function error($msg)
+{
+ // General function for printing critical errors.
+ include_once("inc/header.inc.php");
+ ?>
+ Oops! An error occured!
+
+
+
+ if(is_object($msg))
+ {
+ switch($msg->code)
+ {
+ case -19:
+ echo "It seems you already have your PowerAdmin migrated because the tables cant be
+ altered. Another problem can be that you dont ALTER right on your database,
+ check this if you think your database doesnt have the proper format yet! ";
+ break;
+ case -18:
+ echo "One of the tables required doesnt exist, please run
+ test_setup.php. PEAR::DB Error: " . $msg->getDebugInfo();
+ break;
+ default:
+ echo "Unknown error, sorry: PEAR::DB Returned: " . $msg->getDebugInfo();
+ break;
+ }
+ }
+ else
+ {
+ echo $msg;
+ }
+ ?>
+
+
<< back
|
+
+ include_once("inc/footer.inc.php");
+ die();
+}
+
+
+function message($msg)
+{
+ include_once("inc/header.inc.php");
+ ?>
+ Success!
+
+
+
+
+ if($msg)
+ {
+ echo nl2br($msg);
+ }
+ else
+ {
+ echo "Successful!";
+ }
+ ?>
+
+
+
+ << back
+
+ |
+
+ include_once("inc/footer.inc.php");
+}
+
+$zoneresult = $db->getCol("select id from zones");
+
+foreach($zoneresult as $zr)
+{
+ // Look up the domain_id
+ $zonename = $db->getOne("select name from zones where zones.id=" . $zr);
+ // do a count, if the record already exists in the domains table, dont insert it
+ $dom_count = $db->query("select id from domains where name='$zonename'");
+ if($dom_count->numRows() == 0)
+ {
+ $dom_id = $db->nextID("domains");
+ $db->query("INSERT INTO domains(id, name, type) VALUES('$dom_id', '$zonename', 'NATIVE')");
+ $db->query("UPDATE records SET domain_id=$dom_id where domain_id=$zr");
+ $db->query("UPDATE zones SET name=$dom_id where id=$zr");
+ }
+ else
+ {
+ $row = $dom_count->fetchRow();
+
+ $db->query('UPDATE records SET domain_id=' . $row["id"] . " where domain_id=$zr");
+ $db->query('UPDATE zones SET name=' . $row['id'] . " where id=$zr");
+ }
+}
+
+if(!DB::isError($zoneresult))
+{
+ $db->query("ALTER TABLE zones CHANGE name domain_id INT(11) NOT NULL");
+
+ message("Done updating your tables, enjoy your new PowerAdmin!
+ Please remove this file from your webdirectory!");
+}
+else
+{
+ error("You seem to have no information in the table zones");
+}
+?>