commit | author | age
|
d48470
|
1 |
#!/usr/bin/env php |
1e9cd5
|
2 |
<?php |
155bbb
|
3 |
/* |
A |
4 |
|
|
5 |
+-----------------------------------------------------------------------+ |
|
6 |
| bin/dumpschema.php | |
|
7 |
| | |
|
8 |
| This file is part of the RoundCube Webmail client | |
cbbef3
|
9 |
| Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | |
155bbb
|
10 |
| Licensed under the GNU GPL | |
A |
11 |
| | |
|
12 |
| PURPOSE: | |
|
13 |
| Dumps database schema in XML format using MDB2_Schema | |
|
14 |
| | |
|
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
|
|
19 |
$Id$ |
|
20 |
|
|
21 |
*/ |
1e9cd5
|
22 |
|
d48470
|
23 |
if (php_sapi_name() != 'cli') { |
T |
24 |
die('Not on the "shell" (php-cli).'); |
|
25 |
} |
|
26 |
|
da402d
|
27 |
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); |
1e9cd5
|
28 |
require INSTALL_PATH.'program/include/iniset.php'; |
T |
29 |
|
|
30 |
/** callback function for schema dump **/ |
|
31 |
function print_schema($dump) |
|
32 |
{ |
|
33 |
foreach ((array)$dump as $part) |
|
34 |
echo $dump . "\n"; |
|
35 |
} |
|
36 |
|
|
37 |
$config = new rcube_config(); |
|
38 |
|
|
39 |
// don't allow public access if not in devel_mode |
|
40 |
if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) { |
|
41 |
header("HTTP/1.0 401 Access denied"); |
|
42 |
die("Access denied!"); |
|
43 |
} |
|
44 |
|
|
45 |
$options = array( |
|
46 |
'use_transactions' => false, |
|
47 |
'log_line_break' => "\n", |
|
48 |
'idxname_format' => '%s', |
|
49 |
'debug' => false, |
|
50 |
'quote_identifier' => true, |
|
51 |
'force_defaults' => false, |
06c3d1
|
52 |
'portability' => false, |
1e9cd5
|
53 |
); |
T |
54 |
|
e905db
|
55 |
$dsnw = $config->get('db_dsnw'); |
T |
56 |
$dsn_array = MDB2::parseDSN($dsnw); |
|
57 |
|
|
58 |
// set options for postgres databases |
|
59 |
if ($dsn_array['phptype'] == 'pgsql') { |
|
60 |
$options['disable_smart_seqname'] = true; |
|
61 |
$options['seqname_format'] = '%s'; |
|
62 |
} |
|
63 |
|
|
64 |
$schema =& MDB2_Schema::factory($dsnw, $options); |
1e9cd5
|
65 |
$schema->db->supported['transactions'] = false; |
T |
66 |
|
e905db
|
67 |
|
1e9cd5
|
68 |
// send as text/xml when opened in browser |
T |
69 |
if ($_SERVER['REMOTE_ADDR']) |
|
70 |
header('Content-Type: text/xml'); |
|
71 |
|
|
72 |
|
|
73 |
if (PEAR::isError($schema)) { |
|
74 |
$error = $schema->getMessage() . ' ' . $schema->getUserInfo(); |
|
75 |
} |
|
76 |
else { |
|
77 |
$dump_config = array( |
|
78 |
// 'output_mode' => 'file', |
|
79 |
'output' => 'print_schema', |
|
80 |
); |
155bbb
|
81 |
|
1e9cd5
|
82 |
$definition = $schema->getDefinitionFromDatabase(); |
e905db
|
83 |
$definition['charset'] = 'utf8'; |
T |
84 |
|
1e9cd5
|
85 |
if (PEAR::isError($definition)) { |
T |
86 |
$error = $definition->getMessage() . ' ' . $definition->getUserInfo(); |
|
87 |
} |
|
88 |
else { |
|
89 |
$operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_STRUCTURE); |
|
90 |
if (PEAR::isError($operation)) { |
|
91 |
$error = $operation->getMessage() . ' ' . $operation->getUserInfo(); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
$schema->disconnect(); |
|
97 |
|
e905db
|
98 |
if ($error && !$_SERVER['REMOTE_ADDR']) |
T |
99 |
fputs(STDERR, $error); |
1e9cd5
|
100 |
|
T |
101 |
?> |