From 9e67e531aa7f1b62662999c44eb9f8b7fd6959ef Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Sat, 4 Feb 2012 23:16:50 -0500 Subject: [PATCH 1/3] How is this typo still in here? --- core/extension.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/extension.class.php b/core/extension.class.php index e5ce13d2..b54956de 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -191,7 +191,7 @@ abstract class DataHandlerExtension extends SimpleExtension { } } - public function onThumnbnailGeneration(ThumbnailGenerationEvent $event) { + public function onThumbnailGeneration(ThumbnailGenerationEvent $event) { if($this->supported_ext($event->type)) { if (method_exists($this, 'create_thumb_force') && $event->force == true) { $this->create_thumb_force($event->hash); From 8db3546c8d87fff7ab396a32fe2c910c98bc89e2 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Sun, 5 Feb 2012 12:11:56 -0500 Subject: [PATCH 2/3] Changes to the install script for Issue 101. --- install.php | 78 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/install.php b/install.php index 09da4d33..61a1bf69 100755 --- a/install.php +++ b/install.php @@ -1,7 +1,8 @@ - + + Shimmie Installation - @@ -31,9 +33,10 @@ TD INPUT {width: 350px;}

Install Error

Shimmie needs to be run via a web server with PHP support -- you appear to be either opening the file from your hard disk, or your - web server is mis-configured. + web server is mis-configured.

If you've installed a web server on your desktop PC, you probably - want to visit the local web server. + want to visit the local web server.

+

@@ -52,6 +55,7 @@ if(is_readable("config.php")) { <h1>Shimmie Repair Console</h1> <?php include "config.php"; + if($_SESSION['dsn'] == DATABASE_DSN || $_POST['dsn'] == DATABASE_DSN) { if($_POST['dsn']) {$_SESSION['dsn'] = $_POST['dsn'];} @@ -76,10 +80,12 @@ if(is_readable("config.php")) { </form> "; */ - echo "<h3>Database quick fix for User deletion</h3>"; - echo "just a database fix for those who instaled shimmie before 2012 january the 22rd.<br>"; - echo "Note: some things needs to be done manually, to work properly.<br>"; - echo "WARNING: ONLY PROCEEDS IF YOU KNOW WHAT YOU ARE DOING!"; + echo "<h3>Database Fix for User deletion</h3>"; + echo "This is a database fix for those who instaled shimmie before 2012 January 22rd.<br/>"; + echo "<b>This is only for users with <u>MySQL</u> databases!</b><br/>"; + echo "Note: Some things needs to be done manually, to work properly.<br/>"; + echo "Please BACKUP YOUR DATABASE before performing this fix!<br>"; + echo "WARNING: ONLY PROCEEDS IF YOU KNOW WHAT YOU ARE DOING!<br>"; echo " <form action='install.php?action=Database_user_deletion_fix' method='POST'> <input type='submit' value='go!'> @@ -102,8 +108,7 @@ if(is_readable("config.php")) { } else { echo " <h3>Login</h3> - Enter the database DSN exactly as in config.php (ie, as originally - installed) to access advanced recovery tools: + <p>Enter the database DSN exactly as in config.php (ie, as originally installed) to access advanced recovery tools:</p> <form action='install.php' method='POST'> <center> @@ -249,7 +254,7 @@ function begin() { // {{{ <h3>Help</h3> <p>Please make sure the database you have chosen exists and is empty.<br> - The username provided must have access to create tables within the database. + The username provided must have access to create tables within the database.</p> </div> EOD; @@ -354,11 +359,12 @@ function build_dirs() { // {{{ !file_exists("images") || !file_exists("thumbs") || !file_exists("data") || !is_writable("images") || !is_writable("thumbs") || !is_writable("data") ) { - print "Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data', - and they need to be writable by the PHP user (if you see this error, - if probably means the folders are owned by you, and they need to be - writable by the web server). - <p>Once you have created these folders, hit 'refresh' to continue."; + print "<p>Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data', + and they need to be writable by the PHP user.</p> + <p>If you see this error, if probably means the folders are owned by you, and they need to be + writable by the web server.</p> + <p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p> + <p>Once you have created these folders and/or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>"; exit; } } // }}} @@ -393,10 +399,18 @@ function Database_user_deletion_fix() { require_once "core/database.class.php"; $db = new Database(); - echo "Fixing user_favorites table...."; + if ($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') { + echo "<br><br>Database is not MySQL - Aborting changes.<br><br>"; + echo '<a href="install.php">Go Back</a>'; + return; + } else { + echo "<h3>Performing Database Fix Operations</h3><br>"; + } + + echo "Fixing user_favorites table....<br><br>"; ($db->Execute("ALTER TABLE user_favorites ENGINE=InnoDB;")) ? print_r("ok<br>") : print_r("failed<br>"); - echo "adding Foreign key to user ids..."; + echo "adding Foreign key to user ids...<br><br>"; ($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<br>"):print_r("failed<br>"); echo "cleaning, the table from deleted image favorites...<br>"; @@ -406,17 +420,17 @@ function Database_user_deletion_fix() { 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..."; + echo "adding forign key to image ids...<br><br>"; ($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<br>"):print_r("failed<br>"); - echo "adding foreign keys to private messages..."; + echo "adding foreign keys to private messages...<br><br>"; ($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<br>"):print_r("failed<br>"); - echo "Just one more step...which you need to do manually:<br>"; + echo "<br><br>Just one more step...which you need to do manually:<br>"; echo "You need to go to your database and Delete the foreign key on the owner_id in the images table.<br><br>"; echo "<a href='http://www.justin-cook.com/wp/2006/05/09/how-to-remove-foreign-keys-in-mysql/'>How to remove foreign keys</a><br><br>"; echo "and finally execute this querry:<br><br>"; From a78ca78c9b0210f1eac1ebe798d6b3a55c9ac191 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" <jgen.tech@gmail.com> Date: Sun, 5 Feb 2012 16:35:34 -0500 Subject: [PATCH 3/3] More changes to the install script. More error checking, better formating, etc.. --- core/database.class.php | 2 +- install.php | 65 +++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 27805521..53abd16e 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -310,7 +310,7 @@ class Database { } $matches = array(); - if(CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) { + if( defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) { if($matches[1] == "memcache") { $this->cache = new MemcacheCache($matches[2]); } diff --git a/install.php b/install.php index 61a1bf69..a14c4c7a 100755 --- a/install.php +++ b/install.php @@ -54,10 +54,32 @@ if(is_readable("config.php")) { <div id="iblock"> <h1>Shimmie Repair Console</h1> <?php - include "config.php"; + + /* + * Compute the path to the folder containing "install.php" and + * store it as the 'Shimmie Root' folder for later on. + * + * Example: + * __SHIMMIE_ROOT__ = '/var/www/shimmie2/' + * + */ + define('__SHIMMIE_ROOT__', trim( remove_trailing_slash( dirname(__FILE__) ) ) . '/' ); + + // Pull in necessary files + require_once __SHIMMIE_ROOT__."config.php"; // Load user/site specifics First + require_once __SHIMMIE_ROOT__."core/default_config.inc.php"; // Defaults for the rest. + require_once __SHIMMIE_ROOT__."core/util.inc.php"; + require_once __SHIMMIE_ROOT__."core/database.class.php"; - if($_SESSION['dsn'] == DATABASE_DSN || $_POST['dsn'] == DATABASE_DSN) { - if($_POST['dsn']) {$_SESSION['dsn'] = $_POST['dsn'];} + if ( + ( array_key_exists('dsn', $_SESSION) && $_SESSION['dsn'] === DATABASE_DSN ) || + ( array_key_exists('dsn', $_POST) && $_POST['dsn'] === DATABASE_DSN ) + ) + { + if ( array_key_exists('dsn', $_POST) && !empty($_POST['dsn']) ) + { + $_SESSION['dsn'] = $_POST['dsn']; + } if(empty($_GET["action"])) { echo "<h3>Basic Checks</h3>"; @@ -81,14 +103,14 @@ if(is_readable("config.php")) { "; */ echo "<h3>Database Fix for User deletion</h3>"; - echo "This is a database fix for those who instaled shimmie before 2012 January 22rd.<br/>"; - echo "<b>This is only for users with <u>MySQL</u> databases!</b><br/>"; - echo "Note: Some things needs to be done manually, to work properly.<br/>"; + echo "<p>This is a database fix for those who instaled shimmie before 2012 January 22rd.</p>"; + echo "<p><b>This is only for users with <u>MySQL</u> databases!</b></p>"; + echo "<p>Note: Some things needs to be done manually, to work properly.<br/>"; echo "Please BACKUP YOUR DATABASE before performing this fix!<br>"; - echo "WARNING: ONLY PROCEEDS IF YOU KNOW WHAT YOU ARE DOING!<br>"; + echo "WARNING: ONLY PROCEED IF YOU KNOW WHAT YOU ARE DOING!<br></p>"; echo " <form action='install.php?action=Database_user_deletion_fix' method='POST'> - <input type='submit' value='go!'> + <input type='submit' value='Go'> </form> "; @@ -101,6 +123,7 @@ if(is_readable("config.php")) { } else if($_GET["action"] == "logout") { session_destroy(); + echo "<h3>Logged Out</h3><p>You have been logged out.</p><a href='index.php'>Main Shimmie Page</a>"; } else if($_GET["action"] == "Database_user_deletion_fix") { Database_user_deletion_fix(); @@ -123,13 +146,24 @@ if(is_readable("config.php")) { echo "\t\t</div>"; exit; } -require_once "core/compat.inc.php"; -require_once "core/util.inc.php"; -require_once "core/database.class.php"; do_install(); // utilities {{{ + +/** + * Strips off any kind of slash at the end so as to normalise the path. + * @param string $path Path to normalise. + * @return string Path without trailing slash. + */ +function remove_trailing_slash($path) { + if ((substr($path, -1) === '/') || (substr($path, -1) === '\\')) { + return substr($path, 0, -1); + } else { + return $path; + } +} + function check_gd_version() { $gdversion = 0; @@ -394,15 +428,14 @@ EOD; } } // }}} -function Database_user_deletion_fix() { +function Database_user_deletion_fix() { // {{{ try { - require_once "core/database.class.php"; $db = new Database(); - if ($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') { + if ($db->db->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') { echo "<br><br>Database is not MySQL - Aborting changes.<br><br>"; echo '<a href="install.php">Go Back</a>'; - return; + throw new PDOException("Database is not MySQL."); } else { echo "<h3>Performing Database Fix Operations</h3><br>"; } @@ -443,7 +476,7 @@ function Database_user_deletion_fix() { // FIXME: Make the error message user friendly exit($e->getMessage()); } -} +} // }}} ?> </body> </html>