5 +-----------------------------------------------------------------------+
8 | This file is part of the Roundcube Webmail client |
9 | Copyright (C) 2005-2009, The Roundcube Dev Team |
10 | Licensed under the GNU GPL |
13 | Dumps database schema in XML format using MDB2_Schema |
15 +-----------------------------------------------------------------------+
16 | Author: Thomas Bruederli <roundcube@gmail.com> |
17 +-----------------------------------------------------------------------+
19 $Id: dumpschema.sh 4677 2011-04-20 13:10:45Z alec $
23 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
25 require INSTALL_PATH.'program/include/clisetup.php';
27 /** callback function for schema dump **/
28 function print_schema($dump)
30 foreach ((array)$dump as $part)
34 $config = new rcube_config();
36 // don't allow public access if not in devel_mode
37 if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) {
38 header("HTTP/1.0 401 Access denied");
39 die("Access denied!");
43 'use_transactions' => false,
44 'log_line_break' => "\n",
45 'idxname_format' => '%s',
47 'quote_identifier' => true,
48 'force_defaults' => false,
49 'portability' => false,
52 $dsnw = $config->get('db_dsnw');
53 $dsn_array = MDB2::parseDSN($dsnw);
55 // set options for postgres databases
56 if ($dsn_array['phptype'] == 'pgsql') {
57 $options['disable_smart_seqname'] = true;
58 $options['seqname_format'] = '%s';
61 $schema =& MDB2_Schema::factory($dsnw, $options);
62 $schema->db->supported['transactions'] = false;
65 // send as text/xml when opened in browser
66 if ($_SERVER['REMOTE_ADDR'])
67 header('Content-Type: text/xml');
70 if (PEAR::isError($schema)) {
71 $error = $schema->getMessage() . ' ' . $schema->getUserInfo();
75 // 'output_mode' => 'file',
76 'output' => 'print_schema',
79 $definition = $schema->getDefinitionFromDatabase();
80 $definition['charset'] = 'utf8';
82 if (PEAR::isError($definition)) {
83 $error = $definition->getMessage() . ' ' . $definition->getUserInfo();
86 $operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_STRUCTURE);
87 if (PEAR::isError($operation)) {
88 $error = $operation->getMessage() . ' ' . $operation->getUserInfo();
93 $schema->disconnect();
95 if ($error && !$_SERVER['REMOTE_ADDR'])
96 fputs(STDERR, $error);