parent
409b91e861
commit
9ea891f03f
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
// Post Structure
|
||||
define('POSTS_FILE', '.posts');
|
||||
define('POST_ID', 0);
|
||||
define('POST_PARENT', 1);
|
||||
define('POST_TIMESTAMP', 2);
|
||||
define('POST_BUMPED', 3);
|
||||
define('POST_IP', 4);
|
||||
define('POST_NAME', 5);
|
||||
define('POST_TRIPCODE', 6);
|
||||
define('POST_EMAIL', 7);
|
||||
define('POST_NAMEBLOCK', 8);
|
||||
define('POST_SUBJECT', 9);
|
||||
define('POST_MESSAGE', 10);
|
||||
define('POST_PASSWORD', 11);
|
||||
define('POST_FILE', 12);
|
||||
define('POST_FILE_HEX', 13);
|
||||
define('POST_FILE_ORIGINAL', 14);
|
||||
define('POST_FILE_SIZE', 15);
|
||||
define('POST_FILE_SIZE_FORMATTED', 16);
|
||||
define('POST_IMAGE_WIDTH', 17);
|
||||
define('POST_IMAGE_HEIGHT', 18);
|
||||
define('POST_THUMB', 19);
|
||||
define('POST_THUMB_WIDTH', 20);
|
||||
define('POST_THUMB_HEIGHT', 21);
|
||||
define('POST_STICKIED', 22);
|
||||
define('POST_LOCKED', 23);
|
||||
define('POST_MODERATED', 24);
|
||||
|
||||
// Ban Structure
|
||||
define('BANS_FILE', '.bans');
|
||||
define('BAN_ID', 0);
|
||||
define('BAN_IP', 1);
|
||||
define('BAN_TIMESTAMP', 2);
|
||||
define('BAN_EXPIRE', 3);
|
||||
define('BAN_REASON', 4);
|
||||
|
||||
require_once 'flatfile/flatfile.php';
|
||||
$db = new Flatfile();
|
||||
$db->datadir = 'inc/database/flatfile/';
|
||||
// Search past default database path
|
||||
if (file_exists('inc/flatfile/' . POSTS_FILE)) {
|
||||
$db->datadir = 'inc/flatfile/';
|
||||
}
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($newpost) {
|
||||
$post = array();
|
||||
$post[POST_ID] = $newpost['id'];
|
||||
$post[POST_PARENT] = $newpost['parent'];
|
||||
$post[POST_TIMESTAMP] = $newpost['timestamp'];
|
||||
$post[POST_BUMPED] = $newpost['bumped'];
|
||||
$post[POST_IP] = $newpost['ip'];
|
||||
$post[POST_NAME] = $newpost['name'];
|
||||
$post[POST_TRIPCODE] = $newpost['tripcode'];
|
||||
$post[POST_EMAIL] = $newpost['email'];
|
||||
$post[POST_NAMEBLOCK] = $newpost['nameblock'];
|
||||
$post[POST_SUBJECT] = $newpost['subject'];
|
||||
$post[POST_MESSAGE] = $newpost['message'];
|
||||
$post[POST_PASSWORD] = $newpost['password'];
|
||||
$post[POST_FILE] = $newpost['file'];
|
||||
$post[POST_FILE_HEX] = $newpost['file_hex'];
|
||||
$post[POST_FILE_ORIGINAL] = $newpost['file_original'];
|
||||
$post[POST_FILE_SIZE] = $newpost['file_size'];
|
||||
$post[POST_FILE_SIZE_FORMATTED] = $newpost['file_size_formatted'];
|
||||
$post[POST_IMAGE_WIDTH] = $newpost['image_width'];
|
||||
$post[POST_IMAGE_HEIGHT] = $newpost['image_height'];
|
||||
$post[POST_THUMB] = $newpost['thumb'];
|
||||
$post[POST_THUMB_WIDTH] = $newpost['thumb_width'];
|
||||
$post[POST_THUMB_HEIGHT] = $newpost['thumb_height'];
|
||||
$post[POST_MODERATED] = $newpost['moderated'];
|
||||
$post[POST_STICKIED] = $newpost['stickied'];
|
||||
$post[POST_LOCKED] = $newpost['locked'];
|
||||
$GLOBALS['db']->insertWithAutoId(POSTS_FILE, POST_ID, $post);
|
||||
}
|
||||
|
||||
function migrateBan($newban) {
|
||||
$ban = array();
|
||||
$ban[BAN_ID] = $newban['id'];
|
||||
$ban[BAN_IP] = $newban['ip'];
|
||||
$ban[BAN_TIMESTAMP] = $newban['timestamp'];
|
||||
$ban[BAN_EXPIRE] = $newban['expire'];
|
||||
$ban[BAN_REASON] = $newban['reason'];
|
||||
$GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
if (!function_exists('mysql_connect')) {
|
||||
fancyDie("MySQL library is not installed");
|
||||
}
|
||||
|
||||
$link = mysql_connect(TINYIB_DBHOST, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD);
|
||||
if (!$link) {
|
||||
fancyDie("Could not connect to database: " . mysql_error());
|
||||
}
|
||||
$db_selected = mysql_select_db(TINYIB_DBNAME, $link);
|
||||
if (!$db_selected) {
|
||||
fancyDie("Could not select database: " . mysql_error());
|
||||
}
|
||||
mysql_query("SET NAMES 'utf8'");
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . TINYIB_DBPOSTS . "'")) == 0) {
|
||||
mysql_query($posts_sql);
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . TINYIB_DBBANS . "'")) == 0) {
|
||||
mysql_query($bans_sql);
|
||||
}
|
||||
|
||||
if (mysql_num_rows(mysql_query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'")) == 0) {
|
||||
mysql_query("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
if (mysql_num_rows(mysql_query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'locked'")) == 0) {
|
||||
mysql_query("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($post) {
|
||||
mysql_query("INSERT INTO " . TINYIB_DBPOSTS . " (id, parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated, stickied, locked) VALUES (" . $post['id'] . ", " . $post['parent'] . ", " . $post['timestamp'] . ", " . $post['bumped'] . ", '" . mysql_real_escape_string($post['ip']) . "', '" . mysql_real_escape_string($post['name']) . "', '" . mysql_real_escape_string($post['tripcode']) . "', '" . mysql_real_escape_string($post['email']) . "', '" . mysql_real_escape_string($post['nameblock']) . "', '" . mysql_real_escape_string($post['subject']) . "', '" . mysql_real_escape_string($post['message']) . "', '" . mysql_real_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysql_real_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ", " . $post['stickied'] . ", " . $post['locked'] . ")");
|
||||
}
|
||||
|
||||
function migrateBan($ban) {
|
||||
mysql_query("INSERT INTO " . TINYIB_DBBANS . " (id, ip, timestamp, expire, reason) VALUES (" . $ban['id'] . "', '" . mysql_real_escape_string($ban['ip']) . "', '" . $ban['timestamp'] . "', '" . $ban['expire'] . "', '" . mysql_real_escape_string($ban['reason']) . "')");
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
if (!function_exists('mysqli_connect')) {
|
||||
fancyDie("MySQL library is not installed");
|
||||
}
|
||||
|
||||
$link = @mysqli_connect(TINYIB_DBHOST, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD);
|
||||
if (!$link) {
|
||||
fancyDie("Could not connect to database: " . ((is_object($link)) ? mysqli_error($link) : (($link_error = mysqli_connect_error()) ? $link_error : '(unknown error)')));
|
||||
}
|
||||
$db_selected = @mysqli_query($link, "USE " . TINYIB_DBNAME);
|
||||
if (!$db_selected) {
|
||||
fancyDie("Could not select database: " . ((is_object($link)) ? mysqli_error($link) : (($link_error = mysqli_connect_error()) ? $link_error : '(unknown error')));
|
||||
}
|
||||
mysqli_query($link, "SET NAMES 'utf8'");
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBPOSTS . "'")) == 0) {
|
||||
mysqli_query($link, $posts_sql);
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBBANS . "'")) == 0) {
|
||||
mysqli_query($link, $bans_sql);
|
||||
}
|
||||
|
||||
if (mysqli_num_rows(mysqli_query($link, "SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'")) == 0) {
|
||||
mysqli_query($link, "ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
if (mysqli_num_rows(mysqli_query($link, "SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'locked'")) == 0) {
|
||||
mysqli_query($link, "ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($post) {
|
||||
global $link;
|
||||
mysqli_query($link, "INSERT INTO `" . TINYIB_DBPOSTS . "` (`id`, `parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`, `moderated`, `stickied`, `locked`) VALUES (" . $post['id'] . ", " . $post['parent'] . ", " . $post['timestamp'] . ", " . $post['bumped'] . ", '" . mysqli_real_escape_string($link, $post['ip']) . "', '" . mysqli_real_escape_string($link, $post['name']) . "', '" . mysqli_real_escape_string($link, $post['tripcode']) . "', '" . mysqli_real_escape_string($link, $post['email']) . "', '" . mysqli_real_escape_string($link, $post['nameblock']) . "', '" . mysqli_real_escape_string($link, $post['subject']) . "', '" . mysqli_real_escape_string($link, $post['message']) . "', '" . mysqli_real_escape_string($link, $post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysqli_real_escape_string($link, $post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ", " . $post['stickied'] . ", " . $post['locked'] . ")");
|
||||
}
|
||||
|
||||
function migrateBan($ban) {
|
||||
global $link;
|
||||
sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBBANS . " (id, ip, timestamp, expire, reason) VALUES (" . $ban['id'] . "', '" . mysqli_real_escape_string($link, $ban['ip']) . "', '" . $ban['timestamp'] . "', '" . $ban['expire'] . "', '" . mysqli_real_escape_string($link, $ban['reason']) . "')");
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
if (TINYIB_DBDSN == '') { // Build a default (likely MySQL) DSN
|
||||
$dsn = TINYIB_DBDRIVER . ":host=" . TINYIB_DBHOST;
|
||||
if (TINYIB_DBPORT > 0) {
|
||||
$dsn .= ";port=" . TINYIB_DBPORT;
|
||||
}
|
||||
$dsn .= ";dbname=" . TINYIB_DBNAME;
|
||||
} else { // Use a custom DSN
|
||||
$dsn = TINYIB_DBDSN;
|
||||
}
|
||||
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$options = array(PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
|
||||
} else {
|
||||
$options = array(PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
|
||||
}
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD, $options);
|
||||
} catch (PDOException $e) {
|
||||
fancyDie("Failed to connect to the database: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename LIKE " . $dbh->quote(TINYIB_DBPOSTS);
|
||||
$posts_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||
} else {
|
||||
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBPOSTS));
|
||||
$posts_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||
}
|
||||
|
||||
if (!$posts_exists) {
|
||||
$dbh->exec($posts_sql);
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename LIKE " . $dbh->quote(TINYIB_DBBANS);
|
||||
$bans_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||
} else {
|
||||
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBBANS));
|
||||
$bans_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||
}
|
||||
|
||||
if (!$bans_exists) {
|
||||
$dbh->exec($bans_sql);
|
||||
}
|
||||
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='moderated'";
|
||||
$moderated_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||
} else {
|
||||
$dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'");
|
||||
$moderated_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||
}
|
||||
|
||||
if (!$moderated_exists) {
|
||||
$dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN moderated TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='stickied'";
|
||||
$stickied_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||
} else {
|
||||
$dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'");
|
||||
$stickied_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||
}
|
||||
|
||||
if (!$stickied_exists) {
|
||||
$dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||
$query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='locked'";
|
||||
$locked_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||
} else {
|
||||
$dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'locked'");
|
||||
$locked_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||
}
|
||||
|
||||
if (!$locked_exists) {
|
||||
$dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
}
|
||||
|
||||
function pdoQuery($sql, $params = false) {
|
||||
global $dbh;
|
||||
|
||||
if ($params) {
|
||||
$statement = $dbh->prepare($sql);
|
||||
$statement->execute($params);
|
||||
} else {
|
||||
$statement = $dbh->query($sql);
|
||||
}
|
||||
|
||||
return $statement;
|
||||
}
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($post) {
|
||||
global $dbh;
|
||||
$stm = $dbh->prepare("INSERT INTO " . TINYIB_DBPOSTS . " (id, parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated, stickied, locked) " .
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stm->execute(array($post['id'], $post['parent'], $post['timestamp'], $post['bumped'], $post['ip'], $post['name'], $post['tripcode'], $post['email'],
|
||||
$post['nameblock'], $post['subject'], $post['message'], $post['password'],
|
||||
$post['file'], $post['file_hex'], $post['file_original'], $post['file_size'], $post['file_size_formatted'],
|
||||
$post['image_width'], $post['image_height'], $post['thumb'], $post['thumb_width'], $post['thumb_height'], $post['moderated'], $post['stickied'], $post['locked']));
|
||||
}
|
||||
|
||||
function migrateBan($ban) {
|
||||
global $dbh;
|
||||
$stm = $dbh->prepare("INSERT INTO " . TINYIB_DBBANS . " (id, ip, timestamp, expire, reason) VALUES (?, ?, ?, ?, ?)");
|
||||
$stm->execute(array($ban['id'], $ban['ip'], $ban['timestamp'], $ban['expire'], $ban['reason']));
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
if (!extension_loaded('sqlite3')) {
|
||||
fancyDie("SQLite3 extension is either not installed or loaded");
|
||||
}
|
||||
|
||||
$db = new SQLite3(TINYIB_DBPATH);
|
||||
if (!$db) {
|
||||
fancyDie("Could not connect to database: " . $db->lastErrorMsg());
|
||||
}
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBPOSTS . "'");
|
||||
if (!$result->fetchArray()) {
|
||||
$db->exec("CREATE TABLE " . TINYIB_DBPOSTS . " (
|
||||
id INTEGER PRIMARY KEY,
|
||||
parent INTEGER NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL,
|
||||
bumped TIMESTAMP NOT NULL,
|
||||
ip TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
tripcode TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
nameblock TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
file TEXT NOT NULL,
|
||||
file_hex TEXT NOT NULL,
|
||||
file_original TEXT NOT NULL,
|
||||
file_size INTEGER NOT NULL DEFAULT '0',
|
||||
file_size_formatted TEXT NOT NULL,
|
||||
image_width INTEGER NOT NULL DEFAULT '0',
|
||||
image_height INTEGER NOT NULL DEFAULT '0',
|
||||
thumb TEXT NOT NULL,
|
||||
thumb_width INTEGER NOT NULL DEFAULT '0',
|
||||
thumb_height INTEGER NOT NULL DEFAULT '0',
|
||||
moderated INTEGER NOT NULL DEFAULT '0',
|
||||
stickied INTEGER NOT NULL DEFAULT '0',
|
||||
locked INTEGER NOT NULL DEFAULT '0'
|
||||
)");
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBBANS . "'");
|
||||
if (!$result->fetchArray()) {
|
||||
$db->exec("CREATE TABLE " . TINYIB_DBBANS . " (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ip TEXT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL,
|
||||
expire TIMESTAMP NOT NULL,
|
||||
reason TEXT NOT NULL
|
||||
)");
|
||||
}
|
||||
|
||||
// Add moderated column if it isn't present
|
||||
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
// Add stickied column if it isn't present
|
||||
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN stickied INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
// Add locked column if it isn't present
|
||||
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($post) {
|
||||
sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBPOSTS . " (id, parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated, stickied, locked) VALUES (" . $post['id'] . ", " . $post['parent'] . ", " . $post['timestamp'] . ", " . $post['bumped'] . ", '" . sqlite_escape_string($post['ip']) . "', '" . sqlite_escape_string($post['name']) . "', '" . sqlite_escape_string($post['tripcode']) . "', '" . sqlite_escape_string($post['email']) . "', '" . sqlite_escape_string($post['nameblock']) . "', '" . sqlite_escape_string($post['subject']) . "', '" . sqlite_escape_string($post['message']) . "', '" . sqlite_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . sqlite_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ", " . $post['stickied'] . ", " . $post['locked'] . ")");
|
||||
}
|
||||
|
||||
function migrateBan($ban) {
|
||||
sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBBANS . " (id, ip, timestamp, expire, reason) VALUES (" . $ban['id'] . "', '" . sqlite_escape_string($ban['ip']) . "', '" . $ban['timestamp'] . "', '" . $ban['expire'] . "', '" . sqlite_escape_string($ban['reason']) . "')");
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
if (!defined('TINYIB_BOARD')) {
|
||||
die('');
|
||||
}
|
||||
|
||||
if (!function_exists('sqlite_open')) {
|
||||
fancyDie("SQLite library is not installed. Try the sqlite3 database mode.");
|
||||
}
|
||||
|
||||
if (!$db = sqlite_open(TINYIB_DBPATH, 0666, $error)) {
|
||||
fancyDie("Could not connect to database: " . $error);
|
||||
}
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
$result = sqlite_query($db, "SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBPOSTS . "'");
|
||||
if (sqlite_num_rows($result) == 0) {
|
||||
sqlite_query($db, "CREATE TABLE " . TINYIB_DBPOSTS . " (
|
||||
id INTEGER PRIMARY KEY,
|
||||
parent INTEGER NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL,
|
||||
bumped TIMESTAMP NOT NULL,
|
||||
ip TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
tripcode TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
nameblock TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
file TEXT NOT NULL,
|
||||
file_hex TEXT NOT NULL,
|
||||
file_original TEXT NOT NULL,
|
||||
file_size INTEGER NOT NULL DEFAULT '0',
|
||||
file_size_formatted TEXT NOT NULL,
|
||||
image_width INTEGER NOT NULL DEFAULT '0',
|
||||
image_height INTEGER NOT NULL DEFAULT '0',
|
||||
thumb TEXT NOT NULL,
|
||||
thumb_width INTEGER NOT NULL DEFAULT '0',
|
||||
thumb_height INTEGER NOT NULL DEFAULT '0',
|
||||
moderated INTEGER NOT NULL DEFAULT '0',
|
||||
stickied INTEGER NOT NULL DEFAULT '0',
|
||||
locked INTEGER NOT NULL DEFAULT '0'
|
||||
)");
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
$result = sqlite_query($db, "SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBBANS . "'");
|
||||
if (sqlite_num_rows($result) == 0) {
|
||||
sqlite_query($db, "CREATE TABLE " . TINYIB_DBBANS . " (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ip TEXT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL,
|
||||
expire TIMESTAMP NOT NULL,
|
||||
reason TEXT NOT NULL
|
||||
)");
|
||||
}
|
||||
|
||||
// Add moderated column if it isn't present
|
||||
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
// Add stickied column if it isn't present
|
||||
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN stickied INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
// Add locked column if it isn't present
|
||||
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN locked INTEGER NOT NULL DEFAULT '0'");
|
||||
|
||||
if (function_exists('insertPost')) {
|
||||
function migratePost($post) {
|
||||
sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBPOSTS . " (id, parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated, stickied, locked) VALUES (" . $post['id'] . ", " . $post['parent'] . ", " . $post['timestamp'] . ", " . $post['bumped'] . ", '" . sqlite_escape_string($post['ip']) . "', '" . sqlite_escape_string($post['name']) . "', '" . sqlite_escape_string($post['tripcode']) . "', '" . sqlite_escape_string($post['email']) . "', '" . sqlite_escape_string($post['nameblock']) . "', '" . sqlite_escape_string($post['subject']) . "', '" . sqlite_escape_string($post['message']) . "', '" . sqlite_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . sqlite_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ", " . $post['stickied'] . ", " . $post['locked'] . ")");
|
||||
}
|
||||
|
||||
function migrateBan($ban) {
|
||||
sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBBANS . " (id, ip, timestamp, expire, reason) VALUES (" . $ban['id'] . "', '" . sqlite_escape_string($ban['ip']) . "', '" . $ban['timestamp'] . "', '" . $ban['expire'] . "', '" . sqlite_escape_string($ban['reason']) . "')");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue