]> git.mjollnir.org Git - moodle.git/commitdiff
Fixing postgres unicode migration for mac os x and multiple postgres installations
authormjollnir_ <mjollnir_>
Wed, 5 Apr 2006 03:54:12 +0000 (03:54 +0000)
committermjollnir_ <mjollnir_>
Wed, 5 Apr 2006 03:54:12 +0000 (03:54 +0000)
admin/utfdbmigrate.html
admin/utfdbmigrate.php
lang/en_utf8/admin.php

index 7854b577d0132ff163e9d0c1ccc7d1e4ce4b6444..1f118fa6e85751c2f6c86d7bdcf1fac8bdab332b 100644 (file)
    if (!isset($form->dbcluster)) {
        $form->dbcluster = '';
    }
+   if (!isset($form->pathtopgdump)) {
+       $form->pathtopgdump = '';
+   }
+   if (!isset($form->pathtopsql)) {
+       $form->pathtopsql = '';
+   }
 ?>
 <form name="migratefrom" action="utfdbmigrate.php" method="POST">
 <input name="migrate" type="hidden" value="1" />
 <input name="sesskey" type="hidden" value="<?php echo sesskey() ?>" />
 <?php if (isset($err["dbconnect"])) formerr($err["dbconnect"]); ?>
-<table cellpadding="9" cellspacing="0" >
+<?php if (isset($err["pathtopgdump"])) formerr($err["pathtopgdump"]); ?>
+<?php if (isset($err["pathtopsql"])) formerr($err["pathtopsql"]); ?>
+<table cellpadding="9" cellspacing="0" width="500">
 <tr valign="top">
     <td align="right"><?php print_string("dbhost", "install") ?>:</td>
     <td><input type="text" name="dbhost" value="<?php p($form->dbhost) ?>" />
 <tr valign="top">
     <td align="right"><?php print_string("pgcluster", "admin") ?>:</td>
     <td><input type="text" name="dbcluster" value="<?php p($form->dbcluster) ?>" />
-    <br />
-    <?php print_string("pgclusterdescription", "admin") ?>
-    </td>
+    <td><?php print_string("pgclusterdescription", "admin") ?></td>
+</tr>
+<tr valign="top">
+    <td align="right" nowrap="nowrap"><?php print_string("pathtopgdump","admin") ?>:</td>
+    <td><input type="text" name="pathtopgdump" value="<?php p($form->pathtopgdump) ?>" />
+    <td><?php print_string("pathtopgdumpdesc","admin"); ?></td>
+</tr>
+<tr valign="top">
+    <td align="right" nowrap="nowrap"><?php print_string("pathtopsql","admin") ?>:</td>
+    <td><input type="text" name="pathtopsql" value="<?php p($form->pathtopsql) ?>" />
+    <td><?php print_string("pathtopsqldesc","admin"); ?></td>
 </tr>
 </table>
 <center>
index 5b9afcf47c3ca323071864d2e47f9784f852856e..873632d02297d21106b76792be65cbe4059c0190 100755 (executable)
@@ -199,7 +199,16 @@ function db_migrate2utf8(){   //Eloy: Perhaps some type of limit parameter here
             } else {
                 $cluster = '';
             }
