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.
This commit is contained in:
NaGeL 2012-01-22 20:14:35 +01:00
parent 023384149f
commit ddd3f99835
3 changed files with 50 additions and 42 deletions

View File

@ -487,6 +487,11 @@ class UserPage extends SimpleExtension {
"You need to specify the account number to edit")); "You need to specify the account number to edit"));
} }
else{ 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 $database->execute("DELETE FROM users
WHERE id = :id" WHERE id = :id"
, array("id"=>$_POST['id'])); , array("id"=>$_POST['id']));

View File

@ -149,8 +149,10 @@ class UserPageTheme extends Themelet {
protected function build_options(User $duser) { protected function build_options(User $duser) {
global $config, $database, $user; global $config, $database, $user;
$html = "";
if($duser->id != 1){ //justa fool-admin protection so they dont mess around with anon users.
$html = " $html .= "
".make_form(make_link("user_admin/change_pass"))." ".make_form(make_link("user_admin/change_pass"))."
<input type='hidden' name='id' value='{$duser->id}'> <input type='hidden' name='id' value='{$duser->id}'>
<table style='width: 300px;'> <table style='width: 300px;'>
@ -191,6 +193,7 @@ class UserPageTheme extends Themelet {
<input type='submit' value='Delete User with images' onclick='confirm(\"Delete the user with his uploaded images?\");' /> <input type='submit' value='Delete User with images' onclick='confirm(\"Delete the user with his uploaded images?\");' />
</form>"; </form>";
} }
}
return $html; return $html;
} }
// }}} // }}}

View File

@ -285,7 +285,7 @@ function create_tables() { // {{{
INDEX(owner_id), INDEX(owner_id),
INDEX(width), INDEX(width),
INDEX(height), 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", " $db->create_table("tags", "
id SCORE_AIPK, id SCORE_AIPK,
@ -298,8 +298,8 @@ function create_tables() { // {{{
INDEX(image_id), INDEX(image_id),
INDEX(tag_id), INDEX(tag_id),
UNIQUE(image_id, tag_id), UNIQUE(image_id, tag_id),
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, CONSTRAINT foreign_images_tags_image_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_tag_id FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
"); ");
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)"); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)");
} }