From 46776bf853812a7dddba60de4e0f1b0ecd641d1b Mon Sep 17 00:00:00 2001 From: NaGeL Date: Tue, 17 Jan 2012 22:43:16 +0100 Subject: [PATCH 01/10] added author= search tag. --- contrib/artists/main.php | 92 +++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/contrib/artists/main.php b/contrib/artists/main.php index e4a5a803..cb11b40d 100644 --- a/contrib/artists/main.php +++ b/contrib/artists/main.php @@ -43,6 +43,14 @@ class Artists implements Extension { if ($event instanceof PageRequestEvent) $this->handle_commands($event); + + if($event instanceof SearchTermParseEvent) { + $matches = array(); + if(preg_match("/^author=(.*)$/", $event->term, $matches)) { + $char = $matches[1]; + $event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char))); + } + } } public function try_install() { @@ -130,7 +138,10 @@ class Artists implements Extension { } $database->execute("UPDATE images SET author = ? WHERE id = ?" - , array($artistName, $event->image->id)); + , array( + $artistName + , $event->image->id + )); } public function handle_commands($event) { @@ -457,7 +468,9 @@ class Artists implements Extension { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_alias WHERE artist_id = ? AND alias = ?", array( - $artistID, $alias)); + $artistID + , $alias + )); return ($result != 0); } @@ -617,7 +630,12 @@ class Artists implements Extension { global $database; $database->execute("UPDATE artists SET name = ?, notes = ?, updated = now(), user_id = ? WHERE id = ? " - , array( $name, $notes, $userID, $artistID )); + , array( + $name + , $notes + , $userID + , $artistID + )); // ALIAS MATCHING SECTION $i = 0; @@ -708,7 +726,11 @@ class Artists implements Extension { global $database; $database->execute("UPDATE artist_alias SET alias = ?, updated = now(), user_id = ? WHERE id = ? " - , array( $alias, $userID, $aliasID )); + , array( + $alias + , $userID + , $aliasID + )); } private function update_url() @@ -733,7 +755,11 @@ class Artists implements Extension { global $database; $database->execute("UPDATE artist_urls SET url = ?, updated = now(), user_id = ? WHERE id = ?" - , array( $url, $userID, $urlID )); + , array( + $url + , $userID + , $urlID + )); } private function update_member() @@ -759,7 +785,11 @@ class Artists implements Extension { global $database; $database->execute("UPDATE artist_members SET name = ?, updated = now(), user_id = ? WHERE id = ?" - , array( $memberName, $userID, $memberID )); + , array( + $memberName + , $userID + , $memberID + )); } /* @@ -831,7 +861,11 @@ class Artists implements Extension { (user_id, name, notes, created, updated) VALUES (?, ?, ?, now(), now())", - array( $user->id, $name, $notes )); + array( + $user->id + , $name + , $notes + )); $result = $database->get_row("SELECT LAST_INSERT_ID() AS artistID", array()); @@ -845,7 +879,9 @@ class Artists implements Extension { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artists WHERE name = ?" - , array($name)); + , array( + $name + )); return ($result != 0); } @@ -909,7 +945,9 @@ class Artists implements Extension { private function get_artist_id($name){ global $database; $artistID = $database->get_row("SELECT id FROM artists WHERE name = ?" - , array( $name )); + , array( + $name + )); return $artistID['id']; } @@ -918,7 +956,9 @@ class Artists implements Extension { global $database; $artistID = $database->get_row("SELECT artist_id FROM artist_alias WHERE alias = ?" - , array( $alias )); + , array( + $alias + )); return $artistID["artist_id"]; } @@ -932,7 +972,9 @@ class Artists implements Extension { global $database; $database->execute("DELETE FROM artists WHERE id = ? " - , array( $artistID )); + , array( + $artistID + )); } @@ -1056,7 +1098,11 @@ class Artists implements Extension { global $database; $database->execute("INSERT INTO artist_urls (artist_id, created, updated, url, user_id) VALUES (?, now(), now(), ?, ?)" - , array( $artistID, $url, $userID )); + , array( + $artistID + , $url + , $userID + )); } private function add_alias() @@ -1086,7 +1132,11 @@ class Artists implements Extension { global $database; $database->execute("INSERT INTO artist_alias (artist_id, created, updated, alias, user_id) VALUES (?, now(), now(), ?, ?)" - , array( $artistID, $alias, $userID )); + , array( + $artistID + , $alias + , $userID + )); } private function add_members() @@ -1115,7 +1165,11 @@ class Artists implements Extension { global $database; $database->execute("INSERT INTO artist_members (artist_id, name, created, updated, user_id) VALUES (?, ?, now(), now(), ?)" - , array( $artistID, $member, $userID )); + , array( + $artistID + , $member + , $userID + )); } private function member_exists($artistID, $member) @@ -1125,7 +1179,10 @@ class Artists implements Extension { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_members WHERE artist_id = ? AND name = ?" - , array( $artistID, $member )); + , array( + $artistID + , $member + )); return ($result != 0); } @@ -1136,7 +1193,10 @@ class Artists implements Extension { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_urls WHERE artist_id = ? AND url = ?" - , array( $artistID, $url )); + , array( + $artistID + , $url + )); return ($result != 0); } From 3c6217fa4cb16517c06cd51d086450aa3a3ecf9b Mon Sep 17 00:00:00 2001 From: NaGeL Date: Tue, 17 Jan 2012 22:45:24 +0100 Subject: [PATCH 02/10] added [align=(left|center|right)] BBcode which aligns text naturally. --- ext/bbcode/main.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index bddda8c5..328d9dba 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -63,6 +63,7 @@ class BBCode extends FormatterExtension { $text = preg_replace("/\[li\](.*?)\[\/li\]/s", "
  • \\1
  • ", $text); $text = preg_replace("#\[\*\]#s", "
  • ", $text); $text = preg_replace("#
    <(li|ul|ol|/ul|/ol)>#s", "<\\1>", $text); + $text = preg_replace("#\[align=(left|center|right)\](.*?)\[\/align\]#s", "
    \\2
    ", $text); $text = $this->filter_spoiler($text); $text = $this->insert_code($text); return $text; From 520fb08652d674d6d6d98194813567ea3f23a48d Mon Sep 17 00:00:00 2001 From: NaGeL Date: Thu, 19 Jan 2012 16:28:16 +0100 Subject: [PATCH 03/10] just gitignore update --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index b1d70c05..72316d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,12 @@ ext/upload_cmd ext/wiki ext/word_filter ext/zoom + +/ext/resize/main.php +/ext/resize/style.css +/ext/resize/theme.php +/ext/twitter_soc/main.php +/ext/twitter_soc/script.js +/ext/twitter_soc/style.css +/ext/twitter_soc/test.php +/ext/twitter_soc/theme.php \ No newline at end of file From 557a82e7bec36d741063f288eb548efe9073d915 Mon Sep 17 00:00:00 2001 From: NaGeL Date: Thu, 19 Jan 2012 16:43:20 +0100 Subject: [PATCH 04/10] Fixed linking bug in admin_user/list page. --- ext/user/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/user/theme.php b/ext/user/theme.php index 5f1491e1..b503d9f6 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -17,7 +17,7 @@ class UserPageTheme extends Themelet { $html .= "Name"; foreach($users as $duser) { $html .= ""; - $html .= "".html_escape($duser->name).""; + $html .= "".html_escape($duser->name).""; $html .= ""; } $html .= ""; From 8eaaa6a7ca49aafae7ed3f4b868f3fd8cfcc06a9 Mon Sep 17 00:00:00 2001 From: NaGeL Date: Thu, 19 Jan 2012 18:23:43 +0100 Subject: [PATCH 05/10] Added user deletion. User is deleted from database the Comments are deleted too, unknown reason for me Noting else is deleted so far. --- ext/user/main.php | 29 +++++++++++++++++++++++++++++ ext/user/theme.php | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/ext/user/main.php b/ext/user/main.php index fc0da212..0f1e8027 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -144,6 +144,9 @@ class UserPage extends SimpleExtension { // join (select owner_id,count(*) as comment_count from comments group by owner_id) as _comments on _comments.owner_id=users.id; $this->theme->display_user_list($page, User::by_list(0), $user); } + else if($event->get_arg(0) == "delete_user") { + $this->delete_user($page); + } } if(($event instanceof PageRequestEvent) && $event->page_matches("user")) { @@ -463,6 +466,32 @@ class UserPage extends SimpleExtension { ORDER BY most_recent DESC", array("id"=>$duser->id)); return $rows; } + + private function delete_user($page) { + global $user; + global $config; + global $database; + + $page->set_title("Error"); + $page->set_heading("Error"); + $page->add_block(new NavBlock()); + + if (!$user->is_admin()) { + $page->add_block(new Block("Not Admin", "Only admins can delete accounts")); + } + else if(!isset($_POST['id']) || !is_numeric($_POST['id'])) { + $page->add_block(new Block("No ID Specified", + "You need to specify the account number to edit")); + } + else{ + $database->execute("DELETE FROM users + WHERE id = :id" + , array("id"=>$_POST['id'])); + } + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + } + // }}} } add_event_listener(new UserPage()); diff --git a/ext/user/theme.php b/ext/user/theme.php index b503d9f6..424099f4 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -181,6 +181,11 @@ class UserPageTheme extends Themelet { "; + $html .=" +

    ".make_form(make_link("user_admin/delete_user"))." + + + "; } return $html; } From b219d79a22457deb650a5e547546cd8fd5cd399d Mon Sep 17 00:00:00 2001 From: NaGeL Date: Fri, 20 Jan 2012 22:08:19 +0100 Subject: [PATCH 06/10] A database update, for user deletion now user_favorites clean itself too. And a DBfix for those who installed shimmie before this date. --- DBupdate.php | 10 ++++++++++ contrib/favorites/main.php | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 DBupdate.php diff --git a/DBupdate.php b/DBupdate.php new file mode 100644 index 00000000..29a14b65 --- /dev/null +++ b/DBupdate.php @@ -0,0 +1,10 @@ +Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok
    ") : print_r("failed
    "); +echo "adding Foreign key to users..."; +($db->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); +?> \ No newline at end of file diff --git a/contrib/favorites/main.php b/contrib/favorites/main.php index f6c6ef5b..ad37edd0 100644 --- a/contrib/favorites/main.php +++ b/contrib/favorites/main.php @@ -144,8 +144,10 @@ class Favorites extends SimpleExtension { image_id INTEGER NOT NULL, user_id INTEGER NOT NULL, created_at DATETIME NOT NULL, + INDEX(image_id), UNIQUE(image_id, user_id), - INDEX(image_id) + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE ) "); $config->set_int("ext_favorites_version", 1); From 023384149ff1965eac297548e7a1024ebaec3f4f Mon Sep 17 00:00:00 2001 From: NaGeL Date: Sun, 22 Jan 2012 18:55:52 +0100 Subject: [PATCH 07/10] User deletion (Deletes the user with comments, favorites and private messages) User deletion with uploaded images ( all above plus the images the user uploaded) Also the Database fix that is all needed for this in DBupdate.php --- DBupdate.php | 13 ++++++++++++- ext/user/main.php | 42 ++++++++++++++++++++++++++++++++++++++++-- ext/user/theme.php | 10 +++++++--- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/DBupdate.php b/DBupdate.php index 29a14b65..183aa044 100644 --- a/DBupdate.php +++ b/DBupdate.php @@ -5,6 +5,17 @@ include_once "config.php"; $db = new Database(); echo "Fixing user_favorites table...."; ($db->Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok
    ") : print_r("failed
    "); -echo "adding Foreign key to users..."; +echo "adding Foreign key to user ids..."; ($db->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); +echo "cleaning, the table from deleted image favorites...
    "; +$rows = $db->get_all("SELECT * FROM user_favorites WHERE image_id NOT IN ( SELECT id FROM images );"); +foreach( $rows as $key => $value) + $db->Execute("DELETE FROM user_favorites WHERE image_id = :image_id;", array("image_id" => $value["image_id"])); +echo "adding forign key to image ids..."; +($db->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); +echo "adding foreign keys to private messages..."; +($db->Execute("ALTER TABLE private_message +ADD FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, +ADD FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;")) ? print_r("ok
    "):print_r("failed
    "); +echo "DONE!!!!"; ?> \ No newline at end of file diff --git a/ext/user/main.php b/ext/user/main.php index 0f1e8027..4e2620c0 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -147,6 +147,9 @@ class UserPage extends SimpleExtension { else if($event->get_arg(0) == "delete_user") { $this->delete_user($page); } + else if($event->get_arg(0) == "delete_user_with_images") { + $this->delete_user_with_images($page); + } } if(($event instanceof PageRequestEvent) && $event->page_matches("user")) { @@ -487,9 +490,44 @@ class UserPage extends SimpleExtension { $database->execute("DELETE FROM users WHERE id = :id" , array("id"=>$_POST['id'])); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + } + } + + private function delete_user_with_images($page) { + global $user; + global $config; + global $database; + + $page->set_title("Error"); + $page->set_heading("Error"); + $page->add_block(new NavBlock()); + + if (!$user->is_admin()) { + $page->add_block(new Block("Not Admin", "Only admins can delete accounts")); + } + else if(!isset($_POST['id']) || !is_numeric($_POST['id'])) { + $page->add_block(new Block("No ID Specified", + "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) + { + $image = Image::by_id($value['id']); + if($image) { + send_event(new ImageDeletionEvent($image)); + } + } + $database->execute("DELETE FROM users + WHERE id = :id" + , array("id"=>$_POST['id'])); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); } - $page->set_mode("redirect"); - $page->set_redirect(make_link("post/list")); } // }}} diff --git a/ext/user/theme.php b/ext/user/theme.php index 424099f4..304ff541 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -180,11 +180,15 @@ class UserPageTheme extends Themelet { Admin: - "; - $html .=" -

    ".make_form(make_link("user_admin/delete_user"))." + + ".make_form(make_link("user_admin/delete_user"))." + + + ".make_form(make_link("user_admin/delete_user_with_images"))." + + "; } return $html; From ddd3f99835df5fe160dc238f0fc2dc79136e8428 Mon Sep 17 00:00:00 2001 From: NaGeL Date: Sun, 22 Jan 2012 20:14:35 +0100 Subject: [PATCH 08/10] 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)"); } From 9009ab2c9590fdee7a9cd10035f19376a8e58d02 Mon Sep 17 00:00:00 2001 From: NaGeL Date: Sun, 22 Jan 2012 20:20:26 +0100 Subject: [PATCH 09/10] named the foreign keys. --- DBupdate.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DBupdate.php b/DBupdate.php index 183aa044..339d98b3 100644 --- a/DBupdate.php +++ b/DBupdate.php @@ -6,16 +6,16 @@ $db = new Database(); echo "Fixing user_favorites table...."; ($db->Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok
    ") : print_r("failed
    "); echo "adding Foreign key to user ids..."; -($db->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); +($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT foreign_user_favorites_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); echo "cleaning, the table from deleted image favorites...
    "; $rows = $db->get_all("SELECT * FROM user_favorites WHERE image_id NOT IN ( SELECT id FROM images );"); foreach( $rows as $key => $value) $db->Execute("DELETE FROM user_favorites WHERE image_id = :image_id;", array("image_id" => $value["image_id"])); echo "adding forign key to image ids..."; -($db->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); +($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT user_favorites_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); echo "adding foreign keys to private messages..."; ($db->Execute("ALTER TABLE private_message -ADD FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, -ADD FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;")) ? print_r("ok
    "):print_r("failed
    "); +ADD CONSTRAINT foreign_private_message_from_id FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, +ADD CONSTRAINT foreign_private_message_to_id FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;")) ? print_r("ok
    "):print_r("failed
    "); echo "DONE!!!!"; ?> \ No newline at end of file From 36a04fd62cb45f8b90461a9f10e4c8205962bffe Mon Sep 17 00:00:00 2001 From: NaGeL Date: Mon, 23 Jan 2012 15:24:23 +0100 Subject: [PATCH 10/10] put DBupdate.php into the install.php under Shimmie Repair Console. --- DBupdate.php | 21 -------------------- install.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 21 deletions(-) delete mode 100644 DBupdate.php diff --git a/DBupdate.php b/DBupdate.php deleted file mode 100644 index 339d98b3..00000000 --- a/DBupdate.php +++ /dev/null @@ -1,21 +0,0 @@ -Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok
    ") : print_r("failed
    "); -echo "adding Foreign key to user ids..."; -($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT foreign_user_favorites_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); -echo "cleaning, the table from deleted image favorites...
    "; -$rows = $db->get_all("SELECT * FROM user_favorites WHERE image_id NOT IN ( SELECT id FROM images );"); -foreach( $rows as $key => $value) - $db->Execute("DELETE FROM user_favorites WHERE image_id = :image_id;", array("image_id" => $value["image_id"])); -echo "adding forign key to image ids..."; -($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT user_favorites_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); -echo "adding foreign keys to private messages..."; -($db->Execute("ALTER TABLE private_message -ADD CONSTRAINT foreign_private_message_from_id FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, -ADD CONSTRAINT foreign_private_message_to_id FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;")) ? print_r("ok
    "):print_r("failed
    "); -echo "DONE!!!!"; -?> \ No newline at end of file diff --git a/install.php b/install.php index 5310a372..359642e4 100755 --- a/install.php +++ b/install.php @@ -76,6 +76,15 @@ if(is_readable("config.php")) { "; */ + echo "

    Database quick fix for User deletion

    "; + echo "just a database fix for those who instaled shimmie before 2012 january the 22rd.
    "; + echo "Note: some things needs to be done manually, to work properly.
    "; + echo "WARNING: ONLY PROCEEDS IF YOU KNOW WHAT YOU ARE DOING!"; + echo " +
    + +
    + "; echo "

    Log Out

    "; echo " @@ -87,6 +96,9 @@ if(is_readable("config.php")) { else if($_GET["action"] == "logout") { session_destroy(); } + else if($_GET["action"] == "Database_user_deletion_fix") { + Database_user_deletion_fix(); + } } else { echo "

    Login

    @@ -372,6 +384,49 @@ EOD; exit; } } // }}} + +function Database_user_deletion_fix() { + try { + require_once "core/database.class.php"; + $db = new Database(); + + echo "Fixing user_favorites table...."; + + ($db->Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok
    ") : print_r("failed
    "); + echo "adding Foreign key to user ids..."; + + ($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT foreign_user_favorites_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); + echo "cleaning, the table from deleted image favorites...
    "; + + $rows = $db->get_all("SELECT * FROM user_favorites WHERE image_id NOT IN ( SELECT id FROM images );"); + + foreach( $rows as $key => $value) + $db->Execute("DELETE FROM user_favorites WHERE image_id = :image_id;", array("image_id" => $value["image_id"])); + + echo "adding forign key to image ids..."; + + ($db->Execute("ALTER TABLE user_favorites ADD CONSTRAINT user_favorites_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"))? print_r("ok
    "):print_r("failed
    "); + + echo "adding foreign keys to private messages..."; + + ($db->Execute("ALTER TABLE private_message + ADD CONSTRAINT foreign_private_message_from_id FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, + ADD CONSTRAINT foreign_private_message_to_id FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;")) ? print_r("ok
    "):print_r("failed
    "); + + echo "Just one more step...which you need to do manually:
    "; + echo "You need to go to your database and Delete the foreign key on the owner_id in the images table.

    "; + echo "How to remove foreign keys

    "; + echo "and finally execute this querry:

    "; + echo "ALTER TABLE images ADD CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT;

    "; + echo "if this is all sucesfull you are done!"; + + } + catch (PDOException $e) + { + // FIXME: Make the error message user friendly + exit($e->getMessage()); + } +} ?>