bobbinsbro Posted January 18, 2009 Share Posted January 18, 2009 hi every1 i have recently joined a project in full swing ( = there's a s**t load of written code). this project runs an install script that creates and initializes a new database, creates new users in the database users table and creates a settings file. i've been helping debug this install process, and everytime the install fails, i have to go througha routine of DROPping users from the DB, DROPping the shcema and deleting the settings file. 1 of my assignments is to write rollback code, so that when an install fails, we won't have to keep reverting changes manually. in most cases, on script error, the php die() function is called. it is called in a whole lot of places... i was wondering if there was a way to re-declare die() at the global scope with enhanced functionality (the functionality needed to revert the crashed install), so that i don't have to go through all the files in the project (over 700 files) and change every die() function the a custom uninstall() function. please tell me there's a way to do this... it will probably be a temporary change (changing die is unsafe in the long term, i know), but it would make the debugging of the install so much more productive. what i would like to do is something like this: <?php //in the global scope function die($msg){ //drop users from database users table //drop schema //unlink('settings_file'); echo $msg; exit; } ?> if you think i'm coming at this problem from the wrong direction, please share your thoughts/recommendations/ideas. they are all welcome. thanx in advance, bobbinsbro Quote Link to comment Share on other sites More sharing options...
elgoog Posted January 18, 2009 Share Posted January 18, 2009 You could maybe add the table dropping to the start of the install script and dont worry if it fails? DROP TABLE IF EXISTS `tablename` Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 18, 2009 Share Posted January 18, 2009 Just about any IDE will allow you to replace all instances of die() into customDie() or something... Also take a look at those functions http://www.php.net/manual/en/book.errorfunc.php Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted January 18, 2009 Share Posted January 18, 2009 If you were running with the apd module enabled, then you could create a new function to replace die Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted January 18, 2009 Author Share Posted January 18, 2009 thanx guyz. @elgoog - now why didn't i think of that... :-\ duh thanx. @Mchl - thanx for the references. i will definitely take a look at those. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.