/** * 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; }
static function perform($from, $to) { $from = gb::version_parse($from); $to = gb::version_parse($to); $froms = gb::version_format($from); $tos = gb::version_format($to); if ($from === $to) { return null; } $is_upgrade = $from < $to; $stages = self::build_stages($from, $to); gb::log('%s gitblog %s -> %s in %d stages', $is_upgrade ? 'upgrading' : 'downgrading', $froms, $tos, count($stages)); # don't break on client abort ignore_user_abort(true); foreach ($stages as $v => $stagefunc) { $prevvs = gb::version_format($v > 0 ? $v - 1 : $v); gb::log('%s -> %s (%s)', $prevvs, gb::version_format($v), $stagefunc[1], $v); # write prev version to site.json so next run will take off where we crashed, if we crash. $orig_v = gb::$version; gb::$version = $prevvs; gb_maint::sync_site_state(); gb::$version = $orig_v; $stages[$v] = call_user_func($stagefunc, $from, $to); } gb_maint::sync_site_state(); return $stages; }