static function upgrade($fromVersion) { self::sync_site_state(); # this can potentially take a very long time set_time_limit(120); $stages = gb_upgrade::perform($fromVersion, gb::$version); gb::log('triggering rebuild as an effect of the upgrade to %s', gb::$version); $failures = GBRebuilder::rebuild($stages ? true : false); gb::log('gitblog is now version %s', gb::$version); if ($failures) { gb::log(LOG_WARNING, 'rebuilding failed with %d failures', count($failures)); return false; } return true; }
/** * Verify integrity of the site, automatically taking any actions to restore * it if broken. * * Return values: * 0 Nothing done (everything is probably OK). * -1 Error (the error has been logged through trigger_error). * 1 gitblog cache was updated. * 2 gitdir is missing and need to be created (git init). * 3 upgrade performed */ static function verify_integrity() { $r = 0; if (!is_dir(gb::$site_dir . '/.git/info/gitblog')) { if (!is_dir(gb::$site_dir . '/.git')) { # 2: no repo/not initialized return 2; } # 1: gitblog cache updated gb_maint::sync_site_state(); GBRebuilder::rebuild(true); return 1; } # load site.json $r = self::load_site_state(); # check site state if ($r === false || !isset(gb::$site_state['url']) || !gb::$site_state['url'] || gb::$site_state['url'] !== gb::$site_url && strpos(gb::$site_url, '://localhost') === false && strpos(gb::$site_url, '://127.0.0.1') === false) { return gb_maint::sync_site_state() === false ? -1 : 0; } elseif (gb::$site_state['version'] !== gb::$version) { return gb_maint::upgrade(gb::$site_state['version']) ? 0 : -1; } elseif (gb::$site_state['posts_pagesize'] !== gb::$posts_pagesize) { gb_maint::sync_site_state(); GBRebuilder::rebuild(true); return 1; } return 0; }
<?php require '../gitblog.php'; ini_set('html_errors', '0'); gb::verify(); if (!isset($_SERVER['HTTP_X_GB_SHARED_SECRET']) || $_SERVER['HTTP_X_GB_SHARED_SECRET'] !== gb::$secret) { header('HTTP/1.1 401 Unauthorized'); exit('error: 401 Unauthorized'); } try { GBRebuilder::rebuild(isset($_REQUEST['force-full-rebuild'])); } catch (Exception $e) { echo 'error:'; throw $e; }
require_once '../_base.php'; function gb_log_html($priority, $msg) { echo '<p class="logmsg ' . ($priority === LOG_WARNING ? 'warning' : ($priority < LOG_WARNING ? 'error' : '')) . '">' . h($msg) . '</p>'; gb_flush(); } gb::$log_cb = 'gb_log_html'; gb::authenticate(); gb::$title[] = 'Rebuild'; include '../_header.php'; ?> <style type="text/css"> p.logmsg { margin:2px 0; font-size:9px; font-family:monospace; } p.logmsg.error, p.logmsg.warning { padding:1em; font-size:13px; } p.logmsg.error { background:#faa; white-space:pre; } p.logmsg.warning { background:#ff9; } </style> <div id="content" class="<?php echo gb_admin::$current_domid; ?> margins"> <h2>Rebuilding</h2> <?php GBRebuilder::rebuild(isset($_GET['force-full-rebuild'])); ?> <p> <input type="button" value="Force full rebuild" onclick="document.location.href='?force-full-rebuild'" /> </p> </div> <?php include '../_footer.php';