/** * Rebuild caches, indexes, etc. */ static function rebuild($forceFullRebuild = false) { gb::log(LOG_NOTICE, 'rebuilding cache' . ($forceFullRebuild ? ' (forcing full rebuild)' : '')); $time_started = microtime(1); $failures = array(); # Load rebuild plugins gb::load_plugins('rebuild'); # Load rebuilders if needed if (empty(self::$rebuilders)) { self::loadRebuilders(); } # Create rebuilder instances $rebuilders = array(); foreach (self::$rebuilders as $cls) { $rebuilders[] = new $cls($forceFullRebuild); } # Load rebuild plugins (2nd offer) gb::load_plugins('rebuild'); # Query ls-tree $ls = rtrim(git::exec('ls-files --stage')); if ($ls) { # Iterate objects $ls = explode("\n", $ls); foreach ($ls as $line) { try { # <mode> SP <object> SP <stage no> TAB <name> if (!$line) { continue; } $line = explode(' ', $line, 3); $id = $line[1]; $name = gb_normalize_git_name(substr($line[2], strpos($line[2], "\t") + 1)); foreach ($rebuilders as $rebuilder) { $rebuilder->onObject($name, $id); } } catch (RuntimeException $e) { gb::log(LOG_ERR, 'failed to rebuild object %s %s: %s', var_export($name, 1), $e->getMessage(), $e->getTraceAsString()); $failures[] = array($rebuilder, $name); } } } # Let rebuilders finalize foreach ($rebuilders as $rebuilder) { try { $rebuilder->finalize(); } catch (RuntimeException $e) { gb::log(LOG_ERR, 'rebuilder %s (0x%x) failed to finalize: %s', get_class($rebuilder), spl_object_hash($rebuilder), GBException::format($e, true, false, null, 0)); $failures[] = array($rebuilder, null); } } gb::log(LOG_NOTICE, 'cache updated -- time spent: %s', gb_format_duration(microtime(1) - $time_started)); return $failures; }
foreach ($state_fields as $k => $discard) { if ($k === 'body') { $modified_state[$k] = $post->rawBody(); } else { $v = $post->{$k}; if ($v instanceof GBDateTime) { $v = strval($v); } $modified_state[$k] = $v; } } } # commit? if ($input['commit']) { git::add($post->name); git::commit(($created ? 'Created' : 'Updated') . ' post ' . r($post->title), gb::$authorized, $post->name); } # build response entity $rsp = array('name' => $post->name, 'version' => $post->id, 'exists' => $post->exists(), 'isTracked' => $post->isTracked(), 'isDirty' => $post->isDirty(), 'state' => $modified_state); # status $status = '200 OK'; if ($created) { $status = '201 Created'; } # send JSON response gb_admin::json_rsp($rsp, $status); gb::log('saved post %s', $post->name); } catch (Exception $e) { gb::log('failed to save post: %s', GBException::format($e, true, false, null, 0)); gb_admin::json_rsp($e->getMessage(), '400 Bad Request'); }
function gb_exception_handler($e) { if (ini_get('html_errors')) { if (headers_sent()) { $msg = GBException::formatHTMLBlock($e); } else { $msg = GBException::formatHTMLDocument($e); } } else { $msg = GBException::format($e, true, false, null, 0); } exit($msg); }