4 * Copyright (C) 2010 Olaf Lenz
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /** This script will automatically create mediawiki instances for
24 projects that do not yet have it.
26 It is intended to be started in a cronjob.
29 # TODO: How to use cronjob history?
30 # Required config variables:
31 # src_path: the directory where the mediawiki sources are installed
32 # var_path: the directory where mediawiki can store its data (i.e. LocalSettings.php and images/)
34 include dirname(__FILE__) . '/../../env.inc.php';
35 require_once $gfwww.'include/pre.php';
36 include $gfcommon.'include/cron_utils.php';
37 include $gfplugins . 'mediawiki/common/config-vars.php';
39 $src_path = forge_get_config('src_path', 'mediawiki');
40 $master_path = forge_get_config('master_path', 'mediawiki');
42 # Get all projects that use the mediawiki plugin
43 $project_res = db_query_params ("SELECT g.unix_group_name from groups g, group_plugin gp, plugins p where g.group_id = gp.group_id and gp.plugin_id = p.plugin_id and p.plugin_name = $1;", array("mediawiki"));
45 $err = "Error: Database Query Failed: ".db_error();
51 # Loop over all projects that use the plugin
52 while ( $row = db_fetch_array($project_res) ) {
53 $project = $row['unix_group_name'];
54 $project_dir = forge_get_config('projects_path', 'mediawiki')
56 cron_debug("Checking $project...");
58 // Create the project directory if necessary
59 if (is_dir($project_dir)) {
60 cron_debug(" Project dir $project_dir exists, so I assumen the project already exists.");
62 cron_debug(" Creating project dir $project_dir.");
63 mkdir($project_dir, 0775, true);
66 $schema = "plugin_mediawiki_$project";
67 // Sanitize schema name
68 strtr($schema, "-", "_");
72 cron_debug(" Creating schema $schema.");
73 $res = db_query_params("CREATE SCHEMA $schema", array());
75 $err = "Error: Schema Creation Failed: " .
83 cron_debug(" Creating mediawiki database.");
84 $table_file = "$src_path/maintenance/postgres/tables.sql";
85 if (!file_exists($table_file)) {
86 $err = "Error: Couldn't find Mediawiki Database Creation File $table_file!";
93 $res = db_query_params("SET search_path=$schema", array());
95 $err = "Error: DB Query Failed: " .
103 $creation_query = file_get_contents($table_file);
104 $res = db_query_from_file($table_file);
106 $err = "Error: Mediawiki Database Creation Failed: " .
114 $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION $schema.default ( COPY = pg_catalog.english )", array());
116 $err = "Error: DB Query Failed: " .
125 $err = "Error: DB Commit Failed: " .
132 $mwwrapper = $sys_share_path."/plugins/mediawiki/bin/mw-wrapper.php" ;
133 $dumpfile = $sys_etc_path."/mediawiki/initial-content.xml" ;
135 if (file_exists ($dumpfile)) {
136 system ("$mwwrapper $project importDump.php $dumpfile") ;
137 system ("$mwwrapper $project rebuildrecentchanges.php") ;
145 // c-file-style: "bsd"