thomascube
2009-03-02 11526305f506245af55e8ae7ea31faec49dfd98d
bin/dumpschema.php
@@ -1,4 +1,28 @@
#!/usr/bin/env php
<?php
/*
 +-----------------------------------------------------------------------+
 | bin/dumpschema.php                                                    |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Dumps database schema in XML format using MDB2_Schema               |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
 $Id$
*/
if (php_sapi_name() != 'cli') {
    die('Not on the "shell" (php-cli).');
}
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
require INSTALL_PATH.'program/include/iniset.php';
@@ -25,11 +49,21 @@
   'debug' => false,
   'quote_identifier' => true,
   'force_defaults' => false,
   'portability' => false
   'portability' => false,
);
$schema =& MDB2_Schema::factory($config->get('db_dsnw'), $options);
$dsnw = $config->get('db_dsnw');
$dsn_array = MDB2::parseDSN($dsnw);
// set options for postgres databases
if ($dsn_array['phptype'] == 'pgsql') {
   $options['disable_smart_seqname'] = true;
   $options['seqname_format'] = '%s';
}
$schema =& MDB2_Schema::factory($dsnw, $options);
$schema->db->supported['transactions'] = false;
// send as text/xml when opened in browser
if ($_SERVER['REMOTE_ADDR'])
@@ -44,8 +78,10 @@
      // 'output_mode' => 'file',
      'output' => 'print_schema',
   );
   $definition = $schema->getDefinitionFromDatabase();
   $definition['charset'] = 'utf8';
   if (PEAR::isError($definition)) {
      $error = $definition->getMessage() . ' ' . $definition->getUserInfo();
   }
@@ -59,7 +95,7 @@
$schema->disconnect();
//if ($error)
//   fputs(STDERR, $error);
if ($error && !$_SERVER['REMOTE_ADDR'])
   fputs(STDERR, $error);
?>