Skip to content

Commit

Permalink
Adds dual-write to comment service
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobemerick committed Jun 3, 2016
1 parent e8fad32 commit 6e5f86b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions module/form/CommentSubmitModule.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function activate()
$comment_id = $this->save_comment();

$comment_meta_id = $this->save_comment_meta($commenter_id, $comment_id, $page_id);
$comment_service_id = $this->save_to_comment_service(Request::getPost());

$this->send_notifications($page_id);
$this->redirect_to_comment($comment_meta_id);
Expand Down Expand Up @@ -200,4 +201,41 @@ private function redirect_to_comment($comment_id)
exit;
}

private function save_to_comment_service(array $data)
{
$path = $_SERVER['REQUEST_URI'];
$path = explode('/', $path);
$path = array_filter($path);
$path = array_slice($path, 0, 2);
$path = implode('/', $path);

$body = [
'commenter' => [
'name' => $data['name'],
'email' => $data['email'],
'website' => $data['website'],
],
'body' => $data['comment'],
'should_notify' => (isset($data['notify']) && $data['notify'] == 'check'),
'should_display' => true,
'domain' => (URLDecode::getSite() == 'blog' ? 'blog.jacobemerick.com' : 'waterfallsofthekeweenaw.com'),
'path' => $path,
'url' => $this->full_path,
'thread' => 'comments',
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'referrer' => $_SERVER['HTTP_REFERER'],
];

global $config;
$configuration = new Swagger\Client\Configuration();
$configuration->setUsername($config->comments->user);
$configuration->setPassword($config->comments->password);
$configuration->addDefaultHeader('Content-Type', 'application/json');
$configuration->setHost($config->comments->host);
$configuration->setCurlTimeout($config->comments->timeout);

$client = new Swagger\Client\ApiClient($configuration);
$response = $client->callApi('/comments', 'POST', '', $body, '');
}
}

0 comments on commit 6e5f86b

Please sign in to comment.