1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Webcook common bundle. |
5
|
|
|
* |
6
|
|
|
* See LICENSE file in the root of the bundle. Webcook |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Webcook\Cms\CoreBundle\Controller; |
10
|
|
|
|
11
|
|
|
use Webcook\Cms\CoreBundle\Base\BaseRestController; |
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
13
|
|
|
use Webcook\Cms\CoreBundle\Entity\Page; |
14
|
|
|
use Webcook\Cms\CoreBundle\Entity\PageSection; |
15
|
|
|
use Webcook\Cms\CoreBundle\Form\Type\PageType; |
16
|
|
|
use Webcook\Cms\CoreBundle\Form\Type\PageSectionType; |
17
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
18
|
|
|
use Webcook\Cms\SecurityBundle\Authorization\Voter\WebcookCmsVoter; |
19
|
|
|
use FOS\RestBundle\Controller\Annotations\Get; |
20
|
|
|
use FOS\RestBundle\Controller\Annotations\Post; |
21
|
|
|
use FOS\RestBundle\Controller\Annotations\Put; |
22
|
|
|
use FOS\RestBundle\Controller\Annotations\Delete; |
23
|
|
|
use Doctrine\DBAL\LockMode; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Page controller. |
27
|
|
|
*/ |
28
|
|
|
class PageController extends BaseRestController |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Update Page. |
32
|
|
|
* |
33
|
|
|
* @param int $id Id of the desired Page. |
34
|
|
|
* |
35
|
|
|
* @ApiDoc( |
36
|
|
|
* description="Update order of page section.", |
37
|
|
|
* input="Webcook\Cms\CoreBundle\Form\Type\PageSectionType" |
38
|
|
|
* ) |
39
|
|
|
* @Put("/page-section/order/{id}", options={"i18n"=false}) |
40
|
|
|
*/ |
41
|
|
|
public function putPageSectionOrderAction($id) |
42
|
|
|
{ |
43
|
|
|
$this->checkPermission(WebcookCmsVoter::ACTION_EDIT); |
44
|
|
|
|
45
|
|
|
$pageSection = $this->getEntityManager()->getRepository('Webcook\Cms\CoreBundle\Entity\PageSection')->find($id); |
46
|
|
|
|
47
|
|
|
if (!is_null($pageSection)) { |
48
|
|
|
$form = $this->createForm(PageSectionType::class); |
49
|
|
|
$form = $this->formSubmit($form, 'PUT'); |
50
|
|
|
if ($form->isValid()) { |
51
|
|
|
$data = $form->getData(); |
52
|
|
|
$pageSection->setOrder($data['order']); |
53
|
|
|
$this->getEntityManager()->flush(); |
54
|
|
|
|
55
|
|
|
$statusCode = 204; |
56
|
|
|
$message = 'Page section has been updated.'; |
57
|
|
|
} else { |
58
|
|
|
$statusCode = 400; |
59
|
|
|
$message = 'Given data are not valid.'; |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
|
|
$statusCode = 404; |
63
|
|
|
$message = 'Page section not found.'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$view = $this->getViewWithMessage(null, $statusCode, $message); |
|
|
|
|
67
|
|
|
|
68
|
|
|
return $this->handleView($view); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get Page by id. |
73
|
|
|
* |
74
|
|
|
* @param int $id [description] |
75
|
|
|
* |
76
|
|
|
* @return Page |
77
|
|
|
* |
78
|
|
|
* @throws NotFoundHttpException If Page doesn't exist |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
private function getPageById($id, $expectedVersion = null) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
if ($expectedVersion) { |
83
|
|
|
$page = $this->getEntityManager()->getRepository('Webcook\Cms\CoreBundle\Entity\Page')->find($id, LockMode::OPTIMISTIC, $expectedVersion); |
|
|
|
|
84
|
|
|
} else { |
85
|
|
|
$page = $this->getEntityManager()->getRepository('Webcook\Cms\CoreBundle\Entity\Page')->find($id); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (!$page instanceof Page) { |
89
|
|
|
throw new NotFoundHttpException('Page not found.'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->saveLockVersion($page); |
93
|
|
|
|
94
|
|
|
return $page; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: