marked more strings for translation
[e-DoKo.git] / update_db.php
1 <?php
2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
3  *
4  *   This file is part of e-DoKo.
5  *
6  *   e-DoKo is free software: you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, either version 3 of the License, or
9  *   (at your option) any later version.
10  *
11  *   e-DoKo is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 error_reporting(E_ALL);
22
23 include_once("config.php");                /* needs to be first in list, since other includes use this */
24 include_once("./include/db.php");          /* database only */
25 include_once("./include/output.php");   /* the rest */
26 include_once("./include/functions.php");   /* the rest */
27
28 /* make sure that user has set all variables in config.php */
29 config_check();
30
31 /* open the database */
32 $return = DB_open();
33 if($return<0 && $return != -2) /* -2 = wrong DB version is ok */
34   exit();
35
36 /* only callable via cron or CLI */
37 if(isset($_SERVER['REMOTE_ADDR']))
38   exit();
39
40 $old_version = DB_get_version();
41 $current_version = 4;
42
43 if($old_version < $current_version)
44   echo "Will upgrade your database now:\n";
45 else
46   echo "You are up to date (version ${current_version}), nothing to do.\n";
47
48 switch($old_version)
49   {
50   case 0:
51     /* add database for digesting */
52     DB_query("CREATE TABLE digest_email (".
53              " `id` int(11) NOT NULL auto_increment,".
54              " `email` varchar(255) default null,".
55              " `create_date` timestamp NOT NULL default '0000-00-00 00:00:00',".
56              " `content` text,".
57              " UNIQUE KEY `id` (`id`),".
58              " index (email))");
59     DB_query("UPDATE Version set version=1");
60     echo "Upgraded to version 1.\n";
61   case 1:
62     /* add new rules */
63     DB_query("ALTER TABLE Rulesets".
64              " ADD COLUMN `lowtrump` enum('poverty','cancel','none') default 'poverty' AFTER schweinchen");
65     DB_query("ALTER TABLE Hand".
66              " MODIFY COLUMN `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL");
67     DB_query("ALTER TABLE Game".
68              " MODIFY COLUMN `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL");
69
70     DB_query("UPDATE Version set version=2");
71     echo "Upgraded to version 2.\n";
72   case 2:
73     DB_query("ALTER TABLE Comment".
74              " ADD COLUMN `game_id` int(11) default NULL AFTER play_id");
75     DB_query("UPDATE Version set version=3");
76     echo "Upgraded to version 3.\n";
77   case 3:
78     DB_query("ALTER TABLE digest_email".
79              " ADD COLUMN `game_id` int(11) default NULL AFTER create_date");
80     DB_query("ALTER TABLE digest_email".
81              " ADD COLUMN `type` enum('misc','your_turn') NOT NULL default 'misc' AFTER create_date");
82     DB_query("UPDATE Version set version=4");
83     echo "Upgraded to version 4.\n";
84
85   }
86
87 ?>