From 07e3f7d4ce5e7bfccc9c83b7406b687c9bcb2764 Mon Sep 17 00:00:00 2001 From: ozhozh Date: Wed, 17 Mar 2010 21:15:32 +0000 Subject: [PATCH] 1.4.3 : hopefully a fixed upgrader. Fixes issue 277 git-svn-id: http://yourls.googlecode.com/svn/trunk@303 12232710-3e20-11de-b438-597f59cd7555 --- changelog.txt | 5 +- includes/functions-upgrade.php | 100 ++++++++++++++++++++------------- includes/version.php | 4 +- 3 files changed, 68 insertions(+), 41 deletions(-) diff --git a/changelog.txt b/changelog.txt index 68eef8b..f918988 100644 --- a/changelog.txt +++ b/changelog.txt @@ -45,4 +45,7 @@ list, simply refer to the commit messages: http://code.google.com/p/yourls/sourc 1.4.2 - fixed bug in auth function - added sample public API file -- added check in API requests for WordPress plugin when adding a new short URL \ No newline at end of file +- added check in API requests for WordPress plugin when adding a new short URL + +1.4.3 +- fixed bug in stats \ No newline at end of file diff --git a/includes/functions-upgrade.php b/includes/functions-upgrade.php index 17a1429..37d4643 100644 --- a/includes/functions-upgrade.php +++ b/includes/functions-upgrade.php @@ -2,55 +2,79 @@ // Upgrade YOURLS and DB schema function yourls_upgrade( $step, $oldver, $newver, $oldsql, $newsql ) { - if( $oldver == '1.3') { + /* Code / DB version table: + 1.3 100 + 1.4 200 + 1.4.1 210 + 1.4.3 220 */ + + // special case for 1.3: the upgrade is a multi step procedure + if( $oldsql == 100 ) { yourls_upgrade_to_14( $step ); - } elseif ( $oldver == '1.4' ) { - yourls_upgrade_to_141( $step ); } -} - -/************************** 1.4 -> 1.4.1 **************************/ - -// Main func for upgrade from 1.4 to 1.4.1 -function yourls_upgrade_to_141( $step ) { + + // other upgrades which are done in a single pass switch( $step ) { + case 1: - // Kill old cookies from 1.3 and prior - setcookie('yourls_username', null, time() - 3600 ); - setcookie('yourls_password', null, time() - 3600 ); - // alter table URL - yourls_alter_url_table_to_141(); - // recreate the htaccess file if needed - yourls_create_htaccess(); - yourls_redirect_javascript( YOURLS_SITE."/admin/upgrade.php?step=3&oldver=1.4&newver=1.4.1&oldsql=200&newsql=210" ); + case 2: + if( $oldsql < 210 ) + yourls_upgrade_to_141(); + + if( $oldsql < 220 ) + yourls_upgrade_to_143(); + + yourls_redirect_javascript( yourls_admin_url( "upgrade.php?step=3" ) ); + break; - case 2: case 3: - // Update options - yourls_update_options_to_141(); + // Update options to reflect latest version + yourls_update_option( 'version', YOURLS_VERSION ); + yourls_update_option( 'db_version', YOURLS_DB_VERSION ); + break; } } -// Alter table URL to 1.4.1 -function yourls_alter_url_table_to_141() { +/************************** 1.4.1 -> 1.4.3 **************************/ + +// Main func for upgrade from 1.4.1 to 1.4.3 +function yourls_upgrade_to_143( ) { + // Check if we have 'keyword' (borked install) or 'shorturl' (ok install) global $ydb; - $table_url = YOURLS_DB_TABLE_URL; $table_log = YOURLS_DB_TABLE_LOG; - $alters[] = "ALTER TABLE `$table_url` CHANGE `keyword` `keyword` VARCHAR( 200 ) BINARY, CHANGE `url` `url` TEXT BINARY "; - $alters[] = "ALTER TABLE `$table_log` CHANGE `shorturl` `keyword` VARCHAR( 200 ) BINARY;"; - foreach( $alters as $alter ) { - $ydb->query( $alter ); + $sql = "SHOW COLUMNS FROM `$table_log`"; + $cols = $ydb->get_results( $sql ); + if ( $cols[2]->Field == 'keyword' ) { + $sql = "ALTER TABLE `$table_log` CHANGE `keyword` `shorturl` VARCHAR( 200 ) BINARY;"; + $ydb->query( $sql ); } echo "

