|
@@ 212-215 (lines=4) @@
|
| 209 |
|
public function generatePaperHiveDocument($dir, $bookID) { |
| 210 |
|
// Try to get the document |
| 211 |
|
$paperHiveObjectString = $this->fetchDocument($bookID); |
| 212 |
|
if ($paperHiveObjectString === false) { |
| 213 |
|
$message = (string)$this->l->t('Problem connecting to PaperHive.'); |
| 214 |
|
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
| 215 |
|
} |
| 216 |
|
$paperHiveObject = json_decode($paperHiveObjectString, true); |
| 217 |
|
|
| 218 |
|
// Check if correct response has been returned |
|
@@ 219-222 (lines=4) @@
|
| 216 |
|
$paperHiveObject = json_decode($paperHiveObjectString, true); |
| 217 |
|
|
| 218 |
|
// Check if correct response has been returned |
| 219 |
|
if (json_last_error() != JSON_ERROR_NONE) { |
| 220 |
|
$message = (string)$this->l->t('Received wrong response from PaperHive.'); |
| 221 |
|
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
// Check if document is found |
| 225 |
|
if (!(isset($paperHiveObject['metadata']) && isset($paperHiveObject['metadata']['title']))) { |
|
@@ 233-236 (lines=4) @@
|
| 230 |
|
// Try fetching discussions |
| 231 |
|
$paperHiveDiscussionsString = $this->fetchDiscussions($bookID); |
| 232 |
|
$paperHiveDiscussions = json_decode($paperHiveDiscussionsString, true); |
| 233 |
|
if ($paperHiveDiscussionsString === false || json_last_error() != JSON_ERROR_NONE) { |
| 234 |
|
$message = (string)$this->l->t('Problem connecting to PaperHive to fetch discussions.'); |
| 235 |
|
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
| 236 |
|
} |
| 237 |
|
$discussionCount = -1; |
| 238 |
|
if (json_last_error() === JSON_ERROR_NONE && isset($paperHiveDiscussions['discussions'])) { |
| 239 |
|
$discussionCount = count($paperHiveDiscussions['discussions']); |