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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
<?php
/**
*
* @package phpBB3
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
* This file creates new schema files for every database.
* The filenames will be prefixed with an underscore to not overwrite the current schema files.
*
* If you overwrite the original schema files please make sure you save the file with UNIX linefeeds.
*/
$schema_path = dirname(__FILE__) . '/../install/schemas/';
if (!is_writable($schema_path))
{
die('Schema path not writable');
}
define('IN_PHPBB', true);
define('IN_INSTALL', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$classes = $phpbb_container->get('ext.manager')
->get_finder()
->core_path('phpbb/')
->directory('db/migration/data')
->get_classes();
$db_tools = new \phpbb\db\tools($db, true);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, $config, $db, $db_tools, $phpbb_root_path, $phpEx, 'phpbb_');
$schema_data = $schema_generator->get_schema();
$dbms_type_map = phpbb\db\tools::get_dbms_type_map();
$fp = fopen($schema_path . 'schema.json', 'wb');
fwrite($fp, json_encode($schema_data, JSON_PRETTY_PRINT));
fclose($fp);
$supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite');
foreach ($supported_dbms as $dbms)
{
$fp = fopen($schema_path . $dbms . '_schema.sql', 'wb');
// Write Header
switch ($dbms)
{
case 'mysql_40':
case 'mysql_41':
case 'firebird':
case 'sqlite':
fwrite($fp, "# DO NOT EDIT THIS FILE, IT IS GENERATED\n");
fwrite($fp, "#\n");
fwrite($fp, "# To change the contents of this file, edit\n");
fwrite($fp, "# phpBB/develop/create_schema_files.php and\n");
fwrite($fp, "# run it.\n");
break;
case 'mssql':
case 'oracle':
case 'postgres':
fwrite($fp, "/*\n");
fwrite($fp, " * DO NOT EDIT THIS FILE, IT IS GENERATED\n");
fwrite($fp, " *\n");
fwrite($fp, " * To change the contents of this file, edit\n");
fwrite($fp, " * phpBB/develop/create_schema_files.php and\n");
fwrite($fp, " * run it.\n");
fwrite($fp, " */\n\n");
break;
}
$line = '';
switch ($dbms)
{
case 'firebird':
$line .= custom_data('firebird') . "\n";
break;
case 'oracle':
$line .= custom_data('oracle') . "\n";
break;
case 'postgres':
$line .= "BEGIN;\n\n";
$line .= custom_data('postgres') . "\n";
$line .= "COMMIT;\n\n";
break;
}
fwrite($fp, $line);
fclose($fp);
}
/**
* Data put into the header for various dbms
*/
function custom_data($dbms)
{
switch ($dbms)
{
case 'oracle':
return <<<EOF
/*
This first section is optional, however its probably the best method
of running phpBB on Oracle. If you already have a tablespace and user created
for phpBB you can leave this section commented out!
The first set of statements create a phpBB tablespace and a phpBB user,
make sure you change the password of the phpBB user before you run this script!!
*/
/*
CREATE TABLESPACE "PHPBB"
LOGGING
DATAFILE 'E:\ORACLE\ORADATA\LOCAL\PHPBB.ora'
SIZE 10M
AUTOEXTEND ON NEXT 10M
MAXSIZE 100M;
CREATE USER "PHPBB"
PROFILE "DEFAULT"
IDENTIFIED BY "phpbb_password"
DEFAULT TABLESPACE "PHPBB"
QUOTA UNLIMITED ON "PHPBB"
ACCOUNT UNLOCK;
GRANT ANALYZE ANY TO "PHPBB";
GRANT CREATE SEQUENCE TO "PHPBB";
GRANT CREATE SESSION TO "PHPBB";
GRANT CREATE TABLE TO "PHPBB";
GRANT CREATE TRIGGER TO "PHPBB";
GRANT CREATE VIEW TO "PHPBB";
GRANT "CONNECT" TO "PHPBB";
COMMIT;
DISCONNECT;
CONNECT phpbb/phpbb_password;
*/
EOF;
break;
case 'postgres':
return <<<EOF
/*
Domain definition
*/
CREATE DOMAIN varchar_ci AS varchar(255) NOT NULL DEFAULT ''::character varying;
/*
Operation Functions
*/
CREATE FUNCTION _varchar_ci_equal(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) = LOWER($2)' LANGUAGE SQL STRICT;
CREATE FUNCTION _varchar_ci_not_equal(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) != LOWER($2)' LANGUAGE SQL STRICT;
CREATE FUNCTION _varchar_ci_less_than(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) < LOWER($2)' LANGUAGE SQL STRICT;
CREATE FUNCTION _varchar_ci_less_equal(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) <= LOWER($2)' LANGUAGE SQL STRICT;
CREATE FUNCTION _varchar_ci_greater_than(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) > LOWER($2)' LANGUAGE SQL STRICT;
CREATE FUNCTION _varchar_ci_greater_equals(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) >= LOWER($2)' LANGUAGE SQL STRICT;
/*
Operators
*/
CREATE OPERATOR <(
PROCEDURE = _varchar_ci_less_than,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = >,
NEGATOR = >=,
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel);
CREATE OPERATOR <=(
PROCEDURE = _varchar_ci_less_equal,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = >=,
NEGATOR = >,
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel);
CREATE OPERATOR >(
PROCEDURE = _varchar_ci_greater_than,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = <,
NEGATOR = <=,
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel);
CREATE OPERATOR >=(
PROCEDURE = _varchar_ci_greater_equals,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = <=,
NEGATOR = <,
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel);
CREATE OPERATOR <>(
PROCEDURE = _varchar_ci_not_equal,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = <>,
NEGATOR = =,
RESTRICT = neqsel,
JOIN = neqjoinsel);
CREATE OPERATOR =(
PROCEDURE = _varchar_ci_equal,
LEFTARG = varchar_ci,
RIGHTARG = varchar_ci,
COMMUTATOR = =,
NEGATOR = <>,
RESTRICT = eqsel,
JOIN = eqjoinsel,
HASHES,
MERGES,
SORT1= <);
EOF;
break;
}
return '';
}
echo 'done';
|