private function parsePostList($postList) { if (!$postList) { return null; } $ret = array(); foreach (explode('|', $postList) as $id) { try { $ret[] = Post::newFromId(UUID::fromHex($id)); } catch (\Exception $ex) { $this->dieUsage("There is no post with ID {$id}", 'nosuchpostid'); } } return $ret; }
private function doImport(array $json) { global $wgTriggerFlowThreadHooks; $wgTriggerFlowThreadHooks = false; $output = $this->getOutput(); foreach ($json as $articles) { $title = \Title::newFromText($articles->title); $count = count($articles->posts); $skipped = 0; // Skip non-existent title if ($title === null || !$title->exists()) { $output->addWikiMsg('flowthreadimport-failed', $articles->title, $count); continue; } $titleId = $title->getArticleID(); foreach ($articles->posts as $postJson) { $data = array('id' => UUID::fromHex($postJson->id), 'pageid' => $titleId, 'userid' => $postJson->userid, 'username' => $postJson->username, 'text' => $postJson->text, 'parentid' => $postJson->parentid ? UUID::fromHex($postJson->parentid) : null, 'status' => $postJson->status, 'like' => 0, 'report' => 0); $postObject = new Post($data); try { $postObject->post(); } catch (\Exception $ex) { $count--; $skipped++; } } if ($count) { $logEntry = new \ManualLogEntry('comments', 'import'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($title); $logEntry->setParameters(array('4::count' => $count)); $logId = $logEntry->insert(); $logEntry->publish($logId, 'udp'); $output->addWikiMsg('flowthreadimport-success', $articles->title, $count); } if ($skipped) { $output->addWikiMsg('flowthreadimport-skipped', $articles->title, $skipped); } } }