install/upgrade.php
changeset 494 6c78cc456091
parent 486 600a92aa34c7
child 496 449b042ea6b0
equal deleted inserted replaced
493:d8296f89ebb5 494:6c78cc456091
    14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    15  */
    15  */
    16 
    16 
    17 define('IN_ENANO', 1);
    17 define('IN_ENANO', 1);
    18 
    18 
    19 // The list of versions in THIS BRANCH, in chronological order.
    19 // The list of versions in THIS AND PREVIOUS branches, in chronological order.
    20 $enano_versions = array('1.1.1', '1.1.2', '1.1.3');
    20 $enano_versions = array();
       
    21 $enano_versions['1.0'] = array('1.0', '1.0.1', '1.0.2b1', '1.0.2', '1.0.3', '1.0.4');
       
    22 $enano_versions['1.1'] = array('1.1.1', '1.1.2', '1.1.3');
    21 
    23 
    22 // Turn on every imaginable API hack to make common load on older databases
    24 // Turn on every imaginable API hack to make common load on older databases
    23 define('IN_ENANO_UPGRADE', 1);
    25 define('IN_ENANO_UPGRADE', 1);
    24 define('IN_ENANO_MIGRATION', 1);
    26 define('IN_ENANO_MIGRATION', 1);
    25 define('ENANO_ALLOW_LOAD_NOLANG', 1);
    27 define('ENANO_ALLOW_LOAD_NOLANG', 1);
    26 @ini_set('display_errors', 'on');
    28 @ini_set('display_errors', 'on');
    27 
    29 
    28 require('includes/sql_parse.php');
    30 // Load installer files
    29 
    31 require_once('includes/sql_parse.php');
    30 require_once('includes/common.php');
    32 require_once('includes/common.php');
       
    33 require_once('includes/libenanoinstall.php');
       
    34 
    31 // when the installer's common is loaded, it runs chdir() to the ENANO_ROOT, thus making this Enano's common.php
    35 // when the installer's common is loaded, it runs chdir() to the ENANO_ROOT, thus making this Enano's common.php
    32 require_once('includes/common.php');
    36 require_once('includes/common.php');
    33 @ini_set('display_errors', 'on');
    37 @ini_set('display_errors', 'on');
    34 
    38 
    35 $ui = new Enano_Installer_UI('Enano upgrader', false);
    39 $ui = new Enano_Installer_UI('Enano upgrader', false);
   151 // The real migration code
   155 // The real migration code
   152 $ui->show_header();
   156 $ui->show_header();
   153 
   157 
   154 if ( isset($_GET['stage']) && @$_GET['stage'] == 'pimpmyenano' )
   158 if ( isset($_GET['stage']) && @$_GET['stage'] == 'pimpmyenano' )
   155 {
   159 {
       
   160   /*
       
   161    HOW DOES ENANO'S UPGRADER WORK?
       
   162    
       
   163    Versions of Enano are organized into branches and then specific versions by
       
   164    version number. The upgrader works by using a list of known version numbers
       
   165    and then systematically executing upgrade schemas for each version.
       
   166    
       
   167    When the user requests an upgrade, the first thing performed is a migration
       
   168    check, which verifies that they are within the right branch. If they are not
       
   169    within the right branch the upgrade framework will load a migration script
       
   170    which will define a function named MIGRATE(). Performing more than one
       
   171    migration in one pass will probably never be supported. How that works for
       
   172    UX in 1.3.x/1.4.x I know not yet.
       
   173    
       
   174    After performing any necessary branch migrations, the framework will perform
       
   175    any upgrades within the target branch, which is the first two parts
       
   176    (delimited by periods) of the installer's version number defined in the
       
   177    installer's common.php.
       
   178    
       
   179    enano_perform_upgrade() will only do upgrades. Not migrations. The two as
       
   180    illustrated within this installer are very different.
       
   181    */
       
   182   
   156   // Do we need to run the migration first?
   183   // Do we need to run the migration first?
   157   if ( substr(enano_version(), 0, 4) != '1.1.' )
   184   list($major_version, $minor_version) = explode('.', enano_version());
       
   185   $current_branch = "$major_version.$minor_version";
       
   186   
       
   187   list($major_version, $minor_version) = explode('.', installer_enano_version());
       
   188   $target_branch = "$major_version.$minor_version";
       
   189   
       
   190   if ( $target_branch != $current_branch )
   158   {
   191   {
   159     require(ENANO_ROOT . '/install/upgrade/migration/1.0-1.1.php');
   192     // First upgrade to the latest revision of the current branch
       
   193     enano_perform_upgrade($current_branch);
       
   194     // Branch migration could be tricky and is often highly specific between
       
   195     // major branches, so just include a custom migration script.
       
   196     require(ENANO_ROOT . "/install/schemas/upgrade/migration/{$current_branch}-{$target_branch}.php");
   160     $result = MIGRATE();
   197     $result = MIGRATE();
   161     if ( !$result )
   198     if ( !$result )
   162     {
   199     {
   163       echo 'Migration failed, there should be an error message above.';
   200       echo 'Migration failed, there should be an error message above.';
   164       $ui->show_footer();
   201       $ui->show_footer();
   165       exit;
   202       exit;
   166     }
   203     }
   167   }
   204   }
   168   // Main upgrade stage
   205   
   169   
   206   // Do the actual upgrade
   170   // Init vars
   207   enano_perform_upgrade($target_branch);
   171   $version_flipped = array_flip($enano_versions);
   208   
   172   $version_curr = enano_version();
       
   173   $version_target = installer_enano_version();
       
   174   
       
   175   // Calculate which scripts to run
       
   176   if ( !isset($version_flipped[$version_curr]) )
       
   177   {
       
   178     echo '<p>ERROR: Unsupported version</p>';
       
   179     $ui->show_footer();
       
   180     exit;
       
   181   }
       
   182   if ( !isset($version_flipped[$version_target]) )
       
   183   {
       
   184     echo '<p>ERROR: Upgrader doesn\'t support its own version</p>';
       
   185     $ui->show_footer();
       
   186     exit;
       
   187   }
       
   188   $upg_queue = array();
       
   189   for ( $i = $version_flipped[$version_curr]; $i < $version_flipped[$version_target]; $i++ )
       
   190   {
       
   191     if ( !isset($enano_versions[$i + 1]) )
       
   192     {
       
   193       echo '<p>ERROR: Unsupported intermediate version</p>';
       
   194       $ui->show_footer();
       
   195       exit;
       
   196     }
       
   197     $ver_this = $enano_versions[$i];
       
   198     $ver_next = $enano_versions[$i + 1];
       
   199     $upg_queue[] = array($ver_this, $ver_next);
       
   200   }
       
   201   
       
   202   // Verify that all upgrade scripts are usable
       
   203   foreach ( $upg_queue as $verset )
       
   204   {
       
   205     $file = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}-$dbdriver.sql";
       
   206     if ( !file_exists($file) )
       
   207     {
       
   208       echo "<p>ERROR: Couldn't find required schema file: $file</p>";
       
   209       $ui->show_footer();
       
   210       exit;
       
   211     }
       
   212   }
       
   213   // Perform upgrade
       
   214   foreach ( $upg_queue as $verset )
       
   215   {
       
   216     $file = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}-$dbdriver.sql";
       
   217     try
       
   218     {
       
   219       $parser = new SQL_Parser($file);
       
   220     }
       
   221     catch(Exception $e)
       
   222     {
       
   223       die("<pre>$e</pre>");
       
   224     }
       
   225     
       
   226     $parser->assign_vars(array(
       
   227       'TABLE_PREFIX' => table_prefix
       
   228     ));
       
   229   
       
   230     $sql_list = $parser->parse();
       
   231   
       
   232     foreach ( $sql_list as $sql )
       
   233     {
       
   234       if ( !$db->sql_query($sql) )
       
   235         $db->_die();
       
   236     }
       
   237     
       
   238     // Is there an additional script (logic) to be run after the schema?
       
   239     $postscript = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}.php";
       
   240     if ( file_exists($postscript) )
       
   241       @include($postscript);
       
   242     
       
   243     // The advantage of calling setConfig on the system version here?
       
   244     // Simple. If the upgrade fails, it will pick up from the last
       
   245     // version, not try to start again from the beginning. This will
       
   246     // still cause errors in most cases though. Eventually we probably
       
   247     // need some sort of query-numbering system that tracks in-progress
       
   248     // upgrades.
       
   249     
       
   250     setConfig('enano_version', $verset[1]);
       
   251   }
       
   252   echo '<p>All done!</p>';
   209   echo '<p>All done!</p>';
   253 }
   210 }
   254 else
   211 else
   255 {
   212 {
   256   ?>
   213   ?>