install/includes/libenanoinstall.php
author Dan
Fri, 18 Dec 2009 21:11:42 -0500
changeset 1182 58af2268331b
parent 1144 fcb2be1428e7
child 1183 15957df91ea4
permissions -rw-r--r--
Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     1
<?php
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     2
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     3
/*
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 945
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     6
 * Installation package
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     7
 * libenanoinstall.php - Installation payload backend
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     8
 *
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
     9
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    10
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    11
 *
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    14
 */
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    15
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    16
$neutral_color = 'C';
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    17
1182
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    18
// Chat log from the night of the 1.1.7 release:
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    19
// (09:08:20 PM) Neal: btw, did you figure out what caused the PHP fatal error in the 1.1.7
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    20
//                     trunk for the CLI autoinstall script for the BitNami installer?
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    21
// (09:08:38 PM) Dan: oh
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    22
// (09:08:40 PM) Dan: eh
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    23
// (09:08:45 PM) Dan: yeah i'll fix that real quick
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    24
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    25
// Hence, the function_exists check.
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    26
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    27
if ( !function_exists('run_installer_stage') ):
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    28
function run_installer_stage($stage_id, $stage_name, $function, $failure_explanation, $allow_skip = true)
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    29
{
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    30
  static $resumed = false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    31
  static $resume_stack = array();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    32
  
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    33
  if ( empty($resume_stack) && isset($_POST['resume_stack']) && preg_match('/[a-z_]+((\|[a-z_]+)+)/', $_POST['resume_stack']) )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    34
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    35
    $resume_stack = explode('|', $_POST['resume_stack']);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    36
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    37
  
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    38
  $already_run = false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    39
  if ( in_array($stage_id, $resume_stack) )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    40
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    41
    $already_run = true;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    42
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    43
  
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    44
  if ( !$resumed )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    45
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    46
    if ( !isset($_GET['sub']) )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    47
      $resumed = true;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    48
    if ( isset($_GET['sub']) && $_GET['sub'] == $stage_id )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    49
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    50
      $resumed = true;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    51
    }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    52
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    53
  if ( !$resumed && $allow_skip )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    54
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    55
    echo_stage_success($stage_id, $stage_name);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    56
    return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    57
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    58
  if ( !function_exists($function) )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    59
    die('libenanoinstall: CRITICAL: function "' . $function . '" for ' . $stage_id . ' doesn\'t exist');
945
c19242d13a49 Removed "@" from all call_user_func() calls to make debugging special pages and such possible
Dan
parents: 857
diff changeset
    60
  $result = call_user_func($function, false, $already_run);
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    61
  if ( $result )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    62
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    63
    echo_stage_success($stage_id, $stage_name);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    64
    $resume_stack[] = $stage_id;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    65
    return true;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    66
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    67
  else
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    68
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    69
    echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    70
    return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    71
  }
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    72
}
1182
58af2268331b Fixed libenanoinstall/CLI double declaration of run_installer_stage()
Dan
parents: 1144
diff changeset
    73
