public function finishSave()
{
if (count($this->jsopBody) > 0) {
$request = $this->getRequest(Request::POST, "/");
$body = '';
if (count($this->jsopBody) > 1 || !isset($this->jsopBody[':diff'])) {
$mime_boundary = md5(mt_rand());
//do the diffs at last
$diff = null;
if (isset($this->jsopBody[':diff'])) {
$diff = $this->jsopBody[':diff'];
unset($this->jsopBody[':diff']);
}
foreach ($this->jsopBody as $n => $v) {
$body .= $this->getMimePart($n, $v, $mime_boundary);
}
if ($diff) {
$body .= $this->getMimePart(":diff", $diff, $mime_boundary);
}
$body .= "--" . $mime_boundary . "--" . "\r\n\r\n";
// finish with two eol's!!
$request->setContentType("multipart/form-data; boundary={$mime_boundary}");
} else {
$body = urlencode(":diff") . "=" . urlencode($this->jsopBody[':diff']);
$request->setContentType("application/x-www-form-urlencoded; charset=utf-8");
}
try {
$request->setBody($body);
$request->execute();
} catch (HTTPErrorException $e) {
// TODO: can we throw any other more specific errors here?
throw new RepositoryException('Something went wrong while saving nodes', $e->getCode(), $e);
}
}
$this->jsopBody = array();
}