<?php
-require_once(DOCROOT . 'inc/wfpl/persistent.php');
+# 1. Write the next db_upgrade_to_X() at the bottom of this file. It will be
+# called automatically.
-# instructions:
-#
-# 1. Write the next db_upgrade_to_XX() at the bottom of this file
-#
-# 2. curl -H "X-UPGRADE-DB-NOW: y" http://this-site.com/
-
-function db_upgrade() {
- header("Content-Type: text/plain");
- ini_set('display_errors', '1');
- ini_set('html_errors', '0');
-
- # initialize where we store the current db schema version
- 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;');
-
- # now we can just do the needed upgrades
- $cur = persistent_get('db_schema_version');
- if ($cur === null) {
- $cur = 0;
- }
-
- echo "db schema at version $cur\n\n";
-
- $upgraded = false;
- for ($next = $cur + 1; function_exists("db_upgrade_$next"); $next += 1) {
- echo "upgrading DB to version $next...\n";
- flush();
- call_user_func("db_upgrade_$next");
- persistent_set('db_schema_version', $next);
- echo "done\n\n";
- flush();
- $upgraded = true;
- }
-
- if ($upgraded) {
- echo "Upgrades complete\n";
- } else {
- echo "No upgrades needed\n";
- }
-
- exit();
+function db_upgrade_to_1() {
+db_send_query(<<<EOLsql
+ create table wfpl_sessions (
+ id int unique auto_increment,
+ session_key varchar(16),
+ idle_timeout int,
+ expires int,
+ expires_max int,
+ value text
+ ) CHARSET=utf8;
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table email_templates (
+ id int unique auto_increment,
+ slug varchar(200) binary not null default "",
+ notes text binary not null default "",
+ from_addr varchar(100) binary not null default "",
+ to_addr varchar(100) binary not null default "",
+ cc_addr varchar(100) binary not null default "",
+ bcc_addr varchar(100) binary not null default "",
+ subject varchar(200) binary not null default "",
+ content text binary not null default ""
+ ) CHARSET=utf8;
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table files (
+ id int unique auto_increment,
+ filename varchar(100) not null default "",
+ description varchar(200) not null default ""
+ );
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table cms_images (
+ id int unique auto_increment,
+ image varchar(240) not null default "",
+ name varchar(200) not null default "",
+ caption varchar(200) not null default "",
+ created_at int not null default 0
+ );
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table cms_pages (
+ id int unique auto_increment,
+ filename varchar(200) not null default "",
+ title varchar(200) not null default "",
+ nav_title varchar(200) not null default "",
+ navbar int not null default 0,
+ layout int not null default 0,
+ content mediumtext not null default "",
+ sidebar_content mediumtext not null default "",
+ description text not null default "",
+ keywords text not null default ""
+ );
+EOLsql
+);
+db_send_query(<<<EOLsql
+ insert into cms_pages set
+ filename='index',
+ title='Home',
+ content='Under Construction',
+ navbar=1000000000;
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table users (
+ id int unique auto_increment,
+ name varchar(200) binary not null default "",
+ username varchar(200) binary not null default "",
+ password varchar(255) binary not null default "",
+ role varchar(200) binary not null default "",
+ last_active int(11) not null default 0,
+ last_login int(11) not null default 0
+ ) CHARSET=utf8;
+EOLsql
+);
+db_send_query(<<<EOLsql
+ insert into users set
+ name="fixme",
+ username="fixme",
+ password="$2y$10$84xUpPFQFRYRwpGkt01YtObJZcRKGReM/5ywHXCbwDF2bja41CDZm",
+ role="admin";
+EOLsql
+);
+db_send_query(<<<EOLsql
+ create table paypal_ipn (
+ id int unique auto_increment,
+ txn_id varchar(250) not null default "",
+ status varchar(250) not null default "",
+ ipn_at int(11) not null default 0,
+ txn_type varchar(100) not null default "",
+ subscr_id varchar(100) not null default "",
+ custom varchar(250) not null default "",
+ for_table_id int not null default 0,
+ for_row_id int not null default 0,
+ processed int(1) not null default 0,
+ item_name varchar(250) not null default "",
+ item_number varchar(250) not null default "",
+ needs_review int(1) not null default 0,
+ payment_status varchar(250) not null default "",
+ mc_gross varchar(250) not null default "",
+ mc_currency varchar(250) not null default "",
+ receiver_email varchar(250) not null default "",
+ payer_email varchar(250) not null default "",
+ log text not null default ""
+ ) CHARSET=utf8;
+EOLsql
+);
}
-#function db_upgrade_1() {
-# db_send_query("alter table foo add bar int(11) not null default 0");
-#}
+function db_upgrade_to_2() {
+db_send_query(<<<EOLsql
+ create table history_cms_pages (
+ history_id int unique auto_increment,
+ history_when int not null default 0,
+ history_user_id int not null default 0,
+ id int,
+ filename varchar(200) not null default "",
+ title varchar(200) not null default "",
+ nav_title varchar(200) not null default "",
+ navbar int not null default 0,
+ layout int not null default 0,
+ content mediumtext not null default "",
+ sidebar_content mediumtext not null default "",
+ description text not null default "",
+ keywords text not null default ""
+ );
+EOLsql
+);
+db_send_query(<<<EOLsql
+ insert into history_cms_pages (
+ history_when,
+ history_user_id,
+ id,
+ filename,
+ title,
+ nav_title,
+ navbar,
+ layout,
+ content,
+ sidebar_content,
+ description,
+ keywords
+ ) select
+ 0,
+ 0,
+ id,
+ filename,
+ title,
+ nav_title,
+ navbar,
+ layout,
+ content,
+ sidebar_content,
+ description,
+ keywords
+ from cms_pages;
+EOLsql
+);
+}