summaryrefslogtreecommitdiffstats
path: root/update_db.php
blob: 498b24e663317d22c7044fca8d36b94637c7df99 (plain)
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
<?php
/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
 *
 *   This file is part of e-DoKo.
 *
 *   e-DoKo is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   e-DoKo is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

error_reporting(E_ALL);

include_once("config.php");                /* needs to be first in list, since other includes use this */
include_once("./include/db.php");          /* database only */
include_once("./include/functions.php");   /* the rest */

/* make sure that user has set all variables in config.php */
config_check();

/* open the database */
$return = DB_open();
if($return<0 && $return != -2) /* -2 = wrong DB version is ok */
  exit();

/* only callable via cron or CLI */
if(isset($_SERVER['REMOTE_ADDR']))
  exit();

$old_version = DB_get_version();
$current_version = 2;

if($old_version < $current_version)
  echo "Will upgrade your database now:\n";
else
  echo "You are up to date (version ${current_version}), nothing to do.\n";

switch($old_version)
  {
  case 0:
    /* add database for digesting */
    DB_query("CREATE TABLE digest_email (".
	     " `id` int(11) NOT NULL auto_increment,".
	     " `email` varchar(255) default null,".
	     " `create_date` timestamp NOT NULL default '0000-00-00 00:00:00',".
	     " `content` text,".
	     " UNIQUE KEY `id` (`id`),".
	     " index (email))");
    DB_query("UPDATE Version set version=1");
    echo "Upgraded to version 1.\n";
  case 1:
    /* add new rules */
    DB_query("ALTER TABLE Rulesets".
	     " ADD COLUMN `lowtrump` enum('poverty','cancel','none') default 'poverty' AFTER schweinchen");
    DB_query("ALTER TABLE Hand".
	     " MODIFY COLUMN `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL");
    DB_query("ALTER TABLE Game".
	     " MODIFY COLUMN `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL");

    DB_query("UPDATE Version set version=2");
    echo "Upgraded to version 2.\n";
  }

?>