install/upgrade.php
changeset 411 d1a95497b68f
parent 377 bb3e6c3bd4f4
child 418 322fa0c91303
equal deleted inserted replaced
410:9db359d6e60c 411:d1a95497b68f
    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.
       
    20 $enano_versions = array('1.1.1', '1.1.2');
       
    21 
    19 // Turn on every imaginable API hack to make common load on older databases
    22 // Turn on every imaginable API hack to make common load on older databases
    20 define('IN_ENANO_UPGRADE', 1);
    23 define('IN_ENANO_UPGRADE', 1);
    21 define('IN_ENANO_MIGRATION', 1);
    24 define('IN_ENANO_MIGRATION', 1);
    22 define('ENANO_ALLOW_LOAD_NOLANG', 1);
    25 define('ENANO_ALLOW_LOAD_NOLANG', 1);
    23 @ini_set('display_errors', 'on');
    26 @ini_set('display_errors', 'on');
    32 $ui = new Enano_Installer_UI('Enano upgrader', false);
    35 $ui = new Enano_Installer_UI('Enano upgrader', false);
    33 if ( version_compare(PHP_VERSION, '5.0.0', '<') )
    36 if ( version_compare(PHP_VERSION, '5.0.0', '<') )
    34 {
    37 {
    35   $ui->__construct('Enano upgrader', false);
    38   $ui->__construct('Enano upgrader', false);
    36 }
    39 }
    37 $ui->add_stage('Welcome', true);
    40 $stg_welcome = $ui->add_stage('Welcome', true);
    38 $ui->add_stage('Select version', true);
    41 $stg_confirm = $ui->add_stage('Confirmation', true);
    39 $ui->add_stage('Perform upgrade', true);
    42 $stg_upgrade = $ui->add_stage('Perform upgrade', true);
    40 $ui->add_stage('Finish', true);
    43 $stg_finish  = $ui->add_stage('Finish', true);
    41 $stg_php4 = $ui->add_stage('PHP4 compatibility notice', false);
    44 $stg_php4 = $ui->add_stage('PHP4 compatibility notice', false);
    42 
    45 
    43 if ( version_compare(PHP_VERSION, '5.0.0', '<') || isset($_GET['debug_warn_php4']) )
    46 if ( version_compare(PHP_VERSION, '5.0.0', '<') || isset($_GET['debug_warn_php4']) )
    44 {
    47 {
    45   $ui->set_visible_stage($stg_php4);
    48   $ui->set_visible_stage($stg_php4);
   134   
   137   
   135   $ui->show_footer();
   138   $ui->show_footer();
   136   exit();
   139   exit();
   137 }
   140 }
   138 
   141 
       
   142 if ( isset($_GET['stage']) && @$_GET['stage'] == 'pimpmyenano' )
       
   143 {
       
   144   $ui->set_visible_stage($stg_upgrade);
       
   145 }
       
   146 else
       
   147 {
       
   148   $ui->set_visible_stage($stg_confirm);
       
   149 }
       
   150 
   139 // The real migration code
   151 // The real migration code
   140 $ui->show_header();
   152 $ui->show_header();
   141 
   153 
   142 if ( isset($_GET['stage']) && @$_GET['stage'] == 'pimpmyenano' )
   154 if ( isset($_GET['stage']) && @$_GET['stage'] == 'pimpmyenano' )
   143 {
   155 {
   144   require('install/schemas/upgrade/migration/1.0-1.1.php');
   156   // Do we need to run the migration first?
   145   if ( MIGRATE() )
   157   if ( substr(enano_version(), 0, 4) != '1.1.' )
   146   {
   158   {
   147     echo '<p>Enano survived the migration. Congratulations, you\'re one of the lucky ones, <a href="' . scriptPath . '/index.php">check out the alpha</a>.</p>';
   159     require(ENANO_ROOT . '/install/upgrade/migration/1.0-1.1.php');
   148   }
   160     $result = MIGRATE();
   149   else
   161     if ( !$result )
   150   {
   162     {
   151     echo '<p>Something went wrong, you should have gotten an error message.</p>';
   163       echo 'Migration failed, there should be an error message above.';
   152   }
   164       $ui->show_footer();
       
   165       exit;
       
   166     }
       
   167   }
       
   168   // Main upgrade stage
       
   169   
       
   170   // Init vars
       
   171   $version_flipped = array_flip($enano_versions);
       
   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     setConfig('enano_version', $verset[1]);
       
   238   }
       
   239   echo '<p>All done!</p>';
   153 }
   240 }
   154 else
   241 else
   155 {
   242 {
   156   ?>
   243   ?>
   157   <p>Nothing's really implemented for now except the actual migration code, which is not very smart. Just <a href="<?php echo $session->append_sid('upgrade.php?stage=pimpmyenano'); ?>">do the upgrade and get it over with</a>.</p>
   244   <p>Nothing's really implemented for now except the actual migration code, which is not very smart. Just <a href="<?php echo $session->append_sid('upgrade.php?stage=pimpmyenano'); ?>">do the upgrade and get it over with</a>.</p>