Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo
[e-DoKo.git] / update_db.php
1 <?php
2 /* Copyright 2006, 2007, 2008, 2009, 2010 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/functions.php");   /* the rest */
26
27 /* make sure that user has set all variables in config.php */
28 config_check();
29
30 /* open the database */
31 if(DB_open()<0)
32   exit();
33
34 /* only callable via cron or CLI */
35 if(isset($_SERVER['REMOTE_ADDR']))
36   exit();
37
38 $old_version = DB_get_version();
39 $current_version = 1;
40
41 if($old_version < $current_version)
42   echo "Will upgrade your database now:\n";
43 else
44   echo "You are up to date (version ${current_version}), nothing to do.\n";
45
46 switch($old_version)
47   {
48   case 0:
49     /* add database for digesting */
50     DB_query("CREATE TABLE digest_email (".
51              " `id` int(11) NOT NULL auto_increment,".
52              " `email` varchar(255) default null,".
53              " `create_date` timestamp NOT NULL default '0000-00-00 00:00:00',".
54              " `content` text,".
55              " UNIQUE KEY `id` (`id`),".
56              " index (email))");
57     DB_query("UPDATE Version set version=1");
58     echo "Upgraded to version 1.\n";
59   }
60
61 ?>