if they have pg_dump installed and set up, then use that to dump tables, not our...
authorchriskl <chriskl>
Sun, 21 Dec 2003 10:44:52 +0000 (10:44 +0000)
committerchriskl <chriskl>
Sun, 21 Dec 2003 10:44:52 +0000 (10:44 +0000)
dataexport.php
dbexport.php

index 4c107956fbef26d96300e7638c994d2a27e4d2b4..ab1b2b83726a72c38635da5935371c2452257c5f 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 
        /**
-        * Does an export to the screen or as a download
+        * Does an export to the screen or as a download.  This checks to
+        * see if they have pg_dump set up, and will use it if possible.
         *
-        * $Id: dataexport.php,v 1.7 2003/12/17 09:11:32 chriskl Exp $
+        * $Id: dataexport.php,v 1.8 2003/12/21 10:44:52 chriskl Exp $
         */
 
        $extensions = array(
 
        // If format is set, then perform the export
        if (isset($_REQUEST['what'])) {          
-                
+
+               // Include application functions
+               $_no_output = true;
+               include_once('./libraries/lib.inc.php');
+
                switch ($_REQUEST['what']) {
                        case 'dataonly':
-                               $format = $_REQUEST['d_format'];
-                               $oids = $_REQUEST['d_oids'];
+                               // Check to see if they have pg_dump set up and if they do, use that
+                               // instead of custom dump code
+                               if ($conf['pg_dump_path'] !== null && $conf['pg_dump_path'] != ''
+                                               && ($_REQUEST['d_format'] == 'copy' || $_REQUEST['d_format'] == 'sql')) {
+                                       $url = 'dbexport.php?database=' . urlencode($_REQUEST['database']);
+                                       $url .= '&what=' . urlencode($_REQUEST['what']);
+                                       $url .= '&table=' . urlencode($_REQUEST['table']);
+                                       $url .= '&d_format=' . urlencode($_REQUEST['d_format']);
+                                       if (isset($_REQUEST['d_oids'])) $url .= '&d_oids=' . urlencode($_REQUEST['d_oids']);
+                                       if (isset($_REQUEST['download'])) $url .= '&download=' . urlencode($_REQUEST['download']);
+                                       
+                                       header("Location: {$url}");
+                                       exit;
+                               }
+                               else {
+                                       $format = $_REQUEST['d_format'];
+                                       $oids = isset($_REQUEST['d_oids']);
+                               }
                                break;
                        case 'structureonly':
-                               $clean = $_REQUEST['s_clean'];
+                               // Check to see if they have pg_dump set up and if they do, use that
+                               // instead of custom dump code
+                               if ($conf['pg_dump_path'] !== null && $conf['pg_dump_path'] != '') {
+                                       $url = 'dbexport.php?database=' . urlencode($_REQUEST['database']);
+                                       $url .= '&what=' . urlencode($_REQUEST['what']);
+                                       $url .= '&table=' . urlencode($_REQUEST['table']);
+                                       if (isset($_REQUEST['s_clean'])) $url .= '&s_clean=' . urlencode($_REQUEST['s_clean']);
+                                       if (isset($_REQUEST['download'])) $url .= '&download=' . urlencode($_REQUEST['download']);
+                                       
+                                       header("Location: {$url}");
+                                       exit;
+                               }
+                               else $clean = isset($_REQUEST['s_clean']);
                                break;
                        case 'structureanddata':
-                               $format = $_REQUEST['sd_format'];
-                               $clean = $_REQUEST['sd_clean'];
-                               $oids = $_REQUEST['sd_oids'];
+                               // Check to see if they have pg_dump set up and if they do, use that
+                               // instead of custom dump code
+                               if ($conf['pg_dump_path'] !== null && $conf['pg_dump_path'] != '') {
+                                       $url = 'dbexport.php?database=' . urlencode($_REQUEST['database']);
+                                       $url .= '&what=' . urlencode($_REQUEST['what']);
+                                       $url .= '&table=' . urlencode($_REQUEST['table']);
+                                       $url .= '&sd_format=' . urlencode($_REQUEST['sd_format']);
+                                       if (isset($_REQUEST['sd_clean'])) $url .= '&sd_clean=' . urlencode($_REQUEST['sd_clean']);
+                                       if (isset($_REQUEST['sd_oids'])) $url .= '&sd_oids=' . urlencode($_REQUEST['sd_oids']);
+                                       if (isset($_REQUEST['download'])) $url .= '&download=' . urlencode($_REQUEST['download']);
+                                       
+                                       header("Location: {$url}");
+                                       exit;
+                               }
+                               else {
+                                       $format = $_REQUEST['sd_format'];
+                                       $clean = isset($_REQUEST['sd_clean']);
+                                       $oids = isset($_REQUEST['sd_oids']);
+                               }
                                break;
                }
 
                        header('Content-Type: text/plain');
                }
        
-               // Include application functions
-               $_no_output = true;
-               include_once('./libraries/lib.inc.php');
-       
                if (isset($_REQUEST['query'])) $_REQUEST['query'] = trim(unserialize($_REQUEST['query']));
 
                // Set up the dump transaction
 
                // If the dump is not dataonly then dump the structure prefix
                if ($_REQUEST['what'] != 'dataonly')
-                       echo $data->getTableDefPrefix($_REQUEST['table'], isset($clean));
+                       echo $data->getTableDefPrefix($_REQUEST['table'], $clean);
 
                // If the dump is not structureonly then dump the actual data
                if ($_REQUEST['what'] != 'structureonly') {
 
                        // Execute the query, if set, otherwise grab all rows from the table
                        if (isset($_REQUEST['table']))
-                               $rs = &$data->dumpRelation($_REQUEST['table'], isset($oids));
+                               $rs = &$data->dumpRelation($_REQUEST['table'], $oids);
                        else
                                $rs = $data->conn->Execute($_REQUEST['query']);
 
                        if ($format == 'copy') {
                                $data->fieldClean($_REQUEST['table']);
                                echo "COPY \"{$_REQUEST['table']}\"";
-                               if (isset($oids)) echo " WITH OIDS";
+                               if ($oids) echo " WITH OIDS";
                                echo " FROM stdin;\n";
                                while (!$rs->EOF) {
                                        $first = true;
                                        $j = 0;
                                        foreach ($rs->f as $k => $v) {
                                                $finfo = $rs->fetchField($j++);
-                                               if ($finfo->name == $data->id && !isset($oids)) continue;
+                                               if ($finfo->name == $data->id && !$oids) continue;
                                                echo "\t\t<th>", $misc->printVal($finfo->name, true), "</th>\r\n";
                                        }
                                }
                                        $j = 0;
                                        foreach ($rs->f as $k => $v) {
                                                $finfo = $rs->fetchField($j++);
-                                               if ($finfo->name == $data->id && !isset($oids)) continue;
+                                               if ($finfo->name == $data->id && !$oids) continue;
                                                echo "\t\t<td>", $misc->printVal($v, true, $finfo->type), "</td>\r\n";
                                        }
                                        echo "\t</tr>\r\n";
index 420c953aca64cb48e00b46bac80d8d09b226919a..f8f684e67063a0ca18b7d604c64539ecb26faaad 100644 (file)
@@ -1,8 +1,9 @@
 <?php
        /**
-        * Does an export of a database to the screen or as a download
+        * Does an export of a database to the screen or as a download.
+        * Can also dump a specific table of a database.
         *
-        * $Id: dbexport.php,v 1.3 2003/12/17 09:11:32 chriskl Exp $
+        * $Id: dbexport.php,v 1.4 2003/12/21 10:44:52 chriskl Exp $
         */
 
        // Include application functions
@@ -28,7 +29,7 @@
                $hostname = $conf['servers'][$_SESSION['webdbServerID']]['host'];
                $port = $conf['servers'][$_SESSION['webdbServerID']]['port'];
                $username = escapeshellarg($_SESSION['webdbUsername']);
-               $database = escapeshellarg($_REQUEST['database']);
+               $database = escapeshellarg($_REQUEST['database']);              
 
                // Build command for executing pg_dump
                $cmd = escapeshellcmd($conf['pg_dump_path']) . " -i -U {$username}";
                if ($port !== null && $port != '') {
                        $cmd .= " -p " . escapeshellarg($port);
                }
+               
+               // Check for a table specified
+               if (isset($_REQUEST['table'])) {
+                       $cmd .= " -t " . escapeshellarg($_REQUEST['table']);
+               }
                                
                switch ($_REQUEST['what']) {
                        case 'dataonly':
@@ -50,7 +56,7 @@
                                if (isset($_REQUEST['s_clean'])) $cmd .= ' -c';
                                break;
                        case 'structureanddata':
-                               if ($_REQUEST['sd_format'] == 'sql') $cmd .= ' -d';                             
+                               if ($_REQUEST['sd_format'] == 'sql') $cmd .= ' -d';
                                elseif (isset($_REQUEST['sd_oids'])) $cmd .= ' -o';
                                if (isset($_REQUEST['sd_clean'])) $cmd .= ' -c';
                                break;