endif;
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    74
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    75
function start_install_table()
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    76
{
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    77
  echo '<table border="0" cellspacing="0" cellpadding="0" style="margin-top: 10px;">' . "\n";
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    78
}
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    79
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    80
function close_install_table()
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    81
{
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    82
  echo '</table>' . "\n\n";
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    83
  flush();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    84
}
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    85
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    86
function echo_stage_success($stage_id, $stage_name)
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    87
{
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    88
  global $neutral_color;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    89
  $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
404
fb4f9e6f378f Made the form validation icons (check/X/?) more visually appealing. IE-friendliness is still on the TODO list.
Dan
parents: 352
diff changeset
    90
  echo '<tr><td style="width: 500px; background-color: #' . "{$neutral_color}{$neutral_color}FF{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Done" src="../images/check.png" /></td></tr>' . "\n";
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    91
  flush();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    92
}
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    93
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    94
function echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack)
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    95
{
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    96
  global $neutral_color;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    97
  global $lang;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    98
  
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
    99
  $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A';
404
fb4f9e6f378f Made the form validation icons (check/X/?) more visually appealing. IE-friendliness is still on the TODO list.
Dan
parents: 352
diff changeset
   100
  echo '<tr><td style="width: 500px; background-color: #' . "FF{$neutral_color}{$neutral_color}{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Failed" src="../images/checkbad.png" /></td></tr>' . "\n";
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   101
  flush();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   102
  close_install_table();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   103
  $post_data = '';
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   104
  $mysql_error = mysql_error();
626
be0e904eec17 Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents: 536
diff changeset
   105
  $file = ( defined('IN_ENANO_UPGRADE') ) ? 'upgrade.php' : 'install.php';
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   106
  foreach ( $_POST as $key => $value )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   107
  {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   108
    // FIXME: These should really also be sanitized for double quotes
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   109
    $value = htmlspecialchars($value);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   110
    $key = htmlspecialchars($key);
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   111
    $post_data .= "          <input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   112
  }
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   113
  if ( $stage_id == 'renameconfig' )
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   114
    echo '<p>' . $failure_explanation . '</p>';
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   115
  else
626
be0e904eec17 Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents: 536
diff changeset
   116
    echo '<form action="' . $file . '?stage=install&amp;sub=' . $stage_id . '" method="post">
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   117
            ' . $post_data . '
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   118
            <input type="hidden" name="resume_stack" value="' . htmlspecialchars(implode('|', $resume_stack)) . '" />
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   119
            <h3>' . $lang->get('meta_msg_err_stagefailed_title') . '</h3>
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   120
             <p>' . $failure_explanation . '</p>
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   121
             ' . ( !empty($mysql_error) ? "<p>" . $lang->get('meta_msg_err_stagefailed_mysqlerror') . " $mysql_error</p>" : '' ) . '
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   122
             <p>' . $lang->get('meta_msg_err_stagefailed_body') . '</p>
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   123
             <p style="text-align: center;"><input type="submit" value="' . $lang->get('meta_btn_retry_installation') . '" /></p>
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   124
          </form>';
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   125
  global $ui;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   126
  $ui->show_footer();
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   127
  exit;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   128
}
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
diff changeset
   129
1144
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   130
function install_get_crypto_backend()
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   131
{
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   132
  $crypto_backend = 'none';
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   133
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   134
  // Extension test: BCMath
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   135
  if ( function_exists('bcadd') )
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   136
    $crypto_backend = 'bcmath';
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   137
  
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   138
  // Extension test: Big_Int
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   139
  if ( function_exists('bi_from_str') )
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   140
    $crypto_backend = 'bigint';
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   141
  
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   142
  // Extension test: GMP
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   143
  if ( function_exists('gmp_init') )
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   144
    $crypto_backend = 'gmp';
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   145
  
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   146
  return $crypto_backend;
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   147
}
fcb2be1428e7 Installer sysreqs: Merged all the crypto extensions into one check; altered warnings. Strings are hopefully cleaned up.
Dan
parents: 1081
diff changeset
   148
