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