You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dumpschema.sh 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | bin/dumpschema.sh |
  6. | |
  7. | This file is part of the Roundcube Webmail client |
  8. | Copyright (C) 2005-2009, The Roundcube Dev Team |
  9. | |
  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. |
  13. | |
  14. | PURPOSE: |
  15. | Dumps database schema in XML format using MDB2_Schema |
  16. | |
  17. +-----------------------------------------------------------------------+
  18. | Author: Thomas Bruederli <roundcube@gmail.com> |
  19. +-----------------------------------------------------------------------+
  20. */
  21. define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
  22. require INSTALL_PATH.'program/include/clisetup.php';
  23. /** callback function for schema dump **/
  24. function print_schema($dump)
  25. {
  26. foreach ((array)$dump as $part)
  27. echo $dump . "\n";
  28. }
  29. $config = new rcube_config();
  30. // don't allow public access if not in devel_mode
  31. if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) {
  32. header("HTTP/1.0 401 Access denied");
  33. die("Access denied!");
  34. }
  35. $options = array(
  36. 'use_transactions' => false,
  37. 'log_line_break' => "\n",
  38. 'idxname_format' => '%s',
  39. 'debug' => false,
  40. 'quote_identifier' => true,
  41. 'force_defaults' => false,
  42. 'portability' => false,
  43. );
  44. $dsnw = $config->get('db_dsnw');
  45. $dsn_array = MDB2::parseDSN($dsnw);
  46. // set options for postgres databases
  47. if ($dsn_array['phptype'] == 'pgsql') {
  48. $options['disable_smart_seqname'] = true;
  49. $options['seqname_format'] = '%s';
  50. }
  51. $schema =& MDB2_Schema::factory($dsnw, $options);
  52. $schema->db->supported['transactions'] = false;
  53. // send as text/xml when opened in browser
  54. if ($_SERVER['REMOTE_ADDR'])
  55. header('Content-Type: text/xml');
  56. if (PEAR::isError($schema)) {
  57. $error = $schema->getMessage() . ' ' . $schema->getUserInfo();
  58. }
  59. else {
  60. $dump_config = array(
  61. // 'output_mode' => 'file',
  62. 'output' => 'print_schema',
  63. );
  64. $definition = $schema->getDefinitionFromDatabase();
  65. $definition['charset'] = 'utf8';
  66. if (PEAR::isError($definition)) {
  67. $error = $definition->getMessage() . ' ' . $definition->getUserInfo();
  68. }
  69. else {
  70. $operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_STRUCTURE);
  71. if (PEAR::isError($operation)) {
  72. $error = $operation->getMessage() . ' ' . $operation->getUserInfo();
  73. }
  74. }
  75. }
  76. $schema->disconnect();
  77. if ($error && !$_SERVER['REMOTE_ADDR'])
  78. fputs(STDERR, $error);
  79. ?>