<div class="breaker"></div> <address> Gitblog/<?php echo gb::$version; ?> (Processing time: <?php echo gb_format_duration(microtime(true) - $gb_time_started); ?> , Git queries: <?php echo git::$query_count; ?> ) </address> </body> </html>
/** * 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; }
function importChannel(DOMNode $channel, $commit) { $channel_name = $channel->getElementsByTagName('title')->item(0)->nodeValue; $this->report('Importing channel "' . h($channel_name) . '"'); $fallbackTZOffset = $this->deduceChannelTimezoneOffset($channel); $count_posts = 0; $count_pages = 0; $count_attachments = 0; $timer = microtime(1); git::reset(); # rollback any previously prepared commit try { foreach ($channel->getElementsByTagName('item') as $item) { if ($item->nodeType !== XML_ELEMENT_NODE) { continue; } $obj = $this->importItem($item, $fallbackTZOffset); if (!$obj) { continue; } if ($obj instanceof GBExposedContent) { $this->postProcessExposedContent($obj); $this->report('Importing ' . ($obj instanceof WPPost ? 'post' : 'page') . ' ' . h($obj->name) . ' "' . h($obj->title) . '" by ' . h($obj->author->name) . ' published ' . $obj->published); if ($this->writeExposedContent($obj)) { if ($obj instanceof WPPost) { $count_posts++; } else { $count_pages++; } } } elseif ($obj instanceof WPAttachment) { $this->postProcessAttachment($obj); $this->report('Importing attachment ' . h($obj->name) . ' (' . h($obj->wpurl) . ')'); if ($this->writeAttachment($obj)) { $count_attachments++; } } if ($this->debug) { $this->dump($obj); } } $timer = microtime(1) - $timer; $count = $count_posts + $count_pages + $count_attachments; $this->importedObjectsCount += $count; $message = 'Imported ' . counted($count, 'object', 'objects', 'zero', 'one') . ' (' . counted($count_posts, 'post', 'posts', 'zero', 'one') . ', ' . counted($count_pages, 'page', 'pages', 'zero', 'one') . ' and ' . counted($count_attachments, 'attachment', 'attachments', 'zero', 'one') . ')'; $this->report($message . ' from channel "' . h($channel_name) . '"' . ' in ' . gb_format_duration($timer)); if ($commit) { $this->report('Creating commit...'); try { git::commit($message . ' from Wordpress blog ' . $channel_name, GBUser::findAdmin()->gitAuthor()); $this->report('Committed to git repository'); } catch (GitError $e) { if (strpos($e->getMessage(), 'nothing added to commit') !== false) { $this->report('Nothing committed because no changes where done'); } else { throw $e; } } } } catch (Exception $e) { git::reset(); # rollback prepared commit throw $e; } }