DataObjects/Builder_tables.php
authorEdward <edward@roojs.com>
Fri, 6 Jun 2014 08:43:11 +0000 (16:43 +0800)
committerEdward <edward@roojs.com>
Fri, 6 Jun 2014 08:43:11 +0000 (16:43 +0800)
DataObjects/Builder_tables.php

index b394afa..a12c39a 100644 (file)
@@ -253,4 +253,58 @@ class Pman_Builder_DataObjects_Builder_tables extends DB_DataObject
 //        exit;
 //    }
     
+    function dumpDatabase()
+    {
+        $roo = HTML_FlexyFramework::get()->page;
+        
+        $dsn = HTML_FlexyFramework::get()->database;
+        print_r($dsn);exit;
+        $database = explode('@', $dsn);
+        
+        $ui = str_replace('mysql://', '', $database[0]);
+        
+        $user = array_shift(explode(':', $ui));
+        $pw = array_pop(explode(':', $ui));
+        
+        $host = array_shift(explode('/', $database[1]));
+        $dn = array_pop(explode('/', $database[1]));
+        
+        $cmd = "mysqldump -u{$user} ";
+        if(!empty($pw)){
+            $cmd .= "-p{$pw} ";
+        }
+        
+        $cmd .= "--no-create-info summit {$tn}";
+        
+        require_once 'System.php';
+            
+        $tmpdir  = System::mktemp("-d dump");
+
+        $path = $tmpdir . '/' . $tn . '.sql';
+        
+        ob_start();
+        
+        passthru($cmd);
+        
+        $data = ob_get_contents();
+        
+        ob_end_clean();
+        
+        file_put_contents($path, $data);
+        
+        header('Content-Description: File Transfer');
+        header ('Content-Type: application/octet-stream');
+        header("Content-Disposition: attachment; filename=\"".basename($path)."\";" );
+        header("Expires: 0");
+        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
+        header("Pragma: public");
+        header('Content-Length: ' . filesize($path));
+        
+        @ob_clean();
+        flush();
+        readfile($path);
+        
+        exit;
+    }
+    
 }