Skip to content

Commit

Permalink
1.4.3 : hopefully a fixed upgrader. Fixes issue 277
Browse files Browse the repository at this point in the history
git-svn-id: http://yourls.googlecode.com/svn/trunk@303 12232710-3e20-11de-b438-597f59cd7555
  • Loading branch information
ozh committed Mar 17, 2010
1 parent 06415e9 commit 07e3f7d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
- added check in API requests for WordPress plugin when adding a new short URL

1.4.3
- fixed bug in stats
100 changes: 62 additions & 38 deletions includes/functions-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<p>Structure of existing tables updated. Please wait...</p>";
}

// 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 "<p>Structure of existing tables updated. Please wait...</p>";
}


/************************** 1.3 -> 1.4 **************************/

// Main func for upgrade from 1.3-RC1 to 1.4
Expand All @@ -67,7 +91,7 @@ function yourls_upgrade_to_14( $step ) {
$create = yourls_create_htaccess(); // returns bool
if ( !$create )
echo "<p class='warning'>Please create your <tt>.htaccess</tt> file (I could not do it for you). Please refer to <a href='http://yourls.org/htaccess'>http://yourls.org/htaccess</a>.";
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:
Expand All @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -217,11 +241,11 @@ function yourls_update_table_to_14() {
$from = $from + $chunk;
$remain = $total - $from;
echo "<p>Converted $chunk database rows ($remain remaining). Continuing... Please do not close this window until it's finished!</p>";
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 '<p>All rows converted! Please wait...</p>';
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 );
}

}
Expand Down
4 changes: 2 additions & 2 deletions includes/version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// Bump this when updating the zip package
define('YOURLS_VERSION', '1.4.2');
define('YOURLS_DB_VERSION', '210');
define('YOURLS_VERSION', '1.4.3');
define('YOURLS_DB_VERSION', '220');
?>

0 comments on commit 07e3f7d

Please sign in to comment.