From 9c9aeef15cf56c303c97954e68b07760f639725a Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Wed, 5 Apr 2006 03:54:12 +0000 Subject: [PATCH] Fixing postgres unicode migration for mac os x and multiple postgres installations --- admin/utfdbmigrate.html | 24 ++++++++++++++++++++---- admin/utfdbmigrate.php | 34 +++++++++++++++++++++++++++++++--- lang/en_utf8/admin.php | 12 +++++++----- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/admin/utfdbmigrate.html b/admin/utfdbmigrate.html index 7854b577d0..1f118fa6e8 100644 --- a/admin/utfdbmigrate.html +++ b/admin/utfdbmigrate.html @@ -14,12 +14,20 @@ if (!isset($form->dbcluster)) { $form->dbcluster = ''; } + if (!isset($form->pathtopgdump)) { + $form->pathtopgdump = ''; + } + if (!isset($form->pathtopsql)) { + $form->pathtopsql = ''; + } ?>
- + + +
+ + + + + + + + +
: @@ -43,9 +51,17 @@
: -
- -
: +
: +
diff --git a/admin/utfdbmigrate.php b/admin/utfdbmigrate.php index 5b9afcf47c..873632d022 100755 --- a/admin/utfdbmigrate.php +++ b/admin/utfdbmigrate.php @@ -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; } diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 636941c9ec..6623e5f8b4 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -203,13 +203,15 @@ $string['order3'] = 'Third'; $string['pathdvips'] = 'Path of dvips binary'; $string['pathconvert'] = 'Path of convert binary'; $string['pathlatex'] = 'Path of latex 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'] = '
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['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'; -- 2.39.5