diff options
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/database.php | 22 | ||||
-rw-r--r-- | engine/lib/version.php | 49 |
2 files changed, 46 insertions, 25 deletions
diff --git a/engine/lib/database.php b/engine/lib/database.php index 87b002508..262e651ee 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -518,9 +518,10 @@ function run_sql_script($scriptlocation) { * * @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example) * @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/) + * @param bool $quiet If true, will suppress all error messages. Don't use this. * @return bool */ -function db_upgrade($version, $fromdir = "") { +function db_upgrade($version, $fromdir = "", $quiet = FALSE) { global $CONFIG; // Elgg and its database must be installed to upgrade it! @@ -539,7 +540,7 @@ function db_upgrade($version, $fromdir = "") { while ($sqlfile = readdir($handle)) { if (!is_dir($fromdir . $sqlfile)) { - if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) { + if (preg_match('/^([0-9]{10})\.(sql)$/', $sqlfile, $matches)) { $sql_version = (int) $matches[1]; if ($sql_version > $version) { $sqlupgrades[] = $sqlfile; @@ -552,17 +553,22 @@ function db_upgrade($version, $fromdir = "") { if (sizeof($sqlupgrades) > 0) { foreach($sqlupgrades as $sqlfile) { -// let's not allow failing upgrade to pass. -// try { + + // hide all errors. + if ($quiet) { + try { + run_sql_script($fromdir . $sqlfile); + } catch (DatabaseException $e) { + error_log($e->getmessage()); + } + } else { run_sql_script($fromdir . $sqlfile); -// } catch (DatabaseException $e) { -// error_log($e->getmessage()); -// } + } } } } - return true; + return TRUE; } /** diff --git a/engine/lib/version.php b/engine/lib/version.php index 3728fb8ec..3cf321a0f 100644 --- a/engine/lib/version.php +++ b/engine/lib/version.php @@ -11,14 +11,15 @@ /** * Run any php upgrade scripts which are required * - * @param unknown_type $version + * @param int $version Version upgrading from. + * @param bool $quiet Suppress errors. Don't use this. */ -function upgrade_code($version) { +function upgrade_code($version, $quiet = FALSE) { global $CONFIG; // Elgg and its database must be installed to upgrade it! if (!is_db_installed() || !is_installed()) { - return false; + return FALSE; } $version = (int) $version; @@ -29,7 +30,7 @@ function upgrade_code($version) { while ($updatefile = readdir($handle)) { // Look for upgrades and add to upgrades list if (!is_dir($CONFIG->path . 'engine/lib/upgrades/' . $updatefile)) { - if (preg_match('/([0-9]*)\.php/',$updatefile,$matches)) { + if (preg_match('/^([0-9]{10})\.(php)$/', $updatefile, $matches)) { $core_version = (int) $matches[1]; if ($core_version > $version) { $upgrades[] = $updatefile; @@ -40,20 +41,29 @@ function upgrade_code($version) { // Sort and execute asort($upgrades); + if (sizeof($upgrades) > 0) { foreach($upgrades as $upgrade) { - try { + // hide all errors. + if ($quiet) { + // hide include errors as well as any exceptions that might happen + try { + if (!@include($CONFIG->path . 'engine/lib/upgrades/' . $upgrade)) { + error_log($e->getmessage()); + } + } catch (Exception $e) { + error_log($e->getmessage()); + } + } else { include($CONFIG->path . 'engine/lib/upgrades/' . $upgrade); - } catch (Exception $e) { - error_log($e->getmessage()); } } } - return true; + return TRUE; } - return false; + return FALSE; } /** @@ -66,11 +76,10 @@ function get_version($humanreadable = false) { global $CONFIG; if (include($CONFIG->path . "version.php")) { - if (!$humanreadable) return $version; - return $release; + return (!$humanreadable) ? $version : $release; } - return false; + return FALSE; } /** @@ -83,10 +92,10 @@ function version_upgrade_check() { $version = get_version(); if ($version > $dbversion) { - return true; + return TRUE; } - return false; + return FALSE; } /** @@ -96,12 +105,18 @@ function version_upgrade_check() { function version_upgrade() { $dbversion = (int) datalist_get('version'); + // No version number? Oh snap...this is an upgrade from a clean installation < 1.7. + // Run all upgrades without error reporting and hope for the best. + // See http://trac.elgg.org/elgg/ticket/1432 for more. + $quiet = !$dbversion; + // Upgrade database - db_upgrade($dbversion); - system_message(elgg_echo('upgrade:db')); + if (db_upgrade($dbversion, '', $quiet)) { + system_message(elgg_echo('upgrade:db')); + } // Upgrade core - if (upgrade_code($dbversion)) { + if (upgrade_code($dbversion, $quiet)) { system_message(elgg_echo('upgrade:core')); } |