PostFactory more informative log and bugfix for null arguments with array typehint.

This commit is contained in:
Alexey Skobkin 2016-03-26 02:48:39 +03:00
parent b5007fceec
commit dd3733f75e

View file

@ -92,7 +92,13 @@ class PostFactory
$post = $this->createFromDTO($postData); $post = $this->createFromDTO($postData);
$posts[] = $post; $posts[] = $post;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->log->error('Error while processing post DTO', ['post_id' => $postData->getPost()->getId()]); $this->log->error('Error while processing post DTO', [
'post_id' => $postData->getPost()->getId(),
'exception' => get_class($e),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
]);
} }
} }
@ -127,7 +133,12 @@ class PostFactory
throw new InvalidPostDataException('Post author does not contain id', $postData); throw new InvalidPostDataException('Post author does not contain id', $postData);
} }
try {
$user = $this->userFactory->createFromDTO($postData->getPost()->getAuthor()); $user = $this->userFactory->createFromDTO($postData->getPost()->getAuthor());
} catch (\Exception $e) {
$this->log->error('Error while creating user from DTO');
throw $e;
}
if (null === ($post = $this->postRepository->find($postData->getPost()->getId()))) { if (null === ($post = $this->postRepository->find($postData->getPost()->getId()))) {
// Creating new post // Creating new post
@ -145,10 +156,26 @@ class PostFactory
->setPrivate($postData->getPost()->getPrivate()) ->setPrivate($postData->getPost()->getPrivate())
; ;
$this->updatePostTags($post, $postData->getPost()->getTags()); try {
$this->updatePostFiles($post, $postData->getPost()->getFiles()); $this->updatePostTags($post, $postData->getPost()->getTags() ?: []);
} catch (\Exception $e) {
$this->log->error('Error while updating post tags');
throw $e;
}
try {
$this->updatePostFiles($post, $postData->getPost()->getFiles() ?: []);
} catch (\Exception $e) {
$this->log->error('Error while updating post files');
throw $e;
}
try {
$this->em->flush($post); $this->em->flush($post);
} catch (\Exception $e) {
$this->log->error('Error while flushing post entity');
throw $e;
}
return $post; return $post;
} }