forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.exportcontroller.php
More file actions
99 lines (88 loc) · 3.06 KB
/
Copy pathclass.exportcontroller.php
File metadata and controls
99 lines (88 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @copyright Vanilla Forums Inc. 2010
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPL2
* @package VanillaPorter
*/
/** Generic controller implemented by forum-specific ones */
abstract class ExportController {
/** @var array Database connection info */
protected $DbInfo = array();
/** @var array Required tables, columns set per exporter */
protected $SourceTables = array();
protected $UseStreaming = FALSE;
/** Forum-specific export routine */
abstract protected function ForumExport($Ex);
/**
* Construct and set the controller's properties from the posted form.
*/
public function __construct() {
$this->HandleInfoForm();
}
/**
* Logic for export process
*/
public function DoExport() {
global $Supported;
// Test connection
$Msg = $this->TestDatabase();
if($Msg === true) {
// Create db object
$Ex = new ExportModel;
$Ex->SetConnection($this->DbInfo['dbhost'], $this->DbInfo['dbuser'], $this->DbInfo['dbpass'], $this->DbInfo['dbname']);
$Ex->Prefix = $this->DbInfo['prefix'];
$Ex->UseStreaming = $this->UseStreaming;
// Test src tables' existence structure
$Msg = $Ex->VerifySource($this->SourceTables);
if($Msg === true) {
// Good src tables - Start dump
$Ex->UseCompression(TRUE);
$Ex->FilenamePrefix = $this->DbInfo['dbname'];
set_time_limit(60*60);
$this->ForumExport($Ex);
// Write the results.
if($Ex->UseStreaming)
exit;
else
ViewExportResult($Ex->Comments, 'Info', $Ex->Path);
}
else
ViewForm(array('Supported' => $Supported, 'Msg' => $Msg, 'Info' => $this->DbInfo)); // Back to form with error
}
else
ViewForm(array('Supported' => $Supported, 'Msg' => $Msg, 'Info' => $this->DbInfo)); // Back to form with error
}
/**
* User submitted db connection info
*/
public function HandleInfoForm() {
$this->DbInfo = array(
'dbhost' => $_POST['dbhost'],
'dbuser' => $_POST['dbuser'],
'dbpass' => $_POST['dbpass'],
'dbname' => $_POST['dbname'],
'type' => $_POST['type'],
'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix']));
$this->UseStreaming = array_key_exists('savefile', $_POST) ? FALSE : TRUE;
}
/**
* Test database connection info
*/
public function TestDatabase() {
// Connection
if($C = @mysql_connect($this->DbInfo['dbhost'], $this->DbInfo['dbuser'], $this->DbInfo['dbpass'])) {
// Database
if(mysql_select_db($this->DbInfo['dbname'], $C)) {
mysql_close($C);
return true;
}
else {
mysql_close($C);
return 'Could not find database “'.$this->DbInfo['dbname'].'”.';
}
}
else
return 'Could not connect to '.$this->DbInfo['dbhost'].' as '.$this->DbInfo['dbuser'].' with given password.';
}
}
?>