[Mapbender-commits] r2774 - branches/2.5/http/tools
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Aug 13 07:05:07 EDT 2008
Author: christoph
Date: 2008-08-13 07:05:07 -0400 (Wed, 13 Aug 2008)
New Revision: 2774
Added:
branches/2.5/http/tools/1_createMySqlDump.php
branches/2.5/http/tools/2_convertDataDumps.php
branches/2.5/http/tools/3_addHeaderToDataDumps.php
Log:
for the build script...just a backup
Added: branches/2.5/http/tools/1_createMySqlDump.php
===================================================================
--- branches/2.5/http/tools/1_createMySqlDump.php (rev 0)
+++ branches/2.5/http/tools/1_createMySqlDump.php 2008-08-13 11:05:07 UTC (rev 2774)
@@ -0,0 +1,61 @@
+<?php
+ $fileArray = array(
+ "mysql" =>
+ array( "from" => "../../resources/db/postgresql/utf8/pgsql_data.sql",
+ "to" => "../../resources/db/mysql/utf8/mysql_data.sql")
+ );
+
+ function saveAsFile($filename, $data) {
+ if ($h = fopen($filename, "w")) {
+ if (!fwrite($h, $data)) {
+ return false;
+ }
+ fclose($h);
+ }
+ return true;
+ }
+
+ // load file
+ $from = $fileArray["mysql"]["from"];
+ $to = $fileArray["mysql"]["to"];
+
+ if (file_exists($from)) {
+ $data = file_get_contents($from);
+ }
+ else {
+ echo "Fatal error: File not found ('" . $from . "').\n";
+ exit(1);
+ }
+
+ // replace postgresql's string escape syntax
+ $pattern = "/, E'/";
+ $data = preg_replace($pattern, ", '", $data);
+
+ // disable foreign keys
+ $pattern = "/UPDATE pg_catalog\.pg_class SET reltriggers = 0;/";
+ if (preg_match($pattern, $data)) {
+ $data = preg_replace($pattern, "SET FOREIGN_KEY_CHECKS=0;", $data);
+ }
+ else {
+ echo "Fatal error: Didn't find expression (pattern: " . $pattern . ").\n";
+ exit(1);
+ }
+
+ // enable foreign keys
+ $pattern = "/UPDATE pg_catalog\.pg_class SET reltriggers = \(SELECT pg_catalog\.count\(\*\) FROM pg_catalog\.pg_trigger where pg_class\.oid = tgrelid\);/";
+ if (preg_match($pattern, $data)) {
+ $data = preg_replace($pattern, "SET FOREIGN_KEY_CHECKS=1;", $data);
+ }
+ else {
+ echo "Fatal error: Didn't find expression (pattern: " . $pattern . ").\n";
+ exit(1);
+ }
+
+ // save mysql file
+ if (!saveAsFile($to, $data)) {
+ echo "Fatal error: File could not be saved ('" . $to . "').\n";
+ exit(1);
+ }
+ echo "Finished.\n\n";
+ exit(0);
+?>
\ No newline at end of file
Added: branches/2.5/http/tools/2_convertDataDumps.php
===================================================================
--- branches/2.5/http/tools/2_convertDataDumps.php (rev 0)
+++ branches/2.5/http/tools/2_convertDataDumps.php 2008-08-13 11:05:07 UTC (rev 2774)
@@ -0,0 +1,44 @@
+<?php
+ // needs to be set, otherwise the iconv option //TRANSLIT
+ // won't work
+ setlocale(LC_CTYPE, "de_DE.utf8");
+
+ $fileArray = array(
+ "mysql" =>
+ array( "from" => "../../resources/db/mysql/utf8/mysql_data.sql",
+ "to" => "../../resources/db/mysql/iso/mysql_data.sql"),
+ "pgsql" =>
+ array( "from" => "../../resources/db/postgresql/utf8/pgsql_data.sql",
+ "to" => "../../resources/db/postgresql/iso/pgsql_data.sql")
+ );
+
+ function saveAsFile($filename, $data) {
+ if ($h = fopen($filename, "w")) {
+ if (!fwrite($h, $data)) {
+ return false;
+ }
+ fclose($h);
+ }
+ return true;
+ }
+
+
+ foreach ($fileArray as $file) {
+ $from = $file["from"];
+ $to = $file["to"];
+
+ if (file_exists($from)) {
+ $data = file_get_contents($from);
+ }
+ else {
+ echo "Fatal error: File not found ('" . $from . "').\n";
+ }
+
+ $dataConverted = iconv("UTF-8", "ASCII//TRANSLIT", $data);
+
+ if (!saveAsFile($to, $dataConverted)) {
+ echo "Fatal error: File could not be saved ('" . $to . "').\n";
+ }
+ }
+ echo "Finished.\n\n";
+?>
\ No newline at end of file
Added: branches/2.5/http/tools/3_addHeaderToDataDumps.php
===================================================================
--- branches/2.5/http/tools/3_addHeaderToDataDumps.php (rev 0)
+++ branches/2.5/http/tools/3_addHeaderToDataDumps.php 2008-08-13 11:05:07 UTC (rev 2774)
@@ -0,0 +1,53 @@
+<?php
+ require_once(dirname(__FILE__) . "/../../core/system.php");
+ setlocale(LC_TIME, "de_DE.utf8");
+
+ $fileArray = array(
+ "mysql" =>
+ array( "iso" => "../../resources/db/mysql/iso/mysql_data.sql",
+ "utf8" => "../../resources/db/mysql/utf8/mysql_data.sql"),
+ "postgresql" =>
+ array( "iso" => "../../resources/db/postgresql/iso/pgsql_data.sql",
+ "utf8" => "../../resources/db/postgresql/utf8/pgsql_data.sql")
+ );
+
+ function saveAsFile($filename, $data) {
+ if ($h = fopen($filename, "w")) {
+ if (!fwrite($h, $data)) {
+ return false;
+ }
+ fclose($h);
+ }
+ return true;
+ }
+
+ foreach ($fileArray as $dbType => $files) {
+ foreach ($files as $characterSet => $file) {
+ if (file_exists($file)) {
+ $data = file_get_contents($file);
+ }
+ else {
+ echo "Fatal error: File not found ('" . $file . "').\n";
+ exit(1);
+ }
+
+ // add header to file
+ $header = "--\n" .
+ "-- " . $dbType . " " . $characterSet . " data dump\n" .
+ "-- \n" .
+ "-- Mapbender " . MB_VERSION_NUMBER . " " . MB_VERSION_APPENDIX . "\n" .
+ "-- \n" .
+ "-- " . date("Y/m/d", MB_RELEASE_DATE) . "\n" .
+ "--\n\n";
+ $data = $header . $data;
+
+ if (!saveAsFile($file, $data)) {
+ echo "Fatal error: File could not be saved ('" . $file . "').\n";
+ exit(1);
+ }
+
+ }
+ }
+ echo "Finished.\n\n";
+ exit(0);
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list