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
33 include dirname(__FILE__) . '/../../env.inc.php';
34 require_once $gfcommon.'include/pre.php';
35 include $gfcommon.'include/cron_utils.php';
37 $src_path = forge_get_config('src_path', 'mediawiki');
38 $master_path = forge_get_config('master_path', 'mediawiki');
40 # Get all projects that use the mediawiki plugin
41 $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"));
43 $err = "Error: Database Query Failed: ".db_error();
49 # Loop over all projects that use the plugin
50 while ( $row = db_fetch_array($project_res) ) {
51 $project = $row['unix_group_name'];
52 $project_dir = forge_get_config('projects_path', 'mediawiki')
54 cron_debug("Checking $project...");
56 // Create the project directory if necessary
57 if (is_dir($project_dir)) {
58 cron_debug(" Project dir $project_dir exists, so I assumen the project already exists.");
60 cron_debug(" Creating project dir $project_dir.");
61 mkdir($project_dir, 0775, true);
64 $schema = "plugin_mediawiki_$project";
65 // Sanitize schema name
66 strtr($schema, "-", "_");
70 cron_debug(" Creating schema $schema.");
71 $res = db_query_params("CREATE SCHEMA $schema", array());
73 $err = "Error: Schema Creation Failed: " .
81 cron_debug(" Creating mediawiki database.");
82 $table_file = "$src_path/maintenance/postgres/tables.sql";
83 if (!file_exists($table_file)) {
84 $err = "Error: Couldn't find Mediawiki Database Creation File $table_file!";
91 $res = db_query_params("SET search_path=$schema", array());
93 $err = "Error: DB Query Failed: " .
101 $creation_query = file_get_contents($table_file);
102 $res = db_query_from_file($table_file);
104 $err = "Error: Mediawiki Database Creation Failed: " .
112 $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION $schema.default ( COPY = pg_catalog.english )", array());
114 $err = "Error: DB Query Failed: " .
123 $err = "Error: DB Commit Failed: " .
130 $mwwrapper = forge_get_config('source_path')."/plugins/mediawiki/bin/mw-wrapper.php" ;
131 $dumpfile = forge_get_config('config_path')."/mediawiki/initial-content.xml" ;
133 if (file_exists ($dumpfile)) {
134 system ("$mwwrapper $project importDump.php $dumpfile") ;
135 system ("$mwwrapper $project rebuildrecentchanges.php") ;
143 // c-file-style: "bsd"