From dd3733f75e1b6df742fb6413b38b977b85d8115c Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 26 Mar 2016 02:48:39 +0300 Subject: [PATCH] PostFactory more informative log and bugfix for null arguments with array typehint. --- .../Service/Factory/Blogs/PostFactory.php | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/PostFactory.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/PostFactory.php index 152a6be..6a9a048 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/PostFactory.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/PostFactory.php @@ -92,7 +92,13 @@ class PostFactory $post = $this->createFromDTO($postData); $posts[] = $post; } 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); } - $user = $this->userFactory->createFromDTO($postData->getPost()->getAuthor()); + try { + $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()))) { // Creating new post @@ -145,10 +156,26 @@ class PostFactory ->setPrivate($postData->getPost()->getPrivate()) ; - $this->updatePostTags($post, $postData->getPost()->getTags()); - $this->updatePostFiles($post, $postData->getPost()->getFiles()); + try { + $this->updatePostTags($post, $postData->getPost()->getTags() ?: []); + } catch (\Exception $e) { + $this->log->error('Error while updating post tags'); + throw $e; + } - $this->em->flush($post); + 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); + } catch (\Exception $e) { + $this->log->error('Error while flushing post entity'); + throw $e; + } return $post; }