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()); + } +} ?>