-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_helper.php
386 lines (342 loc) · 12.9 KB
/
install_helper.php
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
// if we are running in the webserver, bail out
if (isset($_SERVER["REMOTE_ADDR"])) {
trigger_error(
"This script cannot be run from a browser.\n",
E_USER_ERROR
);
}
define("phorum_page", "sphinx_install_helper");
define("PHORUM_ADMIN", 1);
// I guess the phorum-directory should be two levels up.
$PHORUM_DIRECTORY = dirname(__FILE__) . "/../../";
// change directory to the main-dir so we can use common.php
if(file_exists($PHORUM_DIRECTORY."/common.php")) {
chdir($PHORUM_DIRECTORY);
if (!is_readable("./common.php")) {
fprintf(STDERR,
"Unable to read common.php from directory $PHORUM_DIRECTORY\n");
exit(1);
}
} else {
fprintf(STDERR,
"Unable to find Phorum file \"common.php\".\n" .
"Please check the \$PHORUM_DIRECTORY in " . basename(__FILE__) ."\n");
exit(1);
}
require_once("common.php");
// Check the db configuration. We only do Sphinx for MySQL, so check if
// we have MySQL as our database and if it's fully configured.
if (!strstr($PHORUM["DBCONFIG"]["type"], "mysql")) {
trigger_error(
"It looks like you database type is not MySQL.\n" .
"This module only runs with MySQL as the database backend.\n",
E_USER_ERROR
);
}
foreach (array("server", "name", "user", "password", "table_prefix") as $fld) {
if (!isset($PHORUM["DBCONFIG"][$fld])) trigger_error(
"The configuration field \"$fld\" is missing in your Phorum\n" .
"database configuration include/db/config.php. Please fix this\n" .
"and retry running this script.\n",
E_USER_ERROR
);
}
print "\nSphinx install helper\n" .
"---------------------\n\n";
// This array holds the Sphinx configuration variables that we are using.
$options = array
(
array(
"DBHOST",
$PHORUM["DBCONFIG"]["server"],
"The hostname for connecting to the Phorum database server\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array(
"DBPORT",
3306,
"The port at which the Phorum database server is running (default\n" .
"is \"3306\" and normally you should not have to change that value)."
),
array(
"DBNAME",
$PHORUM["DBCONFIG"]["name"],
"The name of the Phorum database.\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array (
"DBUSER",
$PHORUM["DBCONFIG"]["user"],
"The username for accessing the Phorum database.\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array (
"DBPASS",
$PHORUM["DBCONFIG"]["password"],
"The password for the Phorum database.\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array (
"DBPREFIX",
$PHORUM["DBCONFIG"]["table_prefix"],
"The database prefix for the Phorum database.\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array (
"MESSAGE_TABLE",
isset($PHORUM["message_table"])
? $PHORUM["message_table"] : "",
"This is the name of the Phorum database table in which the forum\n" .
"messages are stored.\n" .
"\n" .
"You should not have to change this value, since the default value\n".
"is the actual value that Phorum is uses for accessing your Phorum\n".
"database data."
),
array (
"DATAPATH",
"/var/sphinx",
"The path to the directory where you will store the Sphinx data\n" .
"files. This directory should be writable for the user which is\n" .
"running the Sphinx software and readable for the user which is\n" .
"running the webserver software.\n" .
"\n" .
"Note: This path does not determine where the generated Sphinx\n" .
"configuration file will be written. You will be able to enter the\n" .
"location for writing that file, after choosing the \"g\"enerate \n" .
"menu option.",
TRUE
),
array (
"USE_DELTA_UPDATES",
0,
"If you set this option to a true value (e.g. \"1\"), then the\n" .
"configuration file will have support for doing \"delta updates\"\n" .
"for the search data. This means that two different indexes will\n" .
"be used by the Sphinx system. One index will be updated on a\n" .
"slow schedule (like twice a day). This index will hold all data\n" .
"for messages that were posted up to the time of indexing. The\n" .
"other index will be updated on a really regular base (like each\n" .
"15 minutes or even more regular). This index will hold all data\n" .
"for messages that were posted after the last full index update.\n" .
"\n" .
"Note: for running the delta updates schedule, you will need to run\n".
"MySQL server version 4.1 or higher. It will not work on older\n" .
"versions of MySQL because of lacking features.",
TRUE
),
array (
"MAX_SEARCH_RESULTS",
1000,
"This is the maximum number of search results that the Sphinx\n" .
"search engine will return to Phorum (default is \"1000\").\n"
),
array (
"DATA_PREFIX",
$PHORUM["DBCONFIG"]["table_prefix"],
"This prefix is used as a prefix for all the Sphinx sources,\n" .
"indexes and data files. You can choose anything here you like,\n" .
"as long as this prefix is unique for the DATAPATH setting. If you\n" .
"are storing multiple Sphinx search data sets in the same DATAPATH,\n".
"then you would need to differentiate the DATA_PREFIXes to prevent\n" .
"file name collisions from happening.\n" .
"\n" .
"If you don't know what value to use, then just use the default"
),
array (
"SEARCHD_HOST",
"localhost",
"This is the hostname for connecting to the\n" .
"Sphinx searchd server (default is \"localhost\")."
),
array (
"SEARCHD_PORT",
"3312",
"This is is the port number for connecting to the\n" .
"Sphinx searchd server (default is \"3312\")."
)
);
while (TRUE)
{
print <<<INFO
Please select the configuration option that you want to change. The most
interesting features are marked with "***". When selecting an option, you will
get some more info about the purpose of that option. You can safely return
to this screen after doing so.
INFO;
foreach ($options as $id => $option) {
$flag = isset($option[3]) ? "***" : "";
print ($id+1) . ") $option[0] = $option[1] $flag\n";
}
print "q) Quit from this program.\n";
print "g) Generate configuration file.\n";
print "\n> ";
$opt = trim(fgets(STDIN));
if (((int)$opt > 0 && (int)$opt < count($options)))
{
$id = (int)$opt - 1;
$option = $options[$id];
print "\nOption: $option[0]\n";
print str_repeat("-", 70) . "\n";
print "$option[2]\n";
print str_repeat("-", 70) . "\n";
print "Enter new value or <ENTER> to accept the displayed current value.\n";
print "\n";
print $option[1] . "> ";
$val = trim(fgets(STDIN));
if ($val != '') {
$options[$id][1] = $val;
}
print "\n";
}
elseif ($opt == 'q') {
print "\nAborting ...\n\n";
exit();
}
elseif ($opt == 'g') {
print "\n";
$errors = 0;
foreach ($options as $option) {
if ($option[1] === NULL || $option[1] === '') {
print "Option \"$option[0]\" must be configured.\n";
$errors = 1;
}
}
if ($errors) {
print "\n";
sleep(1);
continue;
} else {
break;
}
}
else
{
print "\nIllegal option selected. Please try again ...\n\n";
sleep(1);
continue;
}
}
foreach ($options as $option) {
$PHORUM["DATA"][$option[0]] = $option[1];
}
$PHORUM["template"] = 'config_template';
ob_start();
include(phorum_get_template("sphinx_search::configuration"));
$config = ob_get_contents();
ob_end_clean();
$outfile = $PHORUM["cache"] . "/sphinx.conf-" . time();
require_once("./include/api/write_file.php");
phorum_api_write_file($outfile, $config);
print <<< CONFIGDONE
----------------------------------------------------------------------
A new configuration has been written to the location:
$outfile
----------------------------------------------------------------------
Look over the generated configuration file and see if you want to change
anything. After that, the first thing to do, would be to get Sphinx up and
running using this configuration file. For doing so, please refer to the
Sphinx documentation. The tasks that have to be taken care of are:
* Indexing your Phorum data, using the Sphinx "indexer" program.
* Running the Sphinx "searchd" program, which will let Phorum access the
indexed search data.
* Setting up scheduled jobs for letting Sphinx update its indexes on a
regular basis.
After setting up Sphinx, you will be ready to enable the Sphinx Search module.
You will have to configure that module from its settings page. If you wish,
this install script can update the module settings for you. Do you want
to run this update now?
CONFIGDONE;
while (TRUE)
{
print "\nPlease enter \"yes\" or \"no\" > ";
$yesno = trim(fgets(STDIN));
if ($yesno == 'yes' || $yesno == 'no') { break; }
}
$prefix = $PHORUM["DATA"]["DATA_PREFIX"];
$mi = "{$prefix}_msg" .
($PHORUM["DATA"]["USE_DELTA_UPDATES"]?" {$prefix}_msg_delta":"");
$ai = "{$prefix}_author" .
($PHORUM["DATA"]["USE_DELTA_UPDATES"]?" {$prefix}_author_delta":"");
$settings = array (
"sphinx_host" => $PHORUM["DATA"]["SEARCHD_HOST"],
"sphinx_port" => $PHORUM["DATA"]["SEARCHD_PORT"],
"message_index" => $mi,
"author_index" => $ai,
"max_search_results" => $PHORUM["DATA"]["MAX_SEARCH_RESULTS"],
);
if ($yesno == 'yes')
{
phorum_db_update_settings(array("mod_sphinx_search" => $settings));
print "\nThe settings for the Sphinx Search module have been updated.\n" .
"You should only have to enable the module to get it working\n" .
"with the Sphinx search engine.\n\n";
} else {
print "\n" .
"You will have to configure the settings for the module by\n" .
"hand. Below, you will see the options that you will need to\n" .
"use in the settings screen for this module, when running with\n" .
"the generated Sphinx configuration file:\n\n" .
"Sphinx IP address or hostname : {$settings["sphinx_host"]}\n" .
"Sphinx port : {$settings["sphinx_port"]}\n" .
"Message index(es) to use : $mi\n" .
"Author index(es) to use : $ai\n" .
"Maximum number of results : {$settings["max_search_results"]}\n".
"\n";
}
CONFIGDONE;
// No delta updates? Then we are done!
if (! $PHORUM["DATA"]["USE_DELTA_UPDATES"]) exit(0);
// Check if the incremental delta updates support table is available
// already. If not, then prompt for creating it now. Otherwise, we're done.
$incr_table = "{$PHORUM["DBCONFIG"]["table_prefix"]}_sphinx_counter";
$incr_recs = phorum_db_interact(
DB_RETURN_ROWS,
"DESC $incr_table",
NULL,
DB_MISSINGTABLEOK
);
if (!empty($incr_recs)) exit(0);
$sql = "CREATE TABLE $incr_table (\n" .
" counter_id int(11) unsigned NOT NULL default '0',\n" .
" `type` enum('author','message') NOT NULL default 'message',\n" .
" max_doc_id int(11) NOT NULL,\n" .
" PRIMARY KEY (counter_id,`type`)\n" .
")";
print <<< CONFIGDONE
----------------------------------------------------------------------
An extra table "$incr_table" is required
----------------------------------------------------------------------
For supporting incremental updates for searching, an extra database
table is required. The definition of this table is:
$sql
Do you want to automatically create this table now?
CONFIGDONE;
while (TRUE)
{
print "\nPlease enter \"yes\" or \"no\" > ";
$yesno = trim(fgets(STDIN));
if ($yesno == 'yes' || $yesno == 'no') { break; }
}
if ($yesno == 'yes') {
phorum_db_interact(DB_RETURN_RES, $sql);
print "\nTable \"$incr_table\" created.\n\n";
}
exit(0);
?>