JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
remove debugging print
[wfpl-cms.git] / inc / db_upgrade.php
1 <?php
2
3 require_once(DOCROOT . 'inc/wfpl/persistent.php');
4
5 # instructions:
6 #
7 # 1.    Write the next db_upgrade_to_XX() at the bottom of this file
8 #
9 # 2.    curl -H "X-UPGRADE-DB-NOW: y" http://this-site.com/
10
11 function db_upgrade() {
12         header("Content-Type: text/plain");
13         ini_set('display_errors', '1');
14         ini_set('html_errors', '0');
15
16         # initialize where we store the current db schema version
17         db_send_query('create table if not exists persistent ( k varchar(30) binary not null default "", v varchar(255) binary not null default "", primary key (k)) CHARSET=utf8;');
18
19         # now we can just do the needed upgrades
20         $cur = persistent_get('db_schema_version');
21         if ($cur === null) {
22                 $cur = 0;
23         }
24
25         echo "db schema at version $cur\n\n";
26
27         $upgraded = false;
28         for ($next = $cur + 1; function_exists("db_upgrade_$next"); $next += 1) {
29                 echo "upgrading DB to version $next...\n";
30                 flush();
31                 call_user_func("db_upgrade_$next");
32                 persistent_set('db_schema_version', $next);
33                 echo "done\n\n";
34                 flush();
35                 $upgraded = true;
36         }
37
38         if ($upgraded) {
39                 echo "Upgrades complete\n";
40         } else {
41                 echo "No upgrades needed\n";
42         }
43
44         exit();
45 }
46
47 #function db_upgrade_1() {
48 #       db_send_query("alter table foo add bar int(11) not null default 0");
49 #}