494
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   149
function enano_perform_upgrade($target_branch)
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   150
{
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   151
  global $db, $session, $paths, $template, $plugins; // Common objects
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   152
  // Import version info
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   153
  global $enano_versions;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   154
  // Import UI functions
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   155
  global $ui;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   156
  // This is needed for upgrade abstraction
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   157
  global $dbdriver;
627
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   158
  
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   159
  // see if we're actually supposed to be in post-upgrade
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   160
  if ( getConfig('enano_version') == 'upg-' . installer_enano_version() )
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   161
  {
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   162
    // yep, fall out here to avoid errors
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   163
    return true;
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   164
  }
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   165
  
494
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   166
  // Main upgrade stage
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   167
  
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   168
  // Init vars
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   169
  list($major_version, $minor_version) = explode('.', installer_enano_version());
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   170
  $installer_branch = "$major_version.$minor_version";
627
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   171
  $installer_branch = preg_replace('/^upg-/', '', $installer_branch);
460e483987ab Fixed a few more upgrader glitches and polished things a bit more.
Dan
parents: 626
diff changeset
   172
  $target_branch = preg_replace('/^upg-/', '', $target_branch);
494
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   173
  
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   174
  $version_flipped = array_flip($enano_versions[$target_branch]);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   175
  $version_curr = enano_version();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   176
  // Change this to be the last version in the current branch.
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   177
  // If we're just upgrading within this branch, use the version the installer library
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   178
  // reports to us. Else, use the latest in the old (current target) branch.
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   179
  // $version_target = installer_enano_version();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   180
  $version_target = ( $target_branch === $installer_branch ) ? installer_enano_version() : $enano_versions[$target_branch][ count($enano_versions[$target_branch]) - 1 ];
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   181
  
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   182
  // Calculate which scripts to run
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   183
  if ( !isset($version_flipped[$version_curr]) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   184
  {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   185
    echo '<p>ERROR: Unsupported version</p>';
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   186
    $ui->show_footer();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   187
    exit;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   188
  }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   189
  if ( !isset($version_flipped[$version_target]) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   190
  {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   191
    echo '<p>ERROR: Upgrader doesn\'t support its own version</p>';
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   192
    $ui->show_footer();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   193
    exit;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   194
  }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   195
  $upg_queue = array();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   196
  for ( $i = $version_flipped[$version_curr]; $i < $version_flipped[$version_target]; $i++ )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   197
  {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   198
    if ( !isset($enano_versions[$target_branch][$i + 1]) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   199
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   200
      echo '<p>ERROR: Unsupported intermediate version</p>';
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   201
      $ui->show_footer();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   202
      exit;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   203
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   204
    $ver_this = $enano_versions[$target_branch][$i];
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   205
    $ver_next = $enano_versions[$target_branch][$i + 1];
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   206
    $upg_queue[] = array($ver_this, $ver_next);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   207
  }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   208
  
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   209
  // Verify that all upgrade scripts are usable
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   210
  foreach ( $upg_queue as $verset )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   211
  {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   212
    $file = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}-$dbdriver.sql";
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   213
    if ( !file_exists($file) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   214
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   215
      echo "<p>ERROR: Couldn't find required schema file: $file</p>";
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   216
      $ui->show_footer();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   217
      exit;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   218
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   219
  }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   220
  // Perform upgrade
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   221
  foreach ( $upg_queue as $verset )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   222
  {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   223
    $file = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}-$dbdriver.sql";
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   224
    try
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   225
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   226
      $parser = new SQL_Parser($file);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   227
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   228
    catch(Exception $e)
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   229
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   230
      die("<pre>$e</pre>");
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   231
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   232
    
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   233
    $parser->assign_vars(array(
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   234
      'TABLE_PREFIX' => table_prefix
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   235
    ));
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   236
  
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   237
    $sql_list = $parser->parse();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   238
    // Check for empty schema file
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   239
    if ( $sql_list[0] === ';' && count($sql_list) == 1 )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   240
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   241
      // It's empty, report success for this version
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   242
      // See below for explanation of why setConfig() is called here
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   243
      setConfig('enano_version', $verset[1]);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   244
      continue;
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   245
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   246
    
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   247
    foreach ( $sql_list as $sql )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   248
    {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   249
      // check for '@' operator on query
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   250
      if ( substr($sql, 0, 1) == '@' )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   251
      {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   252
        // Yes - perform query but don't check for errors
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   253
        $db->sql_query($sql);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   254
      }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   255
      else
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   256
      {
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   257
        // Perform as normal
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   258
        if ( !$db->sql_query($sql) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   259
          $db->_die();
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   260
      }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   261
    }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   262
    
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   263
    // Is there an additional script (logic) to be run after the schema?
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   264
    $postscript = ENANO_ROOT . "/install/schemas/upgrade/{$verset[0]}-{$verset[1]}.php";
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   265
    if ( file_exists($postscript) )
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   266
      @include($postscript);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   267
    
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   268
    // The advantage of calling setConfig on the system version here?
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   269
    // Simple. If the upgrade fails, it will pick up from the last
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   270
    // version, not try to start again from the beginning. This will
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   271
    // still cause errors in most cases though. Eventually we probably
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   272
    // need some sort of query-numbering system that tracks in-progress
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   273
    // upgrades.
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   274
    
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   275
    setConfig('enano_version', $verset[1]);
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   276
  }
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   277
}
6c78cc456091 Added support for upgrading arbitrary previous 1.0.x versions (very experimental)
Dan
parents: 404
diff changeset
   278