-function check_config(&$a) {
-
- $build = get_config('system','build');
- if(! x($build))
- $build = set_config('system','build',DB_UPDATE_VERSION);
-
- $url = get_config('system','url');
-
- // if the url isn't set or the stored url is radically different
- // than the currently visited url, store the current value accordingly.
- // "Radically different" ignores common variations such as http vs https
- // and www.example.com vs example.com.
-
- if((! x($url)) || (! link_compare($url,$a->get_baseurl())))
- $url = set_config('system','url',$a->get_baseurl());
-
- if($build != DB_UPDATE_VERSION) {
- $stored = intval($build);
- $current = intval(DB_UPDATE_VERSION);
- if(($stored < $current) && file_exists('update.php')) {
-
- load_config('database');
-
- // We're reporting a different version than what is currently installed.
- // Run any existing update scripts to bring the database up to current.
-
- require_once('update.php');
-
- // make sure that boot.php and update.php are the same release, we might be
- // updating right this very second and the correct version of the update.php
- // file may not be here yet. This can happen on a very busy site.
+ function check_config(&$a) {
+
+ $build = get_config('system','build');
+ if(! x($build))
+ $build = set_config('system','build',DB_UPDATE_VERSION);
+
+ $url = get_config('system','url');
+
+ // if the url isn't set or the stored url is radically different
+ // than the currently visited url, store the current value accordingly.
+ // "Radically different" ignores common variations such as http vs https
+ // and www.example.com vs example.com.
+
+ if((! x($url)) || (! link_compare($url,$a->get_baseurl())))
+ $url = set_config('system','url',$a->get_baseurl());
+
+ if($build != DB_UPDATE_VERSION) {
+ $stored = intval($build);
+ $current = intval(DB_UPDATE_VERSION);
+ if(($stored < $current) && file_exists('update.php')) {
+
+ load_config('database');
+
+ // We're reporting a different version than what is currently installed.
+ // Run any existing update scripts to bring the database up to current.
+
+ require_once('update.php');
+
+ // make sure that boot.php and update.php are the same release, we might be
+ // updating right this very second and the correct version of the update.php
+ // file may not be here yet. This can happen on a very busy site.
+
+ if(DB_UPDATE_VERSION == UPDATE_VERSION) {
+
+ for($x = $stored; $x < $current; $x ++) {
+ if(function_exists('update_' . $x)) {
+
+ // There could be a lot of processes running or about to run.
+ // We want exactly one process to run the update command.
+ // So store the fact that we're taking responsibility
+ // after first checking to see if somebody else already has.
+
+ // If the update fails or times-out completely you may need to
+ // delete the config entry to try again.
+
+ if(get_config('database','update_' . $x))
+ break;
+ set_config('database','update_' . $x, '1');
+
+ // call the specific update
+
+// global $db;
+// $db->excep(TRUE);
+// try {
+// $db->beginTransaction();
+ $func = 'update_' . $x;
+ $func($a);
+// $db->commit();
+// } catch(Exception $ex) {
+// $db->rollback();
+// //send the administrator an e-mail
+// $email_tpl = get_intltext_template("update_fail_eml.tpl");
+// $email_tpl = replace_macros($email_tpl, array(
+// '$sitename' => $a->config['sitename'],
+// '$siteurl' => $a->get_baseurl(),
+// '$update' => $x,
+// '$error' => $ex->getMessage()));
+// $subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
+
+// mail($a->config['admin_email'], $subject, $text,
+// 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+// . 'Content-type: text/plain; charset=UTF-8' . "\n"
+// . 'Content-transfer-encoding: 8bit' );
+// //try the logger
+// logger('update failed: '.$ex->getMessage().EOL);
+// }
+// $db->excep(FALSE);
+ }
+ }
+ set_config('system','build', DB_UPDATE_VERSION);
+ }
+ }
+ }