| @@ 120-138 (lines=19) @@ | ||
| 117 | * @Route("/api/{version}/content/articles/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
| 118 | * @Method("PATCH") |
|
| 119 | */ |
|
| 120 | public function updateAction(Request $request, $id) |
|
| 121 | { |
|
| 122 | $objectManager = $this->get('swp.object_manager.article'); |
|
| 123 | $article = $this->findOr404($id); |
|
| 124 | $originalArticleStatus = $article->getStatus(); |
|
| 125 | ||
| 126 | $form = $this->createForm(ArticleType::class, $article, ['method' => $request->getMethod()]); |
|
| 127 | ||
| 128 | $form->handleRequest($request); |
|
| 129 | if ($form->isValid()) { |
|
| 130 | $this->get('swp.service.article')->reactOnStatusChange($originalArticleStatus, $article); |
|
| 131 | $objectManager->flush(); |
|
| 132 | $objectManager->refresh($article); |
|
| 133 | ||
| 134 | return new SingleResourceResponse($article); |
|
| 135 | } |
|
| 136 | ||
| 137 | return new SingleResourceResponse($form, new ResponseContext(500)); |
|
| 138 | } |
|
| 139 | ||
| 140 | private function findOr404($id) |
|
| 141 | { |
|
| @@ 115-133 (lines=19) @@ | ||
| 112 | * @Route("/api/{version}/organization/articles/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_core_update_organization_articles", requirements={"id"="\d+"}) |
|
| 113 | * @Method("PATCH") |
|
| 114 | */ |
|
| 115 | public function updateArticleAction(Request $request, int $id) |
|
| 116 | { |
|
| 117 | $objectManager = $this->get('swp.object_manager.article'); |
|
| 118 | $article = $this->getOrganizationArticle($id); |
|
| 119 | $originalArticleStatus = $article->getStatus(); |
|
| 120 | ||
| 121 | $form = $this->createForm(ArticleType::class, $article, ['method' => $request->getMethod()]); |
|
| 122 | ||
| 123 | $form->handleRequest($request); |
|
| 124 | if ($form->isValid()) { |
|
| 125 | $this->get('swp.service.article')->reactOnStatusChange($originalArticleStatus, $article); |
|
| 126 | $objectManager->flush(); |
|
| 127 | $objectManager->refresh($article); |
|
| 128 | ||
| 129 | return new SingleResourceResponse($article); |
|
| 130 | } |
|
| 131 | ||
| 132 | return new SingleResourceResponse($form, new ResponseContext(500)); |
|
| 133 | } |
|
| 134 | ||
| 135 | /** |
|
| 136 | * Show single tenant article. |
|