| 1 |
<?php |
|---|
| 2 |
global $db, $METATABLES; |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
if (!$METATABLES) { |
|---|
| 6 |
$maintables = false; |
|---|
| 7 |
} else { |
|---|
| 8 |
$maintables = false; |
|---|
| 9 |
$datalists = false; |
|---|
| 10 |
foreach ($METATABLES as $table) { |
|---|
| 11 |
if (preg_match("/^{$CFG->prefix}users$/", $table)) { |
|---|
| 12 |
$maintables = true; |
|---|
| 13 |
} |
|---|
| 14 |
if (preg_match("/^{$CFG->prefix}datalists$/", $table)) { |
|---|
| 15 |
$datalists = true; |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
$strdatabasesuccess = "Yay!"; |
|---|
| 21 |
|
|---|
| 22 |
$newinstall = false; |
|---|
| 23 |
|
|---|
| 24 |
if (!$maintables) { |
|---|
| 25 |
if (file_exists($CFG->dirroot . "lib/db/$CFG->dbtype.sql")) { |
|---|
| 26 |
$db->debug = true; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
$continue = true; |
|---|
| 30 |
$infoarr = $db->ServerInfo(); |
|---|
| 31 |
if (!empty($infoarr['version'])) { |
|---|
| 32 |
switch($CFG->dbtype) { |
|---|
| 33 |
case "mysql": |
|---|
| 34 |
if (!preg_match('/^(4\.1|[5-9]\.|[0-9][0-9]+)/', $infoarr['version'])) { |
|---|
| 35 |
error('Error: Your MySQL version is too old: ' . $infoarr['version'] . '. Elgg requires MySQL 4.1 or newer. 5.0 or newer is recommended.'); |
|---|
| 36 |
$continue = false; |
|---|
| 37 |
} |
|---|
| 38 |
break; |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
if ($continue) { |
|---|
| 43 |
if (modify_database($CFG->dirroot . "lib/db/$CFG->dbtype.sql")) { |
|---|
| 44 |
include_once($CFG->dirroot . "version.php"); |
|---|
| 45 |
set_config('version', $version); |
|---|
| 46 |
$db->debug = false; |
|---|
| 47 |
notify($strdatabasesuccess, "green"); |
|---|
| 48 |
if (!isset($CFG->newsinitialpassword) || empty($CFG->newsinitialpassword)) { |
|---|
| 49 |
notify("WARNING: the initial password for the news account is 'password'. This account has administrator privileges, and you should log in and change the password as soon as installation is complete."); |
|---|
| 50 |
} else { |
|---|
| 51 |
|
|---|
| 52 |
//execute_sql("update ".$CFG->prefix."users set password = $newspassword where username = 'news'"); |
|---|
| 53 |
set_field('users', 'password', md5($CFG->newsinitialpassword), 'username', 'news'); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
set_field('users', 'email', $CFG->sysadminemail, 'username', 'news'); |
|---|
| 57 |
} else { |
|---|
| 58 |
$db->debug = false; |
|---|
| 59 |
error("Error: Main databases NOT set up successfully"); |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
} else { |
|---|
| 63 |
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Elgg. See the lib/db directory."); |
|---|
| 64 |
} |
|---|
| 65 |
print_continue("index.php"); |
|---|
| 66 |
die; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
if (user_flag_get("admin",$_SESSION['userid'])) { |
|---|
| 70 |
|
|---|
| 71 |
if (empty($CFG->version)) { |
|---|
| 72 |
$CFG->version = 1; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
if (empty($CFG->release)) { |
|---|
| 76 |
$CFG->release = ""; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
if (!$datalists) { |
|---|
| 80 |
$CFG->version = -1; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
include_once($CFG->dirroot . "version.php"); |
|---|
| 85 |
include_once($CFG->dirroot . "lib/db/$CFG->dbtype.php"); |
|---|
| 86 |
|
|---|
| 87 |
if ($CFG->version) { |
|---|
| 88 |
if ($version > $CFG->version) { |
|---|
| 89 |
|
|---|
| 90 |
$a->oldversion = "$CFG->release ($CFG->version)"; |
|---|
| 91 |
$a->newversion = "$release ($version)"; |
|---|
| 92 |
|
|---|
| 93 |
if (empty($_GET['confirmupgrade'])) { |
|---|
| 94 |
notice_yesno(__gettext('Need to upgrade database'), $CFG->wwwroot . '?confirmupgrade=yes', ''); |
|---|
| 95 |
exit; |
|---|
| 96 |
|
|---|
| 97 |
} else { |
|---|
| 98 |
$db->debug=true; |
|---|
| 99 |
if (main_upgrade($CFG->version)) { |
|---|
| 100 |
$db->debug=false; |
|---|
| 101 |
if (set_config("version", $version)) { |
|---|
| 102 |
notify($strdatabasesuccess, "green"); |
|---|
| 103 |
print_continue("index.php"); |
|---|
| 104 |
exit; |
|---|
| 105 |
} else { |
|---|
| 106 |
notify("Upgrade failed! (Could not update version in config table)"); |
|---|
| 107 |
} |
|---|
| 108 |
} else { |
|---|
| 109 |
$db->debug=false; |
|---|
| 110 |
notify("Upgrade failed! See /version.php"); |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
} else if ($version < $CFG->version) { |
|---|
| 114 |
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!"); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
} else { |
|---|
| 118 |
if (set_config("version", $version)) { |
|---|
| 119 |
print_header("Elgg $release ($version)"); |
|---|
| 120 |
print_continue("index.php"); |
|---|
| 121 |
die; |
|---|
| 122 |
} else { |
|---|
| 123 |
$db->debug=true; |
|---|
| 124 |
if (main_upgrade(0)) { |
|---|
| 125 |
print_continue("index.php"); |
|---|
| 126 |
} else { |
|---|
| 127 |
error("A problem occurred inserting current version into databases"); |
|---|
| 128 |
} |
|---|
| 129 |
$db->debug=false; |
|---|
| 130 |
} |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
} |
|---|
| 134 |
?> |
|---|