diff options
author | thomascube <thomas@roundcube.net> | 2008-09-18 13:13:08 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2008-09-18 13:13:08 +0000 |
commit | 1e9cd56403a35e33d2fcf561c7a7a8a396396378 (patch) | |
tree | f9c3bfd5d01a415a4bac4cbfa50f0de0eaaa8adf /bin/dumpschema.php | |
parent | dda75730ae64dc71a90e0b09ce7ee3e8f6451549 (diff) |
Script to dump the current database schema using MDB2_Schema (for development only)
Diffstat (limited to 'bin/dumpschema.php')
-rw-r--r-- | bin/dumpschema.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/bin/dumpschema.php b/bin/dumpschema.php new file mode 100644 index 000000000..683e2719e --- /dev/null +++ b/bin/dumpschema.php @@ -0,0 +1,65 @@ +<?php + +define('INSTALL_PATH', realpath('./../') . '/'); +require INSTALL_PATH.'program/include/iniset.php'; + +/** callback function for schema dump **/ +function print_schema($dump) +{ + foreach ((array)$dump as $part) + echo $dump . "\n"; +} + +$config = new rcube_config(); + +// don't allow public access if not in devel_mode +if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) { + header("HTTP/1.0 401 Access denied"); + die("Access denied!"); +} + +$options = array( + 'use_transactions' => false, + 'log_line_break' => "\n", + 'idxname_format' => '%s', + 'debug' => false, + 'quote_identifier' => true, + 'force_defaults' => false, + 'portability' => false +); + +$schema =& MDB2_Schema::factory($config->get('db_dsnw'), $options); +$schema->db->supported['transactions'] = false; + +// send as text/xml when opened in browser +if ($_SERVER['REMOTE_ADDR']) + header('Content-Type: text/xml'); + + +if (PEAR::isError($schema)) { + $error = $schema->getMessage() . ' ' . $schema->getUserInfo(); +} +else { + $dump_config = array( + // 'output_mode' => 'file', + 'output' => 'print_schema', + ); + + $definition = $schema->getDefinitionFromDatabase(); + if (PEAR::isError($definition)) { + $error = $definition->getMessage() . ' ' . $definition->getUserInfo(); + } + else { + $operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_STRUCTURE); + if (PEAR::isError($operation)) { + $error = $operation->getMessage() . ' ' . $operation->getUserInfo(); + } + } +} + +$schema->disconnect(); + +//if ($error) +// fputs(STDERR, $error); + +?> |