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