-            $cmd = "PGPASSWORD={$CFG->dbpass} PGCLIENTENCODING='UNICODE' PGDATABASE={$CFG->dbname} pg_dump -Fp -O -x -U {$CFG->dbuser}$cluster";
+            $pgdump = 'pg_dump';
+            if (!empty($_SESSION['newpostgresdb']->pathtopgdump)) {
+                $pgdump = $_SESSION['newpostgresdb']->pathtopgdump;
+            }
+            $psql = 'psql';
+            if (!empty($_SESSION['newpostgresdb']->pathtopsql)) {
+                $pgsql = $_SESSION['newpostgresdb']->pathtopsql;
+            }
+            
+            $cmd = "PGPASSWORD={$CFG->dbpass} PGCLIENTENCODING='UNICODE' PGDATABASE={$CFG->dbname} $pgdump -Fp -O -x -U {$CFG->dbuser}$cluster";
             if ($CFG->dbhost)  {
                 $host = split(":", $CFG->dbhost);
                 if ($host[0]) $cmd .= " -h {$host[0]}";
@@ -208,7 +217,7 @@ function db_migrate2utf8(){   //Eloy: Perhaps some type of limit parameter here
             $cmds[] = $cmd;
             $cmds[] = 'grep -v "COMMENT ON SCHEMA"';
             $cmds[] = 'iconv -f UTF-8 -t UTF-8 -c';
-            $cmd = "PGPASSWORD={$_SESSION['newpostgresdb']->dbpass} PGDATABASE={$_SESSION['newpostgresdb']->dbname} psql -q -U {$_SESSION['newpostgresdb']->dbuser} -v ON_ERROR_STOP=1$cluster";
+            $cmd = "PGPASSWORD={$_SESSION['newpostgresdb']->dbpass} PGDATABASE={$_SESSION['newpostgresdb']->dbname} $psql -q -U {$_SESSION['newpostgresdb']->dbuser} -v ON_ERROR_STOP=1$cluster";
             if ($_SESSION['newpostgresdb']->dbhost)  {
                 $host = split(":", $_SESSION['newpostgresdb']->dbhost);
                 if ($host[0]) $cmd .= " -h {$host[0]}";
@@ -217,7 +226,16 @@ function db_migrate2utf8(){   //Eloy: Perhaps some type of limit parameter here
             $cmds[] = $cmd;
             foreach ($cmds as $key => $cmd) {
                 $files[] = tempnam($CFG->dataroot, 'utf8_');
-                exec($cmd . ($key?" < {$files[$key-1]}":'') . " 2>&1 > {$files[$key]}", $output, $return_var);
+                $cmd = $cmd . ($key?" < {$files[$key-1]}":'') . " 2>&1 > {$files[$key]}";
+                if (stripos(PHP_OS, 'darwin') !== false && stripos($cmd,'iconv') !== false) {
+                    // I know this looks DREADFULLY hackish, but the iconv in mac os x seems to have a return code of 1 for warnings
+                    // and I cannot figure out why, it's a very different version of iconv to most *nix versions, even seems to be a 
+                    // different gnu project.
+                    // If someone can figure out a better way to do this, FEEL FREE :)
+                    // - Penny
+                    $cmd .= ' || true';
+                }
+                exec($cmd, $output, $return_var);
                 if ($key) {
                     unlink($files[$key-1]);
                 }
@@ -811,6 +829,16 @@ function validate_form(&$form, &$err) {
         return;
     }
 
+    if (!empty($form->pathtopgdump) && !is_executable($form->pathtopgdump)) {
+        $err['pathtopgdump'] = get_string('pathtopgdumpinvalid','admin');
+        return;
+    }
+
+    if (!empty($form->pathtopsql) && !is_executable($form->pathtopsql)) {
+        $err['pathtopsql'] = get_string('pathtopsqlinvalid','admin');
+        return;
+    }                                   
+
     return;
 }
 
index 636941c9ec04f6d01bb989d1ee31f2b988e53eef..6623e5f8b4d9a36fbfdac221af41e0f73cda28c6 100644 (file)
@@ -203,13 +203,15 @@ $string['order3'] = 'Third';
 $string['pathdvips'] = 'Path of <i>dvips</i> binary';
 $string['pathconvert'] = 'Path of <i>convert</i> binary';
 $string['pathlatex'] = 'Path of <i>latex</i> binary';
+$string['pathtopgdump'] = 'Path to pg_dump';
+$string['pathtopgdumpdesc'] = 'This is only necessary to enter if you have more than one pg_dump on your system (for example if you have more than one version of postgresql installed)';
+$string['pathtopgdumpinvalid'] = 'Invalid path to pg_dump - either wrong path or not executable';
+$string['pathtopsql'] = 'Path to psql';
+$string['pathtopsqldesc'] = 'This is only necessary to enter if you have more than one psql on your system (for example if you have more than one version of postgresql installed)';
+$string['pathtopsqlinvalid'] = 'Invalid path to psql - either wrong path or not executable';
 $string['pleaseregister'] = 'Please register your site to remove this button';
 $string['pgcluster'] = 'PostgreSQL Cluster';
-$string['pgclusterdescription'] = '<pre>PostgreSQL version/cluster parameter
-for command line operations.
-If you only have one postgresql
-on your system or you are not
-sure what this is, leave this blank.</pre>';
+$string['pgclusterdescription'] = 'PostgreSQL version/cluster parameter for command line operations. If you only have one postgresql on your system or you are not sure what this is, leave this blank.';
 $string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.';
 $string['sitelangchanged'] = 'Site language setting changed successfully';
 $string['sitemaintenance'] = 'The site is undergoing maintenance and is currently not available';