Aleksander Machniak
2016-05-22 77b5d7ee304a688a2eb115ce04b460b43c0dd700
commit | author | age
d48470 1 #!/usr/bin/env php
1e9cd5 2 <?php
155bbb 3 /*
A 4  +-----------------------------------------------------------------------+
30aa4c 5  | bin/dumpschema.sh                                                     |
155bbb 6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 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.                     |
155bbb 13  |                                                                       |
A 14  | PURPOSE:                                                              |
15  |   Dumps database schema in XML format using MDB2_Schema               |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
1e9cd5 21
0ea079 22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
6cc3f5 23
A 24 require INSTALL_PATH.'program/include/clisetup.php';
1e9cd5 25
T 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,
06c3d1 48     'portability' => false,
1e9cd5 49 );
T 50
e905db 51 $dsnw = $config->get('db_dsnw');
T 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);
1e9cd5 61 $schema->db->supported['transactions'] = false;
T 62
e905db 63
1e9cd5 64 // send as text/xml when opened in browser
T 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     );
155bbb 77     
1e9cd5 78     $definition = $schema->getDefinitionFromDatabase();
e905db 79     $definition['charset'] = 'utf8';
T 80
1e9cd5 81     if (PEAR::isError($definition)) {
T 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
e905db 94 if ($error && !$_SERVER['REMOTE_ADDR'])
T 95     fputs(STDERR, $error);
1e9cd5 96
T 97 ?>