From ddd3f99835df5fe160dc238f0fc2dc79136e8428 Mon Sep 17 00:00:00 2001 From: NaGeL Date: Sun, 22 Jan 2012 20:14:35 +0100 Subject: [PATCH] deleting the user withouth images delete resulted in image deletion too: the DB entriy gets removed but the image stays on the Hard drive. this is fixed. also the Foreign key needs to be manually updated in images table. named the foreign keys in install.php for easier altering in the future. --- ext/user/main.php | 5 +++ ext/user/theme.php | 81 ++++++++++++++++++++++++---------------------- install.php | 6 ++-- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/ext/user/main.php b/ext/user/main.php index 4e2620c0..d964d6b9 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -487,6 +487,11 @@ class UserPage extends SimpleExtension { "You need to specify the account number to edit")); } else{ + $rows = $database->get_all("SELECT * FROM images WHERE owner_id = :owner_id", array("owner_id" => $_POST['id'])); + foreach ($rows as $key => $value) + { + $database->Execute("UPDATE images SET owner_id = :owner_id WHERE id = :id;", array("owner_id" => 1, "id" => $value['id'])); + } $database->execute("DELETE FROM users WHERE id = :id" , array("id"=>$_POST['id'])); diff --git a/ext/user/theme.php b/ext/user/theme.php index 304ff541..e258d186 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -149,47 +149,50 @@ class UserPageTheme extends Themelet { protected function build_options(User $duser) { global $config, $database, $user; - - $html = " - ".make_form(make_link("user_admin/change_pass"))." - - - - - - -
Change Password
Password
Repeat Password
- - -

".make_form(make_link("user_admin/change_email"))." - - - - - -
Change Email
Address
- - "; - - if($user->is_admin()) { - $i_user_id = int_escape($duser->id); - $h_is_admin = $duser->is_admin() ? " checked" : ""; + $html = ""; + if($duser->id != 1){ //justa fool-admin protection so they dont mess around with anon users. + $html .= " -

".make_form(make_link("user_admin/set_more"))." + ".make_form(make_link("user_admin/change_pass"))." + + + + + + +
Change Password
Password
Repeat Password
+ + +

".make_form(make_link("user_admin/change_email"))." + + + + + +
Change Email
Address
+ + "; + + if($user->is_admin()) { + $i_user_id = int_escape($duser->id); + $h_is_admin = $duser->is_admin() ? " checked" : ""; + $html .= " +

".make_form(make_link("user_admin/set_more"))." + + Admin: + + + + ".make_form(make_link("user_admin/delete_user"))." - Admin: - - - - ".make_form(make_link("user_admin/delete_user"))." - - - - - ".make_form(make_link("user_admin/delete_user_with_images"))." - - - "; + + + + ".make_form(make_link("user_admin/delete_user_with_images"))." + + + "; + } } return $html; } diff --git a/install.php b/install.php index e5f2e5cc..5310a372 100755 --- a/install.php +++ b/install.php @@ -285,7 +285,7 @@ function create_tables() { // {{{ INDEX(owner_id), INDEX(width), INDEX(height), - FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE + CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); $db->create_table("tags", " id SCORE_AIPK, @@ -298,8 +298,8 @@ function create_tables() { // {{{ INDEX(image_id), INDEX(tag_id), UNIQUE(image_id, tag_id), - FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, - FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE + CONSTRAINT foreign_images_tags_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, + CONSTRAINT foreign_images_tags_tag_id FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE "); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)"); }