Structure of existing tables updated. Please wait...

"; } -// Update options to reflect version 1.4.1 -function yourls_update_options_to_141() { - yourls_update_option( 'version', YOURLS_VERSION ); - yourls_update_option( 'db_version', YOURLS_DB_VERSION ); +/************************** 1.4 -> 1.4.1 **************************/ + +// Main func for upgrade from 1.4 to 1.4.1 +function yourls_upgrade_to_141( ) { + // Kill old cookies from 1.3 and prior + setcookie('yourls_username', null, time() - 3600 ); + setcookie('yourls_password', null, time() - 3600 ); + // alter table URL + yourls_alter_url_table_to_141(); + // recreate the htaccess file if needed + yourls_create_htaccess(); +} + +// Alter table URL to 1.4.1 +function yourls_alter_url_table_to_141() { + global $ydb; + $table_url = YOURLS_DB_TABLE_URL; + $alter = "ALTER TABLE `$table_url` CHANGE `keyword` `keyword` VARCHAR( 200 ) BINARY, CHANGE `url` `url` TEXT BINARY "; + $ydb->query( $alter ); + echo "

Structure of existing tables updated. Please wait...

"; } + /************************** 1.3 -> 1.4 **************************/ // Main func for upgrade from 1.3-RC1 to 1.4 @@ -67,7 +91,7 @@ function yourls_upgrade_to_14( $step ) { $create = yourls_create_htaccess(); // returns bool if ( !$create ) echo "

Please create your .htaccess file (I could not do it for you). Please refer to http://yourls.org/htaccess."; - yourls_redirect_javascript( YOURLS_SITE."/admin/upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200", $create ); + yourls_redirect_javascript( yourls_admin_url( "upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200" ), $create ); break; case 2: @@ -82,15 +106,15 @@ function yourls_upgrade_to_14( $step ) { // attempt to drop YOURLS_DB_TABLE_NEXTDEC yourls_update_options_to_14(); // Now upgrade to 1.4.1 - yourls_redirect_javascript( YOURLS_SITE."/admin/upgrade.php?step=1&oldver=1.4&newver=1.4.1&oldsql=200&newsql=210" ); + yourls_redirect_javascript( yourls_admin_url( "upgrade.php?step=1&oldver=1.4&newver=1.4.1&oldsql=200&newsql=210" ) ); break; } } // Update options to reflect new version function yourls_update_options_to_14() { - yourls_update_option( 'version', YOURLS_VERSION ); - yourls_update_option( 'db_version', YOURLS_DB_VERSION ); + yourls_update_option( 'version', '1.4' ); + yourls_update_option( 'db_version', '200' ); if( defined('YOURLS_DB_TABLE_NEXTDEC') ) { global $ydb; @@ -180,7 +204,7 @@ function yourls_update_table_to_14() { $table = YOURLS_DB_TABLE_URL; // Modify each link to reflect new structure - $chunk = 15; + $chunk = 45; $from = isset($_GET['from']) ? intval( $_GET['from'] ) : 0 ; $total = yourls_get_db_stats(); $total = $total['total_links']; @@ -217,11 +241,11 @@ function yourls_update_table_to_14() { $from = $from + $chunk; $remain = $total - $from; echo "

Converted $chunk database rows ($remain remaining). Continuing... Please do not close this window until it's finished!

"; - yourls_redirect_javascript( YOURLS_SITE."/admin/upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200&from=$from", $success ); + yourls_redirect_javascript( yourls_admin_url( "upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200&from=$from" ), $success ); } else { // All done echo '

All rows converted! Please wait...

'; - yourls_redirect_javascript( YOURLS_SITE."/admin/upgrade.php?step=3&oldver=1.3&newver=1.4&oldsql=100&newsql=200", $success ); + yourls_redirect_javascript( yourls_admin_url( "upgrade.php?step=3&oldver=1.3&newver=1.4&oldsql=100&newsql=200" ), $success ); } } diff --git a/includes/version.php b/includes/version.php index 6f3ef1f..22a988d 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,5 +1,5 @@ \ No newline at end of file -- 2.45.0