3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20
ini_set('error_reporting', 2047);
21
if (!empty($_SERVER['SERVER_NAME'])) {
22
print "You must run this from the command line\n";
26
require_once(dirname(__FILE__) . '/XmlParser.inc');
27
require_once(dirname(__FILE__) . '/../../smarty/Smarty.class.php');
29
$tmpdir = dirname(__FILE__) . '/tmp_dbxml_' . rand(1, 30000);
30
if (file_exists($tmpdir)) {
31
print "Tmp dir already exists: $tmpdir\n";
35
if (!mkdir($tmpdir)) {
36
print "Unable to make tmp dir: $tmpdir\n";
40
$smarty = new Smarty();
41
$smarty->compile_dir = $tmpdir;
42
$smarty->error_reporting = error_reporting();
43
$smarty->debugging = true;
44
$smarty->use_sub_dirs = false;
45
$smarty->template_dir = dirname(__FILE__);
47
function generateEntityDbXml() {
50
$entityXmlFiles = glob('tmp/classxml/*.xml');
51
if (empty($entityXmlFiles)) {
54
foreach ($entityXmlFiles as $xmlFile) {
55
$p =& new XmlParser();
56
$root = $p->parse($xmlFile);
57
$base = basename($xmlFile);
58
$base = preg_replace('/\.[^\.]*$/', '', $base);
59
$tmpFile = "tmp/dbxml/$base.xml";
60
$origFile = "$base.xml";
62
$membersBase = $root[0]['child'];
64
'name' => $root[0]['child'][2]['child'][0]['content'],
65
'major' => $root[0]['child'][2]['child'][1]['content'],
66
'minor' => (!empty($root[0]['child'][2]['child'][2]['content']) ?
67
$root[0]['child'][2]['child'][2]['content'] : 0));
73
foreach ($membersBase as $child) {
74
switch($child['name']) {
76
$member = array('name' => $child['child'][0]['content'],
77
'type' => $child['child'][1]['content'],
78
'ucName' => ucfirst($child['child'][0]['content']),
79
'lcType' => strtolower($child['child'][1]['content']));
80
for ($i = 2; $i < count($child['child']); $i++) {
81
switch($child['child'][$i]['name']) {
83
$member['size'] = $child['child'][$i]['content'];
87
$indexes[] = array('columns' => array($member['name']));
88
$member[strtolower($child['child'][$i]['name'])] = 1;
92
$keys[] = array('columns' => array($member['name']));
93
$member[strtolower($child['child'][$i]['name'])] = 1;
97
$keys[] = array('columns' => array($member['name']), 'primary' => 1);
98
$member['primary'] = 1;
103
$member[strtolower($child['child'][$i]['name'])] = 1;
107
$member['required'] = array();
108
if (isset($child['child'][$i]['attrs']['EMPTY'])) {
109
$member['required']['empty'] = $child['child'][$i]['attrs']['EMPTY'];
111
$member['required']['empty'] = 'disallowed';
116
$member['default'] = $child['child'][$i]['content'];
119
case 'MEMBER-EXTERNAL-ACCESS':
120
/* Not relevant for storage layer */
124
print 'Unknown member type: ' . $child['child'][$i]['name'] . '\n';
128
if (empty($member['size'])) {
129
$member['size'] = 'MEDIUM';
132
$members[] = $member;
137
foreach ($child['child'] as $column) {
138
$key['columns'][] = $column['content'];
141
isset($child['attrs']['PRIMARY']) && $child['attrs']['PRIMARY'] == 'true';
147
foreach ($child['child'] as $column) {
148
$index['columns'][] = $column['content'];
151
isset($child['attrs']['PRIMARY']) && $child['attrs']['PRIMARY'] == 'true';
158
$keys[] = array('columns' => array('id'), 'primary' => 1);
163
$smarty->assign('root', $root);
164
$smarty->assign('schema', $schema);
165
$smarty->assign('members', $members);
166
$smarty->assign('keys', $keys);
167
$smarty->assign('indexes', $indexes);
168
$smarty->assign('requiresId', $requiresId);
169
$smarty->assign('isMap', false);
170
$new = $smarty->fetch('dbxml.tpl');
172
$fd = fopen($tmpFile, "w");
178
function generateMapDbXml() {
181
$xmlFile = '../Maps.xml';
182
if (!file_exists($xmlFile)) {
186
$p =& new XmlParser();
187
$root = $p->parse($xmlFile);
188
$base = basename($xmlFile);
189
$base = preg_replace('/\.[^\.]*$/', '', $base);
190
$origFile = "$base.xml";
192
foreach ($root[0]['child'] as $map) {
193
$origMapName = $map['child'][0]['content'];
196
* NOTE! Keep this in sync with the similar block in extractClassXml.pl
197
* and generate-entities.php
199
$mapName = $origMapName;
200
$mapName = preg_replace('/^Gallery/', '', $mapName);
201
/* Shorten some table names to fit Oracle's 30 char name limit.. */
202
$mapName = str_replace('Preferences', 'Prefs', $mapName);
203
$mapName = str_replace('Toolkit', 'Tk', $mapName);
204
$mapName = str_replace('TkOperation', 'TkOperatn', $mapName);
208
'major' => $map['child'][1]['child'][0]['content'],
209
'minor' => $map['child'][1]['child'][1]['content']);
210
$tmpFile = "tmp/dbxml/$origMapName.xml";
216
for ($j = 2; $j < count($map['child']); $j++) {
217
$child = $map['child'][$j];
218
switch($child['name']) {
220
$member = array('name' => $child['child'][0]['content'],
221
'type' => $child['child'][1]['content'],
222
'ucName' => ucfirst($child['child'][0]['content']),
223
'lcType' => strtolower($child['child'][1]['content']));
224
for ($i = 2; $i < count($child['child']); $i++) {
225
switch($child['child'][$i]['name']) {
227
$member['size'] = $child['child'][$i]['content'];
231
$indexes[] = array('columns' => array($member['name']));
232
$member[strtolower($child['child'][$i]['name'])] = 1;
236
$keys[] = array('columns' => array($member['name']));
237
$member[strtolower($child['child'][$i]['name'])] = 1;
241
$keys[] = array('columns' => array($member['name']), 'primary' => 1);
242
$member['primary'] = 1;
246
$member['required'] = array();
247
if (isset($child['child'][$i]['attrs']['EMPTY'])) {
248
$member['required']['empty'] = $child['child'][$i]['attrs']['EMPTY'];
250
$member['required']['empty'] = 'disallowed';
255
$member['default'] = $child['child'][$i]['content'];
258
case 'MEMBER-EXTERNAL-ACCESS':
259
/* Not relevant for storage layer */
263
print 'Unknown member type: ' . $child['child'][$i]['name'] . '\n';
267
if (empty($member['size'])) {
268
$member['size'] = 'MEDIUM';
271
$members[] = $member;
276
foreach ($child['child'] as $column) {
277
$key['columns'][] = $column['content'];
280
isset($child['attrs']['PRIMARY']) && $child['attrs']['PRIMARY'] == 'true';
286
foreach ($child['child'] as $column) {
287
$index['columns'][] = $column['content'];
290
isset($child['attrs']['PRIMARY']) && $child['attrs']['PRIMARY'] == 'true';
296
$smarty->assign('root', $root);
297
$smarty->assign('schema', $schema);
298
$smarty->assign('members', $members);
299
$smarty->assign('keys', $keys);
300
$smarty->assign('indexes', $indexes);
301
$smarty->assign('requiresId', $requiresId);
302
$smarty->assign('isMap', true);
303
$new = $smarty->fetch('dbxml.tpl');
305
$fd = fopen($tmpFile, "w");
312
generateEntityDbXml();
315
/* Clean up the cheap and easy way */
316
if (file_exists($tmpdir)) {
317
system("rm -rf $tmpdir");