did I mention that mysql devs can go choke on a bucket of cocks? Well they can. (Two ways to specify foreign keys, one works, one is silently ignored; wtf?)
This commit is contained in:
parent
46c3989ce5
commit
bda38bff6c
@ -38,10 +38,11 @@ class Bookmarks implements Extension {
|
|||||||
if($config->get_int("ext_bookmarks_version") < 1) {
|
if($config->get_int("ext_bookmarks_version") < 1) {
|
||||||
$database->create_table("bookmark", "
|
$database->create_table("bookmark", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL,
|
||||||
url TEXT NOT NULL,
|
url TEXT NOT NULL,
|
||||||
title TET NOT NULL,
|
title TET NOT NULL,
|
||||||
INDEX (owner_id)
|
INDEX (owner_id),
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_bookmarks_version", 1);
|
$config->set_int("ext_bookmarks_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -106,11 +106,12 @@ class EventLog implements Extension {
|
|||||||
if($config->get_int("ext_event_log_version", 0) < 1) {
|
if($config->get_int("ext_event_log_version", 0) < 1) {
|
||||||
$database->create_table("event_log", "
|
$database->create_table("event_log", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL,
|
||||||
owner_ip SCORE_INET NOT NULL,
|
owner_ip SCORE_INET NOT NULL,
|
||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
event VARCHAR(32) NOT NULL,
|
event VARCHAR(32) NOT NULL,
|
||||||
entry TEXT NOT NULL
|
entry TEXT NOT NULL,
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_event_log_version", 1);
|
$config->set_int("ext_event_log_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ class ImageBan implements Extension {
|
|||||||
$database->create_table("image_bans", "
|
$database->create_table("image_bans", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
hash CHAR(32) NOT NULL,
|
hash CHAR(32) NOT NULL,
|
||||||
date DATETIME DEFAULT now(),
|
date DATETIME DEFAULT SCORE_NOW,
|
||||||
reason TEXT NOT NULL,
|
reason TEXT NOT NULL
|
||||||
");
|
");
|
||||||
$config->set_int("ext_imageban_version", 1);
|
$config->set_int("ext_imageban_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -93,11 +93,13 @@ class NumericScore implements Extension {
|
|||||||
$database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
|
$database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
|
||||||
$database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
|
$database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
|
||||||
$database->create_table("numeric_score_votes", "
|
$database->create_table("numeric_score_votes", "
|
||||||
image_id INTEGER NOT NULL REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id INTEGER NOT NULL,
|
||||||
score INTEGER NOT NULL,
|
score INTEGER NOT NULL,
|
||||||
UNIQUE(image_id, user_id),
|
UNIQUE(image_id, user_id),
|
||||||
INDEX(image_id)
|
INDEX(image_id),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_numeric_score_version", 1);
|
$config->set_int("ext_numeric_score_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,11 @@ class ReportImage implements Extension {
|
|||||||
if($config->get_int("ext_report_image_version") < 1) {
|
if($config->get_int("ext_report_image_version") < 1) {
|
||||||
$database->create_table("image_reports", "
|
$database->create_table("image_reports", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
image_id INTEGER NOT NULL REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
reporter_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
reporter_id INTEGER NOT NULL,
|
||||||
reason TEXT NOT NULL
|
reason TEXT NOT NULL,
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (reporter_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_report_image_version", 1);
|
$config->set_int("ext_report_image_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -69,10 +69,16 @@ class Tag_History implements Extension {
|
|||||||
if($config->get_int("ext_tag_history_version") < 1) {
|
if($config->get_int("ext_tag_history_version") < 1) {
|
||||||
$database->create_table("tag_histories", "
|
$database->create_table("tag_histories", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
image_id INTEGER NOT NULL REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
tags TEXT NOT NULL
|
user_id INTEGER NOT NULL,
|
||||||
|
user_ip SCORE_INET NOT NULL,
|
||||||
|
tags TEXT NOT NULL,
|
||||||
|
date_set DATETIME NOT NULL,
|
||||||
|
INDEX(image_id),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES images(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_tag_history_version", 1);
|
$config->set_int("ext_tag_history_version", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($config->get_int("ext_tag_history_version") == 1) {
|
if($config->get_int("ext_tag_history_version") == 1) {
|
||||||
|
@ -82,11 +82,13 @@ class TextScore implements Extension {
|
|||||||
$database->Execute("ALTER TABLE images ADD COLUMN text_score INTEGER NOT NULL DEFAULT 0");
|
$database->Execute("ALTER TABLE images ADD COLUMN text_score INTEGER NOT NULL DEFAULT 0");
|
||||||
$database->Execute("CREATE INDEX images__text_score ON images(text_score)");
|
$database->Execute("CREATE INDEX images__text_score ON images(text_score)");
|
||||||
$database->create_table("text_score_votes", "
|
$database->create_table("text_score_votes", "
|
||||||
image_id INTEGER NOT NULL REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id INTEGER NOT NULL,
|
||||||
score INTEGER NOT NULL,
|
score INTEGER NOT NULL,
|
||||||
UNIQUE(image_id, user_id),
|
UNIQUE(image_id, user_id),
|
||||||
INDEX(image_id)
|
INDEX(image_id),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_text_score_version", 1);
|
$config->set_int("ext_text_score_version", 1);
|
||||||
}
|
}
|
||||||
|
@ -149,14 +149,15 @@ class Wiki implements Extension {
|
|||||||
if($config->get_int("ext_wiki_version", 0) < 1) {
|
if($config->get_int("ext_wiki_version", 0) < 1) {
|
||||||
$database->create_table("wiki_pages", "
|
$database->create_table("wiki_pages", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL,
|
||||||
owner_ip SCORE_INET NOT NULL,
|
owner_ip SCORE_INET NOT NULL,
|
||||||
date DATETIME DEFAULT NULL,
|
date DATETIME DEFAULT NULL,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
revision INTEGER NOT NULL DEFAULT 1,
|
revision INTEGER NOT NULL DEFAULT 1,
|
||||||
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
||||||
body TEXT NOT NULL,
|
body TEXT NOT NULL,
|
||||||
UNIQUE (title, revision)
|
UNIQUE (title, revision),
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_wiki_version", 2);
|
$config->set_int("ext_wiki_version", 2);
|
||||||
}
|
}
|
||||||
|
@ -162,14 +162,16 @@ class CommentList implements Extension {
|
|||||||
if($config->get_int("ext_comments_version") < 1) {
|
if($config->get_int("ext_comments_version") < 1) {
|
||||||
$database->create_table("comments", "
|
$database->create_table("comments", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
image_id INTEGER NOT NULL REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL,
|
||||||
owner_ip SCORE_INET NOT NULL,
|
owner_ip SCORE_INET NOT NULL,
|
||||||
posted DATETIME DEFAULT NULL,
|
posted DATETIME DEFAULT NULL,
|
||||||
comment TEXT NOT NULL,
|
comment TEXT NOT NULL,
|
||||||
INDEX (image_id),
|
INDEX (image_id),
|
||||||
INDEX (owner_ip),
|
INDEX (owner_ip),
|
||||||
INDEX (posted)
|
INDEX (posted),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
");
|
");
|
||||||
$config->set_int("ext_comments_version", 2);
|
$config->set_int("ext_comments_version", 2);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,9 @@ class PostListBuildingEvent extends Event {
|
|||||||
var $page = null;
|
var $page = null;
|
||||||
var $search_terms = null;
|
var $search_terms = null;
|
||||||
|
|
||||||
public function PostListBuildingEvent($page, $search) {
|
public function __construct(RequestContext $context, $search) {
|
||||||
$this->page = $page;
|
parent::__construct($context);
|
||||||
|
$this->page = $context->page;
|
||||||
$this->search_terms = $search;
|
$this->search_terms = $search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ class Index implements Extension {
|
|||||||
$count = $config->get_int('index_width') * $config->get_int('index_height');
|
$count = $config->get_int('index_width') * $config->get_int('index_height');
|
||||||
$images = Image::find_images($config, $database, ($page_number-1)*$count, $count, $search_terms);
|
$images = Image::find_images($config, $database, ($page_number-1)*$count, $count, $search_terms);
|
||||||
|
|
||||||
send_event(new PostListBuildingEvent($event->page, $search_terms));
|
send_event(new PostListBuildingEvent($event->context, $search_terms));
|
||||||
|
|
||||||
if(!(count($search_terms) == 0 && count($images) == 0)) {
|
if(!(count($search_terms) == 0 && count($images) == 0)) {
|
||||||
$this->theme->set_page($page_number, $total_pages, $search_terms);
|
$this->theme->set_page($page_number, $total_pages, $search_terms);
|
||||||
|
@ -4,8 +4,9 @@ class UserBlockBuildingEvent extends Event {
|
|||||||
var $parts = array();
|
var $parts = array();
|
||||||
var $user = null;
|
var $user = null;
|
||||||
|
|
||||||
public function UserBlockBuildingEvent($user) {
|
public function __construct(RequestContext $context) {
|
||||||
$this->user = $user;
|
parent::__construct($context);
|
||||||
|
$this->user = $context->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_link($name, $link, $position=50) {
|
public function add_link($name, $link, $position=50) {
|
||||||
@ -121,7 +122,7 @@ class UserPage implements Extension {
|
|||||||
global $config;
|
global $config;
|
||||||
$this->theme->display_user_page($event->context->page, $event->display_user, $user);
|
$this->theme->display_user_page($event->context->page, $event->display_user, $user);
|
||||||
if($user->id == $event->display_user->id) {
|
if($user->id == $event->display_user->id) {
|
||||||
$ubbe = new UserBlockBuildingEvent($event->display_user);
|
$ubbe = new UserBlockBuildingEvent($event->context);
|
||||||
send_event($ubbe);
|
send_event($ubbe);
|
||||||
ksort($ubbe->parts);
|
ksort($ubbe->parts);
|
||||||
$this->theme->display_user_links($event->context->page, $event->context->user, $ubbe->parts);
|
$this->theme->display_user_links($event->context->page, $event->context->user, $ubbe->parts);
|
||||||
@ -141,7 +142,7 @@ class UserPage implements Extension {
|
|||||||
$this->theme->display_login_block($page);
|
$this->theme->display_login_block($page);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$ubbe = new UserBlockBuildingEvent($user);
|
$ubbe = new UserBlockBuildingEvent($event->context);
|
||||||
send_event($ubbe);
|
send_event($ubbe);
|
||||||
ksort($ubbe->parts);
|
ksort($ubbe->parts);
|
||||||
$this->theme->display_user_block($page, $user, $ubbe->parts);
|
$this->theme->display_user_block($page, $user, $ubbe->parts);
|
||||||
|
33
install.php
33
install.php
@ -160,9 +160,18 @@ function create_tables($dsn) { // {{{
|
|||||||
name VARCHAR(128) NOT NULL PRIMARY KEY,
|
name VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||||
value TEXT
|
value TEXT
|
||||||
"));
|
"));
|
||||||
|
$db->execute($engine->create_table_sql("users", "
|
||||||
|
id SCORE_AIPK,
|
||||||
|
name VARCHAR(32) NOT NULL,
|
||||||
|
pass CHAR(32),
|
||||||
|
joindate DATETIME NOT NULL DEFAULT SCORE_NOW,
|
||||||
|
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
||||||
|
email VARCHAR(128),
|
||||||
|
INDEX(name)
|
||||||
|
"));
|
||||||
$db->execute($engine->create_table_sql("images", "
|
$db->execute($engine->create_table_sql("images", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL,
|
||||||
owner_ip SCORE_INET NOT NULL,
|
owner_ip SCORE_INET NOT NULL,
|
||||||
filename VARCHAR(64) NOT NULL,
|
filename VARCHAR(64) NOT NULL,
|
||||||
filesize INTEGER NOT NULL,
|
filesize INTEGER NOT NULL,
|
||||||
@ -175,29 +184,23 @@ function create_tables($dsn) { // {{{
|
|||||||
INDEX(owner_id),
|
INDEX(owner_id),
|
||||||
INDEX(hash),
|
INDEX(hash),
|
||||||
INDEX(width),
|
INDEX(width),
|
||||||
INDEX(height)
|
INDEX(height),
|
||||||
"));
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
$db->execute($engine->create_table_sql("users", "
|
|
||||||
id SCORE_AIPK,
|
|
||||||
name VARCHAR(32) NOT NULL,
|
|
||||||
pass CHAR(32),
|
|
||||||
joindate DATETIME NOT NULL DEFAULT SCORE_NOW,
|
|
||||||
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
|
||||||
email VARCHAR(128),
|
|
||||||
INDEX(name)
|
|
||||||
"));
|
"));
|
||||||
$db->execute($engine->create_table_sql("tags", "
|
$db->execute($engine->create_table_sql("tags", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
tag VARCHAR(64) NOT NULL,
|
tag VARCHAR(64) NOT NULL,
|
||||||
count INTEGER NOT NULL DEFAULT 0,
|
count INTEGER NOT NULL DEFAULT 0,
|
||||||
INDEX(tag)
|
UNIQUE(tag)
|
||||||
"));
|
"));
|
||||||
$db->execute($engine->create_table_sql("image_tags", "
|
$db->execute($engine->create_table_sql("image_tags", "
|
||||||
image_id INTEGER REFERENCES images(id) ON DELETE CASCADE,
|
image_id INTEGER NOT NULL,
|
||||||
tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
|
tag_id INTEGER NOT NULL,
|
||||||
INDEX(image_id),
|
INDEX(image_id),
|
||||||
INDEX(tag_id),
|
INDEX(tag_id),
|
||||||
INDEX(image_id, tag_id)
|
INDEX(image_id, tag_id),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
|
||||||
"));
|
"));
|
||||||
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 7)");
|
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 7)");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user