summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-09-18 16:40:44 +0200
committerHorus32014-09-18 16:40:44 +0200
commit11d8a116c70cd5eb49edb8afce34a0aaac49f35e (patch)
treec94e0be77677e77e6f0c3131c0e8a4810471013f
parentf39735adc85901a3a2db83d16334ffff66960f65 (diff)
downloadvfs-11d8a116c70cd5eb49edb8afce34a0aaac49f35e.tar.gz
setup.php
-rw-r--r--public_html/class/mysql.php13
-rw-r--r--public_html/setup.php12
-rw-r--r--public_html/vfs_bootstrap.php3
3 files changed, 22 insertions, 6 deletions
diff --git a/public_html/class/mysql.php b/public_html/class/mysql.php
index 167c8a9..0031eec 100644
--- a/public_html/class/mysql.php
+++ b/public_html/class/mysql.php
@@ -5,7 +5,7 @@ class vfsdb {
public $db;
public function __construct(){
- return true;
+ $this->open();
}
public function open(){
@@ -24,7 +24,7 @@ class vfsdb {
}
if ( ! $this->db->set_charset(DBCHARSET) ){
- failure("<p>Can't set UTF-8 as a charset on your MySQL server." , '500 Server Failure', false, "<h1>Setting Charset failed!</h1>");
+ failure("<p>Can't set UTF-8 as a charset on your MySQL server.</p>" , '500 Server Failure', false, "<h1>Setting Charset failed!</h1>");
}
}
@@ -55,10 +55,11 @@ class vfsdb {
$sql = _prepare($string);
if ( ! $sql )
return false;
+
return $this->db->query($sql);
}
- public function setUp(){
+ public function createTables(){
$user_table =
'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'user
( id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(id),
@@ -71,7 +72,7 @@ class vfsdb {
status INTEGER,
color_folder VARCHAR(70),
color_file VARCHAR(70))
- ENGINE=InnoDB;'
+ ENGINE=InnoDB;';
$files_table =
'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'files
( files_id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(files_id),
@@ -88,7 +89,7 @@ class vfsdb {
last_access INTEGER,
FOREIGN KEY(files_id) REFERENCES user(id) ON DELETE CASCADE
)
- ENGINE=InnoDB;'
+ ENGINE=InnoDB;';
$banned_user_table =
'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'banned_user
( banned_id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(banned_id),
@@ -98,7 +99,7 @@ class vfsdb {
time INTEGER,
user INTEGER
)
- ENGINE=InnoDB;'
+ ENGINE=InnoDB;';
if ( ! $this->db->query($user_table . ' ' . $files_table . ' ' . $banned_user_table) )
failure("<p>Setting up the database failed.</p>", '500 Server Failure', false, "<h1>CREATE TABLE FAILED");
diff --git a/public_html/setup.php b/public_html/setup.php
new file mode 100644
index 0000000..74b0e10
--- /dev/null
+++ b/public_html/setup.php
@@ -0,0 +1,12 @@
+<?php
+# init file to set up the database
+# TODO: pretty html
+
+$vfsdb = new vfsdb();
+$vfsdb->createTables();
+$vfsdb->close();
+
+echo "<p>Successfully created the database.";
+
+# rename this file to avoid setting up the tables twice
+rename(ABSPATH . 'setup.php', ABSPATH . '_setup.php');
diff --git a/public_html/vfs_bootstrap.php b/public_html/vfs_bootstrap.php
index 341b0aa..4f0e05d 100644
--- a/public_html/vfs_bootstrap.php
+++ b/public_html/vfs_bootstrap.php
@@ -8,3 +8,6 @@ if ( ! defined(VFS_CLASS) )
require(ABSPATH . 'functions.php');
require(ABSPATH . VFS_CLASS . 'mysql.php');
+
+if ( file_exists(ABSPATH . 'setup.php') )
+ require(ABSPATh . 'setup.php');