@@ -35,102 +35,102 @@ |
||
35 | 35 | use FOS\RestBundle\Controller\Annotations\Route; |
36 | 36 | |
37 | 37 | class RelatedArticleOrganizationController extends Controller { |
38 | - private EventDispatcherInterface $eventDispatcher; |
|
39 | - private DataTransformerInterface $dataTransformer; |
|
40 | - private CachedTenantContextInterface $cachedTenantContext; |
|
41 | - private PackageRepositoryInterface $packageRepository; |
|
42 | - private ArticleRepositoryInterface $articleRepository; |
|
43 | - private TenantRepositoryInterface $tenantRepository; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param EventDispatcherInterface $eventDispatcher |
|
47 | - * @param DataTransformerInterface $dataTransformer |
|
48 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | - * @param PackageRepositoryInterface $packageRepository |
|
50 | - * @param ArticleRepositoryInterface $articleRepository |
|
51 | - * @param TenantRepositoryInterface $tenantRepository |
|
52 | - */ |
|
53 | - public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | - DataTransformerInterface $dataTransformer, |
|
55 | - CachedTenantContextInterface $cachedTenantContext, |
|
56 | - PackageRepositoryInterface $packageRepository, |
|
57 | - ArticleRepositoryInterface $articleRepository, |
|
58 | - TenantRepositoryInterface $tenantRepository) { |
|
38 | + private EventDispatcherInterface $eventDispatcher; |
|
39 | + private DataTransformerInterface $dataTransformer; |
|
40 | + private CachedTenantContextInterface $cachedTenantContext; |
|
41 | + private PackageRepositoryInterface $packageRepository; |
|
42 | + private ArticleRepositoryInterface $articleRepository; |
|
43 | + private TenantRepositoryInterface $tenantRepository; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param EventDispatcherInterface $eventDispatcher |
|
47 | + * @param DataTransformerInterface $dataTransformer |
|
48 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | + * @param PackageRepositoryInterface $packageRepository |
|
50 | + * @param ArticleRepositoryInterface $articleRepository |
|
51 | + * @param TenantRepositoryInterface $tenantRepository |
|
52 | + */ |
|
53 | + public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | + DataTransformerInterface $dataTransformer, |
|
55 | + CachedTenantContextInterface $cachedTenantContext, |
|
56 | + PackageRepositoryInterface $packageRepository, |
|
57 | + ArticleRepositoryInterface $articleRepository, |
|
58 | + TenantRepositoryInterface $tenantRepository) { |
|
59 | 59 | $this->eventDispatcher = $eventDispatcher; |
60 | 60 | $this->dataTransformer = $dataTransformer; |
61 | 61 | $this->cachedTenantContext = $cachedTenantContext; |
62 | 62 | $this->packageRepository = $packageRepository; |
63 | 63 | $this->articleRepository = $articleRepository; |
64 | 64 | $this->tenantRepository = $tenantRepository; |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | - */ |
|
71 | - public function postAction(Request $request) { |
|
68 | + /** |
|
69 | + * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | + */ |
|
71 | + public function postAction(Request $request) { |
|
72 | 72 | $content = $request->getContent(); |
73 | 73 | $package = $this->dataTransformer->transform($content); |
74 | 74 | $relatedArticlesList = $this->getRelated($package); |
75 | 75 | |
76 | 76 | return new SingleResourceResponse($relatedArticlesList); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | - */ |
|
82 | - public function getRelatedAction(string $id) { |
|
79 | + /** |
|
80 | + * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | + */ |
|
82 | + public function getRelatedAction(string $id) { |
|
83 | 83 | $package = $this->findOr404((int)$id); |
84 | 84 | |
85 | 85 | $relatedArticlesList = $this->getRelated($package); |
86 | 86 | |
87 | 87 | return new SingleResourceResponse($relatedArticlesList); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - private function getRelated(PackageInterface $package): RelatedArticleList { |
|
90 | + private function getRelated(PackageInterface $package): RelatedArticleList { |
|
91 | 91 | $relatedItemsGroups = $package->getItems()->filter(static function ($group) { |
92 | - return ItemInterface::TYPE_TEXT === $group->getType(); |
|
92 | + return ItemInterface::TYPE_TEXT === $group->getType(); |
|
93 | 93 | }); |
94 | 94 | |
95 | 95 | $relatedArticlesList = new RelatedArticleList(); |
96 | 96 | |
97 | 97 | if (null === $package || (null !== $package && 0 === \count($relatedItemsGroups))) { |
98 | - return $relatedArticlesList; |
|
98 | + return $relatedArticlesList; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
102 | 102 | $articleRepository = $this->articleRepository; |
103 | 103 | |
104 | 104 | foreach ($relatedItemsGroups as $item) { |
105 | - if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
105 | + if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
106 | 106 | continue; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - $tenants = []; |
|
110 | - foreach ($existingArticles as $existingArticle) { |
|
109 | + $tenants = []; |
|
110 | + foreach ($existingArticles as $existingArticle) { |
|
111 | 111 | $tenantCode = $existingArticle->getTenantCode(); |
112 | 112 | $tenant = $this->tenantRepository->findOneByCode($tenantCode); |
113 | 113 | |
114 | 114 | $tenants[] = $tenant; |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | - $relatedArticleListItem->setTenants($tenants); |
|
119 | - $relatedArticleListItem->setTitle($item->getHeadline()); |
|
117 | + $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | + $relatedArticleListItem->setTenants($tenants); |
|
119 | + $relatedArticleListItem->setTitle($item->getHeadline()); |
|
120 | 120 | |
121 | - $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
121 | + $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $relatedArticlesList; |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - private function findOr404(int $id): PackageInterface { |
|
127 | + private function findOr404(int $id): PackageInterface { |
|
128 | 128 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
129 | 129 | $tenantContext = $this->cachedTenantContext; |
130 | 130 | if (null === $package = $this->packageRepository->findOneBy(['id' => $id, 'organization' => $tenantContext->getTenant()->getOrganization()])) { |
131 | - throw new NotFoundHttpException('Package was not found.'); |
|
131 | + throw new NotFoundHttpException('Package was not found.'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $package; |
135 | - } |
|
135 | + } |
|
136 | 136 | } |
@@ -37,75 +37,75 @@ |
||
37 | 37 | use FOS\RestBundle\Controller\Annotations\Route as FOSRoute; |
38 | 38 | |
39 | 39 | class SeoMediaController extends AbstractMediaController { |
40 | - private FactoryInterface $seoMetadataFactory; |
|
41 | - private ArticleProviderInterface $articleProvider; |
|
42 | - private EntityManagerInterface $seoObjectManager; |
|
43 | - private FormFactoryInterface $formFactory; |
|
44 | - |
|
45 | - public function __construct( |
|
46 | - FactoryInterface $seoMetadataFactory, |
|
47 | - ArticleProviderInterface $articleProvider, |
|
48 | - FormFactoryInterface $formFactory, |
|
49 | - EntityManagerInterface $seoObjectManager, |
|
50 | - MediaManagerInterface $seoMediaManager, |
|
51 | - CacheInterface $cacheProvider, |
|
52 | - FileProviderInterface $fileProvider, |
|
53 | - FileExtensionCheckerInterface $fileExtensionChecker |
|
54 | - ) { |
|
40 | + private FactoryInterface $seoMetadataFactory; |
|
41 | + private ArticleProviderInterface $articleProvider; |
|
42 | + private EntityManagerInterface $seoObjectManager; |
|
43 | + private FormFactoryInterface $formFactory; |
|
44 | + |
|
45 | + public function __construct( |
|
46 | + FactoryInterface $seoMetadataFactory, |
|
47 | + ArticleProviderInterface $articleProvider, |
|
48 | + FormFactoryInterface $formFactory, |
|
49 | + EntityManagerInterface $seoObjectManager, |
|
50 | + MediaManagerInterface $seoMediaManager, |
|
51 | + CacheInterface $cacheProvider, |
|
52 | + FileProviderInterface $fileProvider, |
|
53 | + FileExtensionCheckerInterface $fileExtensionChecker |
|
54 | + ) { |
|
55 | 55 | $this->seoMetadataFactory = $seoMetadataFactory; |
56 | 56 | $this->formFactory = $formFactory; |
57 | 57 | $this->articleProvider = $articleProvider; |
58 | 58 | $this->seoObjectManager = $seoObjectManager; |
59 | 59 | |
60 | 60 | parent::__construct($seoMediaManager, $cacheProvider, $fileProvider, $fileExtensionChecker); |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @Route("/seo/media/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_seo_media_get") |
|
65 | - */ |
|
66 | - public function getAction(string $mediaId, string $extension): Response { |
|
63 | + /** |
|
64 | + * @Route("/seo/media/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_seo_media_get") |
|
65 | + */ |
|
66 | + public function getAction(string $mediaId, string $extension): Response { |
|
67 | 67 | return $this->getMedia($mediaId, $extension); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @FOSRoute("/api/{version}/upload/seo_image/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_seo_image") |
|
72 | - */ |
|
73 | - public function uploadSeoImageAction(Request $request, string $id, |
|
74 | - SeoImageUploaderInterface $seoImageUploader): SingleResourceResponse { |
|
70 | + /** |
|
71 | + * @FOSRoute("/api/{version}/upload/seo_image/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_seo_image") |
|
72 | + */ |
|
73 | + public function uploadSeoImageAction(Request $request, string $id, |
|
74 | + SeoImageUploaderInterface $seoImageUploader): SingleResourceResponse { |
|
75 | 75 | $article = $this->findOr404($id); |
76 | 76 | $seoMetadata = $article->getSeoMetadata(); |
77 | 77 | |
78 | 78 | if (null === $seoMetadata) { |
79 | - $seoMetadata = $this->seoMetadataFactory->create(); |
|
79 | + $seoMetadata = $this->seoMetadataFactory->create(); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $form = $this->formFactory->createNamed('', SeoImageType::class, $seoMetadata); |
83 | 83 | $form->handleRequest($request); |
84 | 84 | |
85 | 85 | if ($form->isSubmitted() && $form->isValid()) { |
86 | - try { |
|
86 | + try { |
|
87 | 87 | $seoImageUploader->handleUpload($seoMetadata); |
88 | 88 | |
89 | 89 | if (null === $article->getSeoMetadata()) { |
90 | - $article->setSeoMetadata($seoMetadata); |
|
90 | + $article->setSeoMetadata($seoMetadata); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->seoObjectManager->flush(); |
94 | - } catch (\Exception $e) { |
|
94 | + } catch (\Exception $e) { |
|
95 | 95 | return new SingleResourceResponse(['message' => 'Could not upload an image.'], new ResponseContext(400)); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - return new SingleResourceResponse($seoMetadata, new ResponseContext(201)); |
|
98 | + return new SingleResourceResponse($seoMetadata, new ResponseContext(201)); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return new SingleResourceResponse($form, new ResponseContext(400)); |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - private function findOr404(string $id): ArticleInterface { |
|
104 | + private function findOr404(string $id): ArticleInterface { |
|
105 | 105 | if (null === $article = $this->articleProvider->getOneById($id)) { |
106 | - throw new NotFoundHttpException('Article was not found.'); |
|
106 | + throw new NotFoundHttpException('Article was not found.'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return $article; |
110 | - } |
|
110 | + } |
|
111 | 111 | } |
@@ -28,77 +28,77 @@ |
||
28 | 28 | use FOS\RestBundle\Controller\Annotations\Route; |
29 | 29 | |
30 | 30 | class WebhookController extends AbstractAPIController { |
31 | - private WebhookRepositoryInterface $webhookRepository; |
|
32 | - private FormFactoryInterface $formFactory; |
|
33 | - private FactoryInterface $webhookFactory; |
|
34 | - private EntityManagerInterface $entityManager; |
|
35 | - private EventDispatcherInterface $eventDispatcher; |
|
31 | + private WebhookRepositoryInterface $webhookRepository; |
|
32 | + private FormFactoryInterface $formFactory; |
|
33 | + private FactoryInterface $webhookFactory; |
|
34 | + private EntityManagerInterface $entityManager; |
|
35 | + private EventDispatcherInterface $eventDispatcher; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param WebhookRepositoryInterface $webhookRepository |
|
39 | - * @param FormFactoryInterface $formFactory |
|
40 | - * @param FactoryInterface $webhookFactory |
|
41 | - * @param EntityManagerInterface $entityManager |
|
42 | - * @param EventDispatcherInterface $eventDispatcher |
|
43 | - */ |
|
44 | - public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
45 | - FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
46 | - EventDispatcherInterface $eventDispatcher) { |
|
37 | + /** |
|
38 | + * @param WebhookRepositoryInterface $webhookRepository |
|
39 | + * @param FormFactoryInterface $formFactory |
|
40 | + * @param FactoryInterface $webhookFactory |
|
41 | + * @param EntityManagerInterface $entityManager |
|
42 | + * @param EventDispatcherInterface $eventDispatcher |
|
43 | + */ |
|
44 | + public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
45 | + FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
46 | + EventDispatcherInterface $eventDispatcher) { |
|
47 | 47 | $this->webhookRepository = $webhookRepository; |
48 | 48 | $this->formFactory = $formFactory; |
49 | 49 | $this->webhookFactory = $webhookFactory; |
50 | 50 | $this->entityManager = $entityManager; |
51 | 51 | $this->eventDispatcher = $eventDispatcher; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
57 | - */ |
|
58 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
55 | + /** |
|
56 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
57 | + */ |
|
58 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
59 | 59 | return $this->listWebhooks($this->eventDispatcher,$this->webhookRepository, $request); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
64 | - * |
|
65 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
66 | - */ |
|
67 | - public function getAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
62 | + /** |
|
63 | + * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
64 | + * |
|
65 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
66 | + */ |
|
67 | + public function getAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
68 | 68 | return $this->getSingleWebhook($webhook); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
73 | - */ |
|
74 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
71 | + /** |
|
72 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
73 | + */ |
|
74 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
75 | 75 | $ruleRepository = $this->webhookRepository; |
76 | 76 | $ruleFactory = $this->webhookFactory; |
77 | 77 | $formFactory = $this->formFactory; |
78 | 78 | |
79 | 79 | return $this->createWebhook($ruleRepository, $ruleFactory, $request, $formFactory); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
84 | - * |
|
85 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
86 | - */ |
|
87 | - public function deleteAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
82 | + /** |
|
83 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
84 | + * |
|
85 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
86 | + */ |
|
87 | + public function deleteAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
88 | 88 | $webhookRepository = $this->webhookRepository; |
89 | 89 | |
90 | 90 | return $this->deleteWebhook($webhookRepository, $webhook); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
95 | - * |
|
96 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
97 | - */ |
|
98 | - public function updateAction(Request $request, WebhookInterface $webhook): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
95 | + * |
|
96 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
97 | + */ |
|
98 | + public function updateAction(Request $request, WebhookInterface $webhook): SingleResourceResponseInterface { |
|
99 | 99 | $objectManager = $this->entityManager; |
100 | 100 | $formFactory = $this->formFactory; |
101 | 101 | |
102 | 102 | return $this->updateWebhook($objectManager, $request, $webhook, $formFactory); |
103 | - } |
|
103 | + } |
|
104 | 104 | } |
@@ -41,29 +41,29 @@ discard block |
||
41 | 41 | use FOS\RestBundle\Controller\Annotations\Route; |
42 | 42 | |
43 | 43 | class OrganizationRuleController extends AbstractController { |
44 | - private FormFactoryInterface $formFactory; |
|
45 | - private EventDispatcherInterface $eventDispatcher; |
|
46 | - private CachedTenantContextInterface $cachedTenantContext; |
|
47 | - private EntityManagerInterface $entityManager; |
|
48 | - private RuleRepositoryInterface $ruleRepository; |
|
49 | - private RulesMatcherInterface $rulesMatcher; |
|
50 | - private FactoryInterface $ruleFactory; |
|
51 | - private DataTransformerInterface $dataTransformer; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param FormFactoryInterface $formFactory |
|
55 | - * @param EventDispatcherInterface $eventDispatcher |
|
56 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
57 | - * @param EntityManagerInterface $entityManager |
|
58 | - * @param RuleRepositoryInterface $ruleRepository |
|
59 | - * @param RulesMatcherInterface $rulesMatcher |
|
60 | - * @param FactoryInterface $ruleFactory |
|
61 | - * @param DataTransformerInterface $dataTransformer |
|
62 | - */ |
|
63 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | - CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
65 | - RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
66 | - FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
44 | + private FormFactoryInterface $formFactory; |
|
45 | + private EventDispatcherInterface $eventDispatcher; |
|
46 | + private CachedTenantContextInterface $cachedTenantContext; |
|
47 | + private EntityManagerInterface $entityManager; |
|
48 | + private RuleRepositoryInterface $ruleRepository; |
|
49 | + private RulesMatcherInterface $rulesMatcher; |
|
50 | + private FactoryInterface $ruleFactory; |
|
51 | + private DataTransformerInterface $dataTransformer; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param FormFactoryInterface $formFactory |
|
55 | + * @param EventDispatcherInterface $eventDispatcher |
|
56 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
57 | + * @param EntityManagerInterface $entityManager |
|
58 | + * @param RuleRepositoryInterface $ruleRepository |
|
59 | + * @param RulesMatcherInterface $rulesMatcher |
|
60 | + * @param FactoryInterface $ruleFactory |
|
61 | + * @param DataTransformerInterface $dataTransformer |
|
62 | + */ |
|
63 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | + CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
65 | + RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
66 | + FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
67 | 67 | $this->formFactory = $formFactory; |
68 | 68 | $this->eventDispatcher = $eventDispatcher; |
69 | 69 | $this->cachedTenantContext = $cachedTenantContext; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | $this->rulesMatcher = $rulesMatcher; |
73 | 73 | $this->ruleFactory = $ruleFactory; |
74 | 74 | $this->dataTransformer = $dataTransformer; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
80 | - */ |
|
81 | - public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
78 | + /** |
|
79 | + * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
80 | + */ |
|
81 | + public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
82 | 82 | $content = $request->getContent(); |
83 | 83 | $dispatcher = $this->eventDispatcher; |
84 | 84 | $package = $this->dataTransformer->transform($content); |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | $rules = $this->rulesMatcher->getMatchedRules($package); |
88 | 88 | |
89 | 89 | return new SingleResourceResponse($rules); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
94 | - */ |
|
95 | - public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
92 | + /** |
|
93 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
94 | + */ |
|
95 | + public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
96 | 96 | $tenantContext = $this->cachedTenantContext; |
97 | 97 | |
98 | 98 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | ); |
110 | 110 | |
111 | 111 | return new ResourcesListResponse($rules); |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
116 | - */ |
|
117 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
114 | + /** |
|
115 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
116 | + */ |
|
117 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
118 | 118 | $ruleRepository = $this->getRuleRepository(); |
119 | 119 | |
120 | 120 | $rule = $this->ruleFactory->create(); |
@@ -122,54 +122,54 @@ discard block |
||
122 | 122 | $form->handleRequest($request); |
123 | 123 | |
124 | 124 | if ($form->isSubmitted() && $form->isValid()) { |
125 | - $ruleRepository->add($rule); |
|
126 | - $rule->setTenantCode(null); |
|
127 | - $ruleRepository->flush(); |
|
125 | + $ruleRepository->add($rule); |
|
126 | + $rule->setTenantCode(null); |
|
127 | + $ruleRepository->flush(); |
|
128 | 128 | |
129 | - return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
129 | + return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return new SingleResourceResponse($form, new ResponseContext(400)); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
137 | - */ |
|
138 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
135 | + /** |
|
136 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
137 | + */ |
|
138 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
139 | 139 | return new SingleResourceResponse($this->findOr404($id)); |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
144 | - */ |
|
145 | - public function updateRuleAction(Request $request, int $id) { |
|
142 | + /** |
|
143 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
144 | + */ |
|
145 | + public function updateRuleAction(Request $request, int $id) { |
|
146 | 146 | $objectManager = $this->entityManager; |
147 | 147 | $rule = $this->findOr404($id); |
148 | 148 | $form = $this->formFactory->createNamed('', RuleType::class, $rule, ['method' => $request->getMethod()]); |
149 | 149 | |
150 | 150 | $form->handleRequest($request); |
151 | 151 | if ($form->isSubmitted() && $form->isValid()) { |
152 | - $objectManager->flush(); |
|
153 | - $objectManager->refresh($rule); |
|
152 | + $objectManager->flush(); |
|
153 | + $objectManager->refresh($rule); |
|
154 | 154 | |
155 | - return new SingleResourceResponse($rule); |
|
155 | + return new SingleResourceResponse($rule); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return new SingleResourceResponse($form, new ResponseContext(500)); |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
163 | - */ |
|
164 | - public function deleteAction(int $id) { |
|
161 | + /** |
|
162 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
163 | + */ |
|
164 | + public function deleteAction(int $id) { |
|
165 | 165 | $rule = $this->findOr404($id); |
166 | 166 | $ruleRepository = $this->ruleRepository; |
167 | 167 | $ruleRepository->remove($rule); |
168 | 168 | |
169 | 169 | return new SingleResourceResponse(null, new ResponseContext(204)); |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - private function findOr404(int $id) { |
|
172 | + private function findOr404(int $id) { |
|
173 | 173 | $tenantContext = $this->cachedTenantContext; |
174 | 174 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
175 | 175 | |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | 'organization' => $tenantContext->getTenant()->getOrganization(), |
179 | 179 | 'tenantCode' => null, |
180 | 180 | ]))) { |
181 | - throw new NotFoundHttpException('Organization rule was not found.'); |
|
181 | + throw new NotFoundHttpException('Organization rule was not found.'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $rule; |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - private function getRuleRepository() { |
|
187 | + private function getRuleRepository() { |
|
188 | 188 | return $this->ruleRepository; |
189 | - } |
|
189 | + } |
|
190 | 190 | |
191 | - private function getEventDispatcher() { |
|
191 | + private function getEventDispatcher() { |
|
192 | 192 | return $this->eventDispatcher; |
193 | - } |
|
193 | + } |
|
194 | 194 | } |
@@ -23,12 +23,12 @@ |
||
23 | 23 | use FOS\RestBundle\Controller\Annotations\Route; |
24 | 24 | |
25 | 25 | class FailedQueueController extends AbstractController { |
26 | - /** |
|
27 | - * @Route("/api/{version}/failed_queue/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_failed_queue") |
|
28 | - */ |
|
29 | - public function listAction(Request $request, FailedEntriesProvider $failedEntriesProvider) { |
|
26 | + /** |
|
27 | + * @Route("/api/{version}/failed_queue/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_failed_queue") |
|
28 | + */ |
|
29 | + public function listAction(Request $request, FailedEntriesProvider $failedEntriesProvider) { |
|
30 | 30 | $max = $request->query->getInt('limit', 50); |
31 | 31 | |
32 | 32 | return new SingleResourceResponse($failedEntriesProvider->getFailedEntries($max)); |
33 | - } |
|
33 | + } |
|
34 | 34 | } |
@@ -19,34 +19,34 @@ discard block |
||
19 | 19 | use FOS\RestBundle\Controller\Annotations\Route; |
20 | 20 | |
21 | 21 | class SeoMetadataController extends AbstractController { |
22 | - private FormFactoryInterface $formFactory; |
|
23 | - private FactoryInterface $seoMetadataFactory; |
|
24 | - private RepositoryInterface $seoMetadataRepository; |
|
25 | - private EventDispatcherInterface $eventDispatcher; |
|
22 | + private FormFactoryInterface $formFactory; |
|
23 | + private FactoryInterface $seoMetadataFactory; |
|
24 | + private RepositoryInterface $seoMetadataRepository; |
|
25 | + private EventDispatcherInterface $eventDispatcher; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param FormFactoryInterface $formFactory |
|
29 | - * @param FactoryInterface $seoMetadataFactory |
|
30 | - * @param RepositoryInterface $seoMetadataRepository |
|
31 | - * @param EventDispatcherInterface $eventDispatcher |
|
32 | - */ |
|
33 | - public function __construct(FormFactoryInterface $formFactory, FactoryInterface $seoMetadataFactory, |
|
34 | - RepositoryInterface $seoMetadataRepository, EventDispatcherInterface $eventDispatcher) { |
|
27 | + /** |
|
28 | + * @param FormFactoryInterface $formFactory |
|
29 | + * @param FactoryInterface $seoMetadataFactory |
|
30 | + * @param RepositoryInterface $seoMetadataRepository |
|
31 | + * @param EventDispatcherInterface $eventDispatcher |
|
32 | + */ |
|
33 | + public function __construct(FormFactoryInterface $formFactory, FactoryInterface $seoMetadataFactory, |
|
34 | + RepositoryInterface $seoMetadataRepository, EventDispatcherInterface $eventDispatcher) { |
|
35 | 35 | $this->formFactory = $formFactory; |
36 | 36 | $this->seoMetadataFactory = $seoMetadataFactory; |
37 | 37 | $this->seoMetadataRepository = $seoMetadataRepository; |
38 | 38 | $this->eventDispatcher = $eventDispatcher; |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
43 | - */ |
|
44 | - public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
41 | + /** |
|
42 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
43 | + */ |
|
44 | + public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
45 | 45 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
46 | 46 | |
47 | 47 | $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
48 | 48 | if (null === $seoMetadata) { |
49 | - $seoMetadata = $this->seoMetadataFactory->create(); |
|
49 | + $seoMetadata = $this->seoMetadataFactory->create(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $form = $this->formFactory->createNamed('', SeoMetadataType::class, $seoMetadata, ['method' => $request->getMethod()]); |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | $form->handleRequest($request); |
55 | 55 | |
56 | 56 | if ($form->isSubmitted() && $form->isValid()) { |
57 | - $seoMetadata->setPackageGuid($packageGuid); |
|
58 | - $this->seoMetadataRepository->add($seoMetadata); |
|
57 | + $seoMetadata->setPackageGuid($packageGuid); |
|
58 | + $this->seoMetadataRepository->add($seoMetadata); |
|
59 | 59 | |
60 | - return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
60 | + return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return new SingleResourceResponse($form, new ResponseContext(400)); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
68 | - */ |
|
69 | - public function getAction(string $packageGuid): SingleResourceResponse { |
|
66 | + /** |
|
67 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
68 | + */ |
|
69 | + public function getAction(string $packageGuid): SingleResourceResponse { |
|
70 | 70 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
71 | 71 | |
72 | 72 | $existingSeoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
73 | 73 | if (null === $existingSeoMetadata) { |
74 | - throw new NotFoundHttpException('SEO metadata not found!'); |
|
74 | + throw new NotFoundHttpException('SEO metadata not found!'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return new SingleResourceResponse($existingSeoMetadata, new ResponseContext(200)); |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
@@ -44,35 +44,35 @@ discard block |
||
44 | 44 | use FOS\RestBundle\Controller\Annotations\Route; |
45 | 45 | |
46 | 46 | class ContentListItemController extends AbstractController { |
47 | - private ContentListItemRepositoryInterface $contentListItemRepository; |
|
48 | - private EntityManagerInterface $entityManager; |
|
49 | - private ContentListServiceInterface $contentListService; |
|
50 | - private EventDispatcherInterface $eventDispatcher; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
54 | - * @param EntityManagerInterface $entityManager |
|
55 | - * @param ContentListServiceInterface $contentListService |
|
56 | - * @param EventDispatcherInterface $eventDispatcher |
|
57 | - */ |
|
58 | - public function __construct(ContentListItemRepositoryInterface $contentListItemRepository, |
|
59 | - EntityManagerInterface $entityManager, |
|
60 | - ContentListServiceInterface $contentListService, |
|
61 | - EventDispatcherInterface $eventDispatcher) { |
|
47 | + private ContentListItemRepositoryInterface $contentListItemRepository; |
|
48 | + private EntityManagerInterface $entityManager; |
|
49 | + private ContentListServiceInterface $contentListService; |
|
50 | + private EventDispatcherInterface $eventDispatcher; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
54 | + * @param EntityManagerInterface $entityManager |
|
55 | + * @param ContentListServiceInterface $contentListService |
|
56 | + * @param EventDispatcherInterface $eventDispatcher |
|
57 | + */ |
|
58 | + public function __construct(ContentListItemRepositoryInterface $contentListItemRepository, |
|
59 | + EntityManagerInterface $entityManager, |
|
60 | + ContentListServiceInterface $contentListService, |
|
61 | + EventDispatcherInterface $eventDispatcher) { |
|
62 | 62 | $this->contentListItemRepository = $contentListItemRepository; |
63 | 63 | $this->entityManager = $entityManager; |
64 | 64 | $this->contentListService = $contentListService; |
65 | 65 | $this->eventDispatcher = $eventDispatcher; |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * @Route("/api/{version}/content/lists/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_items", requirements={"id"="\d+"}) |
|
71 | - */ |
|
72 | - public function listAction(Request $request, int $id): ResourcesListResponseInterface { |
|
69 | + /** |
|
70 | + * @Route("/api/{version}/content/lists/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_items", requirements={"id"="\d+"}) |
|
71 | + */ |
|
72 | + public function listAction(Request $request, int $id): ResourcesListResponseInterface { |
|
73 | 73 | $sort = $request->query->all('sorting'); |
74 | 74 | if (empty($sort)) { |
75 | - $sort = ['sticky' => 'desc']; |
|
75 | + $sort = ['sticky' => 'desc']; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $items = $this->contentListItemRepository->getPaginatedByCriteria( |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | ); |
106 | 106 | |
107 | 107 | return new ResourcesListResponse($items, $responseContext); |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_lists_item", requirements={"id"="\d+"}) |
|
112 | - */ |
|
113 | - public function getAction($listId, $id) { |
|
110 | + /** |
|
111 | + * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_lists_item", requirements={"id"="\d+"}) |
|
112 | + */ |
|
113 | + public function getAction($listId, $id) { |
|
114 | 114 | return new SingleResourceResponse($this->findOr404($listId, $id)); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_lists_item", requirements={"id"="\d+", "listId"="\d+"}) |
|
119 | - */ |
|
120 | - public function updateAction(Request $request, FormFactoryInterface $formFactory, $listId, |
|
121 | - $id): SingleResourceResponseInterface { |
|
117 | + /** |
|
118 | + * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_lists_item", requirements={"id"="\d+", "listId"="\d+"}) |
|
119 | + */ |
|
120 | + public function updateAction(Request $request, FormFactoryInterface $formFactory, $listId, |
|
121 | + $id): SingleResourceResponseInterface { |
|
122 | 122 | $contentListItem = $this->findOr404($listId, $id); |
123 | 123 | $form = $formFactory->createNamed( |
124 | 124 | '', |
@@ -130,59 +130,59 @@ discard block |
||
130 | 130 | $form->handleRequest($request); |
131 | 131 | |
132 | 132 | if ($form->isSubmitted() && $form->isValid()) { |
133 | - $contentListItem->getContentList()->setUpdatedAt(new DateTime()); |
|
133 | + $contentListItem->getContentList()->setUpdatedAt(new DateTime()); |
|
134 | 134 | |
135 | - if (null !== $contentListItem->getStickyPosition()) { |
|
135 | + if (null !== $contentListItem->getStickyPosition()) { |
|
136 | 136 | $contentListItem->setPosition($contentListItem->getStickyPosition()); |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - $this->entityManager->flush(); |
|
139 | + $this->entityManager->flush(); |
|
140 | 140 | |
141 | - return new SingleResourceResponse($contentListItem); |
|
141 | + return new SingleResourceResponse($contentListItem); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return new SingleResourceResponse($form, new ResponseContext(400)); |
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @Route("/api/{version}/content/lists/{listId}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_batch_update_lists_item", requirements={"listId"="\d+"}) |
|
149 | - */ |
|
150 | - public function batchUpdateAction( |
|
151 | - Request $request, |
|
152 | - FormFactoryInterface $formFactory, |
|
153 | - ContentListRepositoryInterface $contentListRepository, |
|
154 | - ArticleRepositoryInterface $articleRepository, |
|
155 | - EventDispatcherInterface $eventDispatcher, |
|
156 | - int $listId |
|
157 | - ): SingleResourceResponseInterface { |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @Route("/api/{version}/content/lists/{listId}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_batch_update_lists_item", requirements={"listId"="\d+"}) |
|
149 | + */ |
|
150 | + public function batchUpdateAction( |
|
151 | + Request $request, |
|
152 | + FormFactoryInterface $formFactory, |
|
153 | + ContentListRepositoryInterface $contentListRepository, |
|
154 | + ArticleRepositoryInterface $articleRepository, |
|
155 | + EventDispatcherInterface $eventDispatcher, |
|
156 | + int $listId |
|
157 | + ): SingleResourceResponseInterface { |
|
158 | 158 | /** @var ContentListInterface $list */ |
159 | 159 | $list = $contentListRepository->findOneBy(['id' => $listId]); |
160 | 160 | if (null === $list) { |
161 | - throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $list)); |
|
161 | + throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $list)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $form = $formFactory->createNamed('', ContentListItemsType::class, [], ['method' => $request->getMethod()]); |
165 | 165 | |
166 | 166 | $form->handleRequest($request); |
167 | 167 | if ($form->isSubmitted() && $form->isValid()) { |
168 | - $data = $form->getData(); |
|
169 | - $updatedAt = DateTime::createFromFormat(DateTime::RFC3339, $data['updatedAt'], new DateTimeZone('UTC')); |
|
170 | - $updatedAt->setTimezone(new DateTimeZone('UTC')); |
|
171 | - $listUpdatedAt = $list->getUpdatedAt(); |
|
172 | - $listUpdatedAt->setTimezone(new DateTimeZone('UTC')); |
|
173 | - if ($updatedAt < $listUpdatedAt) { |
|
168 | + $data = $form->getData(); |
|
169 | + $updatedAt = DateTime::createFromFormat(DateTime::RFC3339, $data['updatedAt'], new DateTimeZone('UTC')); |
|
170 | + $updatedAt->setTimezone(new DateTimeZone('UTC')); |
|
171 | + $listUpdatedAt = $list->getUpdatedAt(); |
|
172 | + $listUpdatedAt->setTimezone(new DateTimeZone('UTC')); |
|
173 | + if ($updatedAt < $listUpdatedAt) { |
|
174 | 174 | throw new ConflictHttpException('List was already updated'); |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - $updatedArticles = []; |
|
178 | - /** @var ContentListAction $item */ |
|
179 | - foreach ($data['items'] as $item) { |
|
177 | + $updatedArticles = []; |
|
178 | + /** @var ContentListAction $item */ |
|
179 | + foreach ($data['items'] as $item) { |
|
180 | 180 | $position = $item->getPosition(); |
181 | 181 | $isSticky = $item->isSticky(); |
182 | 182 | $contentId = $item->getContentId(); |
183 | 183 | |
184 | 184 | switch ($item->getAction()) { |
185 | - case ContentListAction::ACTION_MOVE: |
|
185 | + case ContentListAction::ACTION_MOVE: |
|
186 | 186 | $contentListItem = $this->findByContentOr404($list, $contentId); |
187 | 187 | |
188 | 188 | $this->ensureThereIsNoItemOnPositionOrThrow409($listId, $position, $isSticky); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $updatedArticles[$contentId] = $contentListItem->getContent(); |
196 | 196 | |
197 | 197 | break; |
198 | - case ContentListAction::ACTION_ADD: |
|
198 | + case ContentListAction::ACTION_ADD: |
|
199 | 199 | $this->ensureThereIsNoItemOnPositionOrThrow409($listId, $position, $isSticky); |
200 | 200 | |
201 | 201 | $object = $articleRepository->findOneById($contentId); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $updatedArticles[$contentId] = $contentListItem->getContent(); |
205 | 205 | |
206 | 206 | break; |
207 | - case ContentListAction::ACTION_DELETE: |
|
207 | + case ContentListAction::ACTION_DELETE: |
|
208 | 208 | $contentListItem = $this->findByContentOr404($list, $contentId); |
209 | 209 | $this->entityManager->remove($contentListItem); |
210 | 210 | $list->setUpdatedAt(new DateTime('now')); |
@@ -213,25 +213,25 @@ discard block |
||
213 | 213 | |
214 | 214 | break; |
215 | 215 | } |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - $this->contentListService->repositionStickyItems($list); |
|
218 | + $this->contentListService->repositionStickyItems($list); |
|
219 | 219 | |
220 | - foreach ($updatedArticles as $updatedArticle) { |
|
220 | + foreach ($updatedArticles as $updatedArticle) { |
|
221 | 221 | $eventDispatcher->dispatch(new ArticleEvent( |
222 | 222 | $updatedArticle, |
223 | 223 | $updatedArticle->getPackage(), |
224 | 224 | ArticleEvents::POST_UPDATE |
225 | 225 | ), ArticleEvents::POST_UPDATE); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - return new SingleResourceResponse($list, new ResponseContext(201)); |
|
228 | + return new SingleResourceResponse($list, new ResponseContext(201)); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | return new SingleResourceResponse($form, new ResponseContext(400)); |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - private function findByContentOr404($listId, $contentId): ContentListItemInterface { |
|
234 | + private function findByContentOr404($listId, $contentId): ContentListItemInterface { |
|
235 | 235 | /** @var ContentListItemInterface $listItem */ |
236 | 236 | $listItem = $this->contentListItemRepository->findOneBy([ |
237 | 237 | 'contentList' => $listId, |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | ]); |
240 | 240 | |
241 | 241 | if (null === $listItem) { |
242 | - throw new NotFoundHttpException(sprintf('Content list item with content_id "%s" was not found on that list. If You want to add new item - use action type "add".', $contentId)); |
|
242 | + throw new NotFoundHttpException(sprintf('Content list item with content_id "%s" was not found on that list. If You want to add new item - use action type "add".', $contentId)); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | return $listItem; |
246 | - } |
|
246 | + } |
|
247 | 247 | |
248 | - private function findOr404($listId, $id): ContentListItemInterface { |
|
248 | + private function findOr404($listId, $id): ContentListItemInterface { |
|
249 | 249 | /** @var ContentListItemInterface $listItem */ |
250 | 250 | $listItem = $this->contentListItemRepository->findOneBy([ |
251 | 251 | 'contentList' => $listId, |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | ]); |
254 | 254 | |
255 | 255 | if (null === $listItem) { |
256 | - throw new NotFoundHttpException(sprintf('Content list item with id "%s" was not found.', $id)); |
|
256 | + throw new NotFoundHttpException(sprintf('Content list item with id "%s" was not found.', $id)); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return $listItem; |
260 | - } |
|
260 | + } |
|
261 | 261 | |
262 | - private function ensureThereIsNoItemOnPositionOrThrow409(int $listId, int $position, bool $isSticky): void { |
|
262 | + private function ensureThereIsNoItemOnPositionOrThrow409(int $listId, int $position, bool $isSticky): void { |
|
263 | 263 | $existingContentListItem = $this->contentListService->isAnyItemPinnedOnPosition($listId, $position); |
264 | 264 | |
265 | 265 | if (null !== $existingContentListItem && $isSticky && $existingContentListItem->isSticky()) { |
266 | - throw new ConflictHttpException('There is already an item pinned on that position. Unpin it first.'); |
|
266 | + throw new ConflictHttpException('There is already an item pinned on that position. Unpin it first.'); |
|
267 | + } |
|
267 | 268 | } |
268 | - } |
|
269 | 269 | } |
@@ -41,32 +41,32 @@ discard block |
||
41 | 41 | use FOS\RestBundle\Controller\Annotations\Route; |
42 | 42 | |
43 | 43 | class ContentPushController extends AbstractController { |
44 | - private EventDispatcherInterface $eventDispatcher; |
|
45 | - private FormFactoryInterface $formFactory; |
|
46 | - private MessageBusInterface $messageBus; |
|
47 | - private CachedTenantContextInterface $cachedTenantContext; //swp_multi_tenancy.tenant_context |
|
48 | - private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
49 | - private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
50 | - private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
51 | - private PackageRepositoryInterface $packageRepository;//swp.repository.package |
|
52 | - private FileProviderInterface $fileProvider; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param EventDispatcherInterface $eventDispatcher |
|
56 | - * @param FormFactoryInterface $formFactory |
|
57 | - * @param MessageBusInterface $messageBus |
|
58 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
59 | - * @param DataTransformerInterface $dataTransformer |
|
60 | - * @param MediaManagerInterface $mediaManager |
|
61 | - * @param EntityManagerInterface $entityManager |
|
62 | - * @param PackageRepositoryInterface $packageRepository |
|
63 | - * @param FileProviderInterface $fileProvider |
|
64 | - */ |
|
65 | - public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
66 | - MessageBusInterface $messageBus, CachedTenantContextInterface $cachedTenantContext, |
|
67 | - DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
68 | - EntityManagerInterface $entityManager, PackageRepositoryInterface $packageRepository, |
|
69 | - FileProviderInterface $fileProvider) { |
|
44 | + private EventDispatcherInterface $eventDispatcher; |
|
45 | + private FormFactoryInterface $formFactory; |
|
46 | + private MessageBusInterface $messageBus; |
|
47 | + private CachedTenantContextInterface $cachedTenantContext; //swp_multi_tenancy.tenant_context |
|
48 | + private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
49 | + private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
50 | + private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
51 | + private PackageRepositoryInterface $packageRepository;//swp.repository.package |
|
52 | + private FileProviderInterface $fileProvider; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param EventDispatcherInterface $eventDispatcher |
|
56 | + * @param FormFactoryInterface $formFactory |
|
57 | + * @param MessageBusInterface $messageBus |
|
58 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
59 | + * @param DataTransformerInterface $dataTransformer |
|
60 | + * @param MediaManagerInterface $mediaManager |
|
61 | + * @param EntityManagerInterface $entityManager |
|
62 | + * @param PackageRepositoryInterface $packageRepository |
|
63 | + * @param FileProviderInterface $fileProvider |
|
64 | + */ |
|
65 | + public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
66 | + MessageBusInterface $messageBus, CachedTenantContextInterface $cachedTenantContext, |
|
67 | + DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
68 | + EntityManagerInterface $entityManager, PackageRepositoryInterface $packageRepository, |
|
69 | + FileProviderInterface $fileProvider) { |
|
70 | 70 | $this->eventDispatcher = $eventDispatcher; |
71 | 71 | $this->formFactory = $formFactory; |
72 | 72 | $this->messageBus = $messageBus; |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | $this->entityManager = $entityManager; |
77 | 77 | $this->packageRepository = $packageRepository; |
78 | 78 | $this->fileProvider = $fileProvider; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
84 | - */ |
|
85 | - public function pushContentAction(Request $request): SingleResourceResponseInterface { |
|
82 | + /** |
|
83 | + * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
84 | + */ |
|
85 | + public function pushContentAction(Request $request): SingleResourceResponseInterface { |
|
86 | 86 | $package = $this->dataTransformer->transform($request->getContent()); |
87 | 87 | $this->eventDispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
88 | 88 | |
@@ -91,27 +91,27 @@ discard block |
||
91 | 91 | $this->messageBus->dispatch(new ContentPushMessage($currentTenant->getId(), $request->getContent())); |
92 | 92 | |
93 | 93 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
98 | - */ |
|
99 | - public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
96 | + /** |
|
97 | + * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
98 | + */ |
|
99 | + public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
100 | 100 | $form = $this->formFactory->createNamed('', MediaFileType::class); |
101 | 101 | $form->handleRequest($request); |
102 | 102 | |
103 | 103 | if ($form->isSubmitted() && $form->isValid()) { |
104 | - $mediaManager = $this->mediaManager; |
|
105 | - $uploadedFile = $form->getData()['media']; |
|
106 | - $mediaId = $request->request->get('mediaId'); |
|
104 | + $mediaManager = $this->mediaManager; |
|
105 | + $uploadedFile = $form->getData()['media']; |
|
106 | + $mediaId = $request->request->get('mediaId'); |
|
107 | 107 | |
108 | - if ($uploadedFile->isValid()) { |
|
108 | + if ($uploadedFile->isValid()) { |
|
109 | 109 | $fileProvider = $this->fileProvider; |
110 | 110 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $uploadedFile->guessExtension()); |
111 | 111 | |
112 | 112 | if (null === $file) { |
113 | - $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
114 | - $this->entityManager->flush(); |
|
113 | + $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
114 | + $this->entityManager->flush(); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return new SingleResourceResponse( |
@@ -124,23 +124,23 @@ discard block |
||
124 | 124 | ], |
125 | 125 | new ResponseContext(201) |
126 | 126 | ); |
127 | - } |
|
127 | + } |
|
128 | 128 | |
129 | - throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
129 | + throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return new SingleResourceResponse($form); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
137 | - */ |
|
138 | - public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
135 | + /** |
|
136 | + * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
137 | + */ |
|
138 | + public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
139 | 139 | $fileProvider = $this->fileProvider; |
140 | 140 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension); |
141 | 141 | |
142 | 142 | if (null === $file) { |
143 | - throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
143 | + throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $mediaManager = $this->mediaManager; |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | 'mime_type' => Mime::getMimeFromExtension($file->getFileExtension()), |
153 | 153 | 'filemeta' => [], |
154 | 154 | ]); |
155 | - } |
|
155 | + } |
|
156 | 156 | |
157 | - protected function getPackageRepository() { |
|
157 | + protected function getPackageRepository() { |
|
158 | 158 | return $this->packageRepository; |
159 | - } |
|
159 | + } |
|
160 | 160 | } |
@@ -41,43 +41,43 @@ discard block |
||
41 | 41 | |
42 | 42 | class RegistrationController extends AbstractController { |
43 | 43 | |
44 | - private SettingsManagerInterface $settingsManager; |
|
45 | - private ScopeContextInterface $scopeContext; |
|
46 | - private EmailVerifier $emailVerifier; |
|
47 | - private UserManagerInterface $userManager; |
|
48 | - private EntityManagerInterface $entityManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param SettingsManagerInterface $settingsManager |
|
52 | - * @param ScopeContextInterface $scopeContext |
|
53 | - * @param EmailVerifier $emailVerifier |
|
54 | - * @param UserManagerInterface $userManager |
|
55 | - * @param EntityManagerInterface $entityManager |
|
56 | - */ |
|
57 | - public function __construct(SettingsManagerInterface $settingsManager, ScopeContextInterface $scopeContext, |
|
58 | - EmailVerifier $emailVerifier, UserManagerInterface $userManager, |
|
59 | - EntityManagerInterface $entityManager) { |
|
44 | + private SettingsManagerInterface $settingsManager; |
|
45 | + private ScopeContextInterface $scopeContext; |
|
46 | + private EmailVerifier $emailVerifier; |
|
47 | + private UserManagerInterface $userManager; |
|
48 | + private EntityManagerInterface $entityManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param SettingsManagerInterface $settingsManager |
|
52 | + * @param ScopeContextInterface $scopeContext |
|
53 | + * @param EmailVerifier $emailVerifier |
|
54 | + * @param UserManagerInterface $userManager |
|
55 | + * @param EntityManagerInterface $entityManager |
|
56 | + */ |
|
57 | + public function __construct(SettingsManagerInterface $settingsManager, ScopeContextInterface $scopeContext, |
|
58 | + EmailVerifier $emailVerifier, UserManagerInterface $userManager, |
|
59 | + EntityManagerInterface $entityManager) { |
|
60 | 60 | $this->settingsManager = $settingsManager; |
61 | 61 | $this->scopeContext = $scopeContext; |
62 | 62 | $this->emailVerifier = $emailVerifier; |
63 | 63 | $this->userManager = $userManager; |
64 | 64 | $this->entityManager = $entityManager; |
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @FOSRoute("/api/{version}/users/register/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_register_user") |
|
70 | - */ |
|
71 | - public function registerAction( |
|
72 | - Request $request, |
|
73 | - UserPasswordHasherInterface $passwordEncoder, |
|
74 | - UserManagerInterface $userManager, |
|
75 | - MailerInterface $mailer |
|
76 | - ) { |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @FOSRoute("/api/{version}/users/register/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_register_user") |
|
70 | + */ |
|
71 | + public function registerAction( |
|
72 | + Request $request, |
|
73 | + UserPasswordHasherInterface $passwordEncoder, |
|
74 | + UserManagerInterface $userManager, |
|
75 | + MailerInterface $mailer |
|
76 | + ) { |
|
77 | 77 | try { |
78 | - $this->ensureThatRegistrationIsEnabled(); |
|
78 | + $this->ensureThatRegistrationIsEnabled(); |
|
79 | 79 | } catch (NotFoundHttpException $e) { |
80 | - return new SingleResourceResponse(null, new ResponseContext(404)); |
|
80 | + return new SingleResourceResponse(null, new ResponseContext(404)); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $user = $userManager->createUser(); |
@@ -86,66 +86,66 @@ discard block |
||
86 | 86 | $form->handleRequest($request); |
87 | 87 | |
88 | 88 | if ($form->isSubmitted() && $form->isValid()) { |
89 | - $user->addRole('ROLE_USER'); |
|
90 | - // encode the plain password |
|
91 | - $user->setPassword( |
|
92 | - $passwordEncoder->hashPassword( |
|
93 | - $user, |
|
94 | - $form->get('plainPassword')->getData() |
|
95 | - ) |
|
96 | - ); |
|
97 | - |
|
98 | - $entityManager = $this->entityManager; |
|
99 | - $entityManager->persist($user); |
|
100 | - $entityManager->flush(); |
|
101 | - |
|
102 | - $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
103 | - $url = $signatureComponents->getSignedUrl(); |
|
104 | - |
|
105 | - $mailer->sendConfirmationEmail($user, $url); |
|
106 | - |
|
107 | - return new JsonResponse([ |
|
108 | - 'message' => sprintf( |
|
109 | - 'The user has been created successfully. |
|
89 | + $user->addRole('ROLE_USER'); |
|
90 | + // encode the plain password |
|
91 | + $user->setPassword( |
|
92 | + $passwordEncoder->hashPassword( |
|
93 | + $user, |
|
94 | + $form->get('plainPassword')->getData() |
|
95 | + ) |
|
96 | + ); |
|
97 | + |
|
98 | + $entityManager = $this->entityManager; |
|
99 | + $entityManager->persist($user); |
|
100 | + $entityManager->flush(); |
|
101 | + |
|
102 | + $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
103 | + $url = $signatureComponents->getSignedUrl(); |
|
104 | + |
|
105 | + $mailer->sendConfirmationEmail($user, $url); |
|
106 | + |
|
107 | + return new JsonResponse([ |
|
108 | + 'message' => sprintf( |
|
109 | + 'The user has been created successfully. |
|
110 | 110 | An email has been sent to %s. It contains an activation link you must click to activate your account.', |
111 | - $user->getEmail() |
|
112 | - ), |
|
113 | - 'url' => $url, |
|
114 | - ]); |
|
111 | + $user->getEmail() |
|
112 | + ), |
|
113 | + 'url' => $url, |
|
114 | + ]); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return new SingleResourceResponse($form, new ResponseContext(400)); |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @Route("/verify/email", name="swp_user_verify_email") |
|
122 | - */ |
|
123 | - public function verifyUserEmail(Request $request, GuardAuthenticatorHandler $guardHandler, |
|
124 | - LoginAuthenticator $authenticator): Response { |
|
120 | + /** |
|
121 | + * @Route("/verify/email", name="swp_user_verify_email") |
|
122 | + */ |
|
123 | + public function verifyUserEmail(Request $request, GuardAuthenticatorHandler $guardHandler, |
|
124 | + LoginAuthenticator $authenticator): Response { |
|
125 | 125 | $id = (int)$request->get('id'); // retrieve the user id from the url |
126 | 126 | |
127 | 127 | if ($request->isXmlHttpRequest()) { |
128 | - return $this->verifyUserEmailFromPWA($id, $request); |
|
128 | + return $this->verifyUserEmailFromPWA($id, $request); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | // Verify the user id exists and is not null |
132 | 132 | if (null === $id) { |
133 | - return $this->redirectToRoute('homepage'); |
|
133 | + return $this->redirectToRoute('homepage'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | $user = $this->userManager->find($id); |
137 | 137 | |
138 | 138 | // Ensure the user exists in persistence |
139 | 139 | if (null === $user) { |
140 | - return $this->redirectToRoute('homepage'); |
|
140 | + return $this->redirectToRoute('homepage'); |
|
141 | 141 | } |
142 | 142 | // validate email confirmation link, sets User::isVerified=true and persists |
143 | 143 | try { |
144 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
144 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
145 | 145 | } catch (VerifyEmailExceptionInterface $exception) { |
146 | - $this->addFlash('verify_email_error', $exception->getReason()); |
|
146 | + $this->addFlash('verify_email_error', $exception->getReason()); |
|
147 | 147 | |
148 | - return $this->redirectToRoute('homepage'); |
|
148 | + return $this->redirectToRoute('homepage'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $guardHandler->authenticateUserAndHandleSuccess( |
@@ -158,63 +158,63 @@ discard block |
||
158 | 158 | $this->addFlash('success', 'The user has been created successfully.'); |
159 | 159 | |
160 | 160 | return $this->redirectToRoute('swp_user_registration_confirmed'); |
161 | - } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Tell the user his account is now confirmed. |
|
165 | - */ |
|
166 | - public function confirmedAction(Request $request) { |
|
163 | + /** |
|
164 | + * Tell the user his account is now confirmed. |
|
165 | + */ |
|
166 | + public function confirmedAction(Request $request) { |
|
167 | 167 | $user = $this->getUser(); |
168 | 168 | if (!is_object($user) || !$user instanceof UserInterface) { |
169 | - $this->createAccessDeniedException('This user does not have access to this section.'); |
|
169 | + $this->createAccessDeniedException('This user does not have access to this section.'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | return $this->render('@SWPUser/Registration/confirmed.html.twig', [ |
173 | 173 | 'user' => $user, |
174 | 174 | ]); |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @throws NotFoundHttpException |
|
179 | - */ |
|
180 | - private function ensureThatRegistrationIsEnabled() { |
|
177 | + /** |
|
178 | + * @throws NotFoundHttpException |
|
179 | + */ |
|
180 | + private function ensureThatRegistrationIsEnabled() { |
|
181 | 181 | $settingName = 'registration_enabled'; |
182 | 182 | $setting = $this->settingsManager->getOneSettingByName($settingName); |
183 | 183 | $registrationEnabled = $this->settingsManager |
184 | 184 | ->get($settingName, $setting['scope'], $this->scopeContext->getScopeOwner($setting['scope'])); |
185 | 185 | if (!$registrationEnabled) { |
186 | - throw new NotFoundHttpException('Registration is disabled.'); |
|
186 | + throw new NotFoundHttpException('Registration is disabled.'); |
|
187 | + } |
|
187 | 188 | } |
188 | - } |
|
189 | 189 | |
190 | - private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
190 | + private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
191 | 191 | // Verify the user id exists and is not null |
192 | 192 | if (null === $id) { |
193 | - return new JsonResponse( |
|
194 | - ['error' => 'User does not exist'] |
|
195 | - ); |
|
193 | + return new JsonResponse( |
|
194 | + ['error' => 'User does not exist'] |
|
195 | + ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $user = $this->userManager->find($id); |
199 | 199 | |
200 | 200 | // Ensure the user exists in persistence |
201 | 201 | if (null === $user) { |
202 | - return new JsonResponse( |
|
203 | - ['error' => 'User does not exist'] |
|
204 | - ); |
|
202 | + return new JsonResponse( |
|
203 | + ['error' => 'User does not exist'] |
|
204 | + ); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | // validate email confirmation link, sets User::isVerified=true and persists |
208 | 208 | try { |
209 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
209 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
210 | 210 | } catch (VerifyEmailExceptionInterface $exception) { |
211 | - return new JsonResponse( |
|
212 | - ['error' => 'Registration confirmation invalid'] |
|
213 | - ); |
|
211 | + return new JsonResponse( |
|
212 | + ['error' => 'Registration confirmation invalid'] |
|
213 | + ); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return new JsonResponse( |
217 | 217 | ['message' => 'The user has been created successfully.'] |
218 | 218 | ); |
219 | - } |
|
219 | + } |
|
220 | 220 | } |