4 * Perform the update operations like renaming SQL tables
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
8 * Copyright © 2007 Roland Hieber
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 require_once("/usr/share/iserv/www/inc/quote.inc");
30 require_once("/usr/share/iserv/www/inc/db.inc");
32 function doSql($cmd, $quiet = false) {
35 $cmd = "psql -c ".qs($cmd);
36 $cmd = ($quiet) ?
$cmd . ">/dev/null 2>&1" : $cmd;
40 function printSql($cmd) { echo $cmd."\n"; return doSql($cmd); }
41 function tableExists($table) {
42 return doSql("SELECT * FROM $table", tnue
);
44 function columnExists($table, $col) {
45 return (doSql("SELECT $col FROM $table", true) and tableExists($table));
48 if(isset($_SERVER["REMOTE_ADDR"])) {
49 die("Run this script as root from the command line.");
52 /*** Generic update tasks *****************************************************/
55 $sOldCfg = "/old/opt/iserv/idesk/inc/error-reporter/config.inc.rpmsave";
56 $sNewCfg = "/usr/share/iserv/www/inc/mod_error-reporter/config.inc";
57 if(is_file($sOldCfg)) {
58 echo "taking over old config file... ";
59 exec("/usr/share/iserv/modules/error-reporter/update-config.sh", $a, $i);
66 /*** database schema updates***************************************************/
67 echo "updating database schema... \n";
68 if(!tableExists("mod_errorreporter")) {
72 /** table from pre-3.0 **/
73 if(tableExists("errors") and !columnExists("errors", "pclabel")) {
74 printSql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;");
77 /** table from 3.0 **/
78 if(tableExists("errors") and !columnExists("errors", "pclabel")) {
79 printSql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
80 "er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,".
81 "comment,commentby,hidden FROM errors;");
82 printSql("DROP TABLE errors;");
85 /** table from 4.0 **/
86 if(tableExists("errorreports")) {
87 printSql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
88 "er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,".
89 "er_text,er_comment,er_commentact,er_hidden FROM errorreports;");
90 printSql("DROP TABLE errorreports;");
This page took 0.049746 seconds and 5 git commands to generate.