summaryrefslogtreecommitdiff
path: root/bin/dumpschema.php
blob: 53c688c3dc6b17212c92f1315502f53a1eed7b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
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);

?>