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; } }
function rollback($strict = true) { if ($this->txFp === false) { if ($strict) { throw new LogicException('transaction is not active'); } return false; } if ($this->autocommitToRepo) { try { git::reset($this->file); } catch (Exception $y) { } } return $this->txEnd(); }