@@ -28,40 +28,40 @@ discard block |
||
28 | 28 | |
29 | 29 | class DefaultController extends AbstractController { |
30 | 30 | |
31 | - private CachedTenantContextInterface $tenantContext; |
|
32 | - private MetaFactoryInterface $metaFactory; |
|
33 | - private Context $templateEngineContext; |
|
34 | - private RouteFactoryInterface $routeFactory; |
|
31 | + private CachedTenantContextInterface $tenantContext; |
|
32 | + private MetaFactoryInterface $metaFactory; |
|
33 | + private Context $templateEngineContext; |
|
34 | + private RouteFactoryInterface $routeFactory; |
|
35 | 35 | |
36 | - public function __construct( |
|
37 | - CachedTenantContextInterface $tenantContext, |
|
38 | - MetaFactoryInterface $metaFactory, |
|
39 | - Context $templateEngineContext, |
|
40 | - RouteFactoryInterface $routeFactory |
|
41 | - ) { |
|
36 | + public function __construct( |
|
37 | + CachedTenantContextInterface $tenantContext, |
|
38 | + MetaFactoryInterface $metaFactory, |
|
39 | + Context $templateEngineContext, |
|
40 | + RouteFactoryInterface $routeFactory |
|
41 | + ) { |
|
42 | 42 | $this->tenantContext = $tenantContext; |
43 | 43 | $this->metaFactory = $metaFactory; |
44 | 44 | $this->templateEngineContext = $templateEngineContext; |
45 | 45 | $this->routeFactory = $routeFactory; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @Route("/", methods={"GET","POST"}, name="homepage") |
|
50 | - */ |
|
51 | - public function indexAction(Request $request): Response { |
|
48 | + /** |
|
49 | + * @Route("/", methods={"GET","POST"}, name="homepage") |
|
50 | + */ |
|
51 | + public function indexAction(Request $request): Response { |
|
52 | 52 | /** @var TenantInterface $currentTenant */ |
53 | 53 | $currentTenant = $this->tenantContext->getTenant(); |
54 | 54 | $route = $currentTenant->getHomepage(); |
55 | 55 | |
56 | 56 | if (null === $route) { |
57 | - /** @var RouteInterface $route */ |
|
58 | - $route = $this->routeFactory->create(); |
|
59 | - $route->setStaticPrefix('/'); |
|
60 | - $route->setName('Homepage'); |
|
61 | - $route->setType('content'); |
|
62 | - $route->setTemplateName('index.html.twig'); |
|
63 | - $route->setCacheTimeInSeconds(360); |
|
64 | - $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
57 | + /** @var RouteInterface $route */ |
|
58 | + $route = $this->routeFactory->create(); |
|
59 | + $route->setStaticPrefix('/'); |
|
60 | + $route->setName('Homepage'); |
|
61 | + $route->setType('content'); |
|
62 | + $route->setTemplateName('index.html.twig'); |
|
63 | + $route->setCacheTimeInSeconds(360); |
|
64 | + $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $this->templateEngineContext->setCurrentPage($this->metaFactory->create($route)); |
@@ -70,5 +70,5 @@ discard block |
||
70 | 70 | $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); |
71 | 71 | |
72 | 72 | return $this->render('index.html.twig', [], $response); |
73 | - } |
|
73 | + } |
|
74 | 74 | } |
@@ -45,39 +45,39 @@ discard block |
||
45 | 45 | |
46 | 46 | class PackageController extends Controller { |
47 | 47 | |
48 | - private FormFactoryInterface $formFactory; |
|
49 | - private EventDispatcherInterface $eventDispatcher; |
|
50 | - private CachedTenantContextInterface $cachedTenantContext; |
|
51 | - private ArticlePublisherInterface $articlePublisher; |
|
52 | - private PersisterRegistry $elasticaPersisterRegistry; |
|
53 | - private PackageRepositoryInterface $packageRepository; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param FormFactoryInterface $formFactory |
|
57 | - * @param EventDispatcherInterface $eventDispatcher |
|
58 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
59 | - * @param ArticlePublisherInterface $articlePublisher |
|
60 | - * @param PersisterRegistry $elasticaPersisterRegistry |
|
61 | - * @param PackageRepositoryInterface $packageRepository |
|
62 | - */ |
|
63 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | - CachedTenantContextInterface $cachedTenantContext, |
|
65 | - ArticlePublisherInterface $articlePublisher, |
|
66 | - PersisterRegistry $elasticaPersisterRegistry, |
|
67 | - PackageRepositoryInterface $packageRepository) { |
|
48 | + private FormFactoryInterface $formFactory; |
|
49 | + private EventDispatcherInterface $eventDispatcher; |
|
50 | + private CachedTenantContextInterface $cachedTenantContext; |
|
51 | + private ArticlePublisherInterface $articlePublisher; |
|
52 | + private PersisterRegistry $elasticaPersisterRegistry; |
|
53 | + private PackageRepositoryInterface $packageRepository; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param FormFactoryInterface $formFactory |
|
57 | + * @param EventDispatcherInterface $eventDispatcher |
|
58 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
59 | + * @param ArticlePublisherInterface $articlePublisher |
|
60 | + * @param PersisterRegistry $elasticaPersisterRegistry |
|
61 | + * @param PackageRepositoryInterface $packageRepository |
|
62 | + */ |
|
63 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | + CachedTenantContextInterface $cachedTenantContext, |
|
65 | + ArticlePublisherInterface $articlePublisher, |
|
66 | + PersisterRegistry $elasticaPersisterRegistry, |
|
67 | + PackageRepositoryInterface $packageRepository) { |
|
68 | 68 | $this->formFactory = $formFactory; |
69 | 69 | $this->eventDispatcher = $eventDispatcher; |
70 | 70 | $this->cachedTenantContext = $cachedTenantContext; |
71 | 71 | $this->articlePublisher = $articlePublisher; |
72 | 72 | $this->elasticaPersisterRegistry = $elasticaPersisterRegistry; |
73 | 73 | $this->packageRepository = $packageRepository; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @Route("/api/{version}/packages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_packages") |
|
79 | - */ |
|
80 | - public function listAction(Request $request) { |
|
77 | + /** |
|
78 | + * @Route("/api/{version}/packages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_packages") |
|
79 | + */ |
|
80 | + public function listAction(Request $request) { |
|
81 | 81 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
82 | 82 | $tenantContext = $this->cachedTenantContext; |
83 | 83 | |
@@ -88,19 +88,19 @@ discard block |
||
88 | 88 | ]), $request->query->all('sorting'), new PaginationData($request)); |
89 | 89 | |
90 | 90 | return new ResourcesListResponse($packages); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @Route("/api/{version}/packages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_package", requirements={"id"="\d+"}) |
|
95 | - */ |
|
96 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @Route("/api/{version}/packages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_package", requirements={"id"="\d+"}) |
|
95 | + */ |
|
96 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
97 | 97 | return new SingleResourceResponse($this->findOr404($id)); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @Route("/api/{version}/packages/{id}/publish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publish_package", requirements={"id"="\d+"}) |
|
102 | - */ |
|
103 | - public function publishAction(Request $request, int $id): SingleResourceResponseInterface { |
|
100 | + /** |
|
101 | + * @Route("/api/{version}/packages/{id}/publish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publish_package", requirements={"id"="\d+"}) |
|
102 | + */ |
|
103 | + public function publishAction(Request $request, int $id): SingleResourceResponseInterface { |
|
104 | 104 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
105 | 105 | /** @var PackageInterface $package */ |
106 | 106 | $package = $this->findOr404($id); |
@@ -109,74 +109,74 @@ discard block |
||
109 | 109 | $form->handleRequest($request); |
110 | 110 | |
111 | 111 | if ($form->isSubmitted() && $form->isValid()) { |
112 | - $this->articlePublisher->publish($package, $form->getData()); |
|
113 | - $this->elasticaPersisterRegistry->getPersister('swp_package')->replaceOne($package); |
|
112 | + $this->articlePublisher->publish($package, $form->getData()); |
|
113 | + $this->elasticaPersisterRegistry->getPersister('swp_package')->replaceOne($package); |
|
114 | 114 | |
115 | - return new SingleResourceResponse(null, new ResponseContext(201)); |
|
115 | + return new SingleResourceResponse(null, new ResponseContext(201)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return new SingleResourceResponse($form, new ResponseContext(400)); |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @Route("/api/{version}/packages/{id}/unpublish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_unpublish_package", requirements={"id"="\d+"}) |
|
123 | - */ |
|
124 | - public function unpublishAction(Request $request, int $id): SingleResourceResponseInterface { |
|
121 | + /** |
|
122 | + * @Route("/api/{version}/packages/{id}/unpublish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_unpublish_package", requirements={"id"="\d+"}) |
|
123 | + */ |
|
124 | + public function unpublishAction(Request $request, int $id): SingleResourceResponseInterface { |
|
125 | 125 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
126 | 126 | $package = $this->findOr404($id); |
127 | 127 | $form = $this->formFactory->createNamed('', UnpublishFromTenantsType::class, null, ['method' => $request->getMethod()]); |
128 | 128 | |
129 | 129 | $form->handleRequest($request); |
130 | 130 | if ($form->isSubmitted() && $form->isValid()) { |
131 | - $formData = $form->getData(); |
|
132 | - /** @var Collection $tenants */ |
|
133 | - $tenants = $formData['tenants']; |
|
134 | - $this->articlePublisher->unpublish($package, $tenants->toArray()); |
|
131 | + $formData = $form->getData(); |
|
132 | + /** @var Collection $tenants */ |
|
133 | + $tenants = $formData['tenants']; |
|
134 | + $this->articlePublisher->unpublish($package, $tenants->toArray()); |
|
135 | 135 | |
136 | - return new SingleResourceResponse(null, new ResponseContext(200)); |
|
136 | + return new SingleResourceResponse(null, new ResponseContext(200)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return new SingleResourceResponse($form, new ResponseContext(400)); |
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @Route("/api/{version}/packages/{id}/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_package", requirements={"id"="\d+"}) |
|
144 | - * |
|
145 | - * @return SingleResourceResponse |
|
146 | - */ |
|
147 | - public function updateAction(Request $request, int $id) { |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @Route("/api/{version}/packages/{id}/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_package", requirements={"id"="\d+"}) |
|
144 | + * |
|
145 | + * @return SingleResourceResponse |
|
146 | + */ |
|
147 | + public function updateAction(Request $request, int $id) { |
|
148 | 148 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
149 | 149 | $package = $this->findOr404($id); |
150 | 150 | $form = $this->formFactory->createNamed('', PackageType::class, $package, ['method' => $request->getMethod()]); |
151 | 151 | |
152 | 152 | $form->handleRequest($request); |
153 | 153 | if ($form->isSubmitted() && $form->isValid()) { |
154 | - if (ContentInterface::STATUS_CANCELED === $package->getPubStatus()) { |
|
154 | + if (ContentInterface::STATUS_CANCELED === $package->getPubStatus()) { |
|
155 | 155 | $package->setStatus(ContentInterface::STATUS_CANCELED); |
156 | - } |
|
157 | - $this->getPackageRepository()->flush(); |
|
156 | + } |
|
157 | + $this->getPackageRepository()->flush(); |
|
158 | 158 | |
159 | - return new SingleResourceResponse($package, new ResponseContext(200)); |
|
159 | + return new SingleResourceResponse($package, new ResponseContext(200)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return new SingleResourceResponse($form, new ResponseContext(400)); |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @return object|null |
|
167 | - */ |
|
168 | - private function findOr404(int $id) { |
|
165 | + /** |
|
166 | + * @return object|null |
|
167 | + */ |
|
168 | + private function findOr404(int $id) { |
|
169 | 169 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
170 | 170 | $tenantContext = $this->cachedTenantContext; |
171 | 171 | |
172 | 172 | if (null === $package = $this->getPackageRepository()->findOneBy(['id' => $id, 'organization' => $tenantContext->getTenant()->getOrganization()])) { |
173 | - throw new NotFoundHttpException('Package was not found.'); |
|
173 | + throw new NotFoundHttpException('Package was not found.'); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $package; |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - protected function getPackageRepository() { |
|
179 | + protected function getPackageRepository() { |
|
180 | 180 | return $this->packageRepository; |
181 | - } |
|
181 | + } |
|
182 | 182 | } |
@@ -37,30 +37,30 @@ discard block |
||
37 | 37 | |
38 | 38 | class ArticleCommentsController extends AbstractController { |
39 | 39 | |
40 | - private ArticleRepositoryInterface $articleRepository; |
|
41 | - private ArticleResolverInterface $articleResolver; |
|
42 | - private FormFactoryInterface $formFactory; |
|
43 | - private EventDispatcherInterface $eventDispatcher; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param ArticleRepositoryInterface $articleRepository |
|
47 | - * @param ArticleResolverInterface $articleResolver |
|
48 | - * @param FormFactoryInterface $formFactory |
|
49 | - * @param EventDispatcherInterface $eventDispatcher |
|
50 | - */ |
|
51 | - public function __construct(ArticleRepositoryInterface $articleRepository, ArticleResolverInterface $articleResolver, |
|
52 | - FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
40 | + private ArticleRepositoryInterface $articleRepository; |
|
41 | + private ArticleResolverInterface $articleResolver; |
|
42 | + private FormFactoryInterface $formFactory; |
|
43 | + private EventDispatcherInterface $eventDispatcher; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param ArticleRepositoryInterface $articleRepository |
|
47 | + * @param ArticleResolverInterface $articleResolver |
|
48 | + * @param FormFactoryInterface $formFactory |
|
49 | + * @param EventDispatcherInterface $eventDispatcher |
|
50 | + */ |
|
51 | + public function __construct(ArticleRepositoryInterface $articleRepository, ArticleResolverInterface $articleResolver, |
|
52 | + FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
53 | 53 | $this->articleRepository = $articleRepository; |
54 | 54 | $this->articleResolver = $articleResolver; |
55 | 55 | $this->formFactory = $formFactory; |
56 | 56 | $this->eventDispatcher = $eventDispatcher; |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @Route("/api/{version}/content/articles", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_article_comments") |
|
62 | - */ |
|
63 | - public function updateAction(Request $request): SingleResourceResponseInterface { |
|
60 | + /** |
|
61 | + * @Route("/api/{version}/content/articles", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_article_comments") |
|
62 | + */ |
|
63 | + public function updateAction(Request $request): SingleResourceResponseInterface { |
|
64 | 64 | $repository = $this->articleRepository; |
65 | 65 | $articleResolver = $this->articleResolver; |
66 | 66 | $form = $this->formFactory->createNamed('', ArticleCommentsType::class, [], ['method' => $request->getMethod()]); |
@@ -68,42 +68,42 @@ discard block |
||
68 | 68 | $form->handleRequest($request); |
69 | 69 | |
70 | 70 | if ($form->isSubmitted() && $form->isValid()) { |
71 | - $data = $form->getData(); |
|
72 | - $article = null; |
|
73 | - if (null !== $data['url']) { |
|
71 | + $data = $form->getData(); |
|
72 | + $article = null; |
|
73 | + if (null !== $data['url']) { |
|
74 | 74 | $article = strpos($data['url'], '/r/') ? $repository->findOneBySlug( |
75 | 75 | str_replace('/r/', '', $this->getFragmentFromUrl($data['url'], 'path')) |
76 | 76 | ) : $articleResolver->resolve($data['url']); |
77 | - } elseif (null !== $data['id']) { |
|
77 | + } elseif (null !== $data['id']) { |
|
78 | 78 | $article = $repository->findOneBy(['id' => $data['id']]); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - if (null === $article) { |
|
81 | + if (null === $article) { |
|
82 | 82 | throw new NotFoundHttpException('Article was not found'); |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - $article->setCommentsCount((int)$data['commentsCount']); |
|
86 | - $article->cancelTimestampable(); |
|
87 | - $repository->flush(); |
|
85 | + $article->setCommentsCount((int)$data['commentsCount']); |
|
86 | + $article->cancelTimestampable(); |
|
87 | + $repository->flush(); |
|
88 | 88 | |
89 | - $this->eventDispatcher->dispatch(new ArticleEvent( |
|
90 | - $article, |
|
91 | - $article->getPackage(), |
|
92 | - ArticleEvents::POST_UPDATE |
|
93 | - ), ArticleEvents::POST_UPDATE); |
|
89 | + $this->eventDispatcher->dispatch(new ArticleEvent( |
|
90 | + $article, |
|
91 | + $article->getPackage(), |
|
92 | + ArticleEvents::POST_UPDATE |
|
93 | + ), ArticleEvents::POST_UPDATE); |
|
94 | 94 | |
95 | - return new SingleResourceResponse($article); |
|
95 | + return new SingleResourceResponse($article); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return new SingleResourceResponse($form, new ResponseContext(400)); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - private function getFragmentFromUrl(string $url, string $fragment): ?string { |
|
101 | + private function getFragmentFromUrl(string $url, string $fragment): ?string { |
|
102 | 102 | $fragments = parse_url($url); |
103 | 103 | if (!array_key_exists($fragment, $fragments)) { |
104 | - return null; |
|
104 | + return null; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return $fragments[$fragment]; |
108 | - } |
|
108 | + } |
|
109 | 109 | } |
@@ -82,7 +82,7 @@ |
||
82 | 82 | throw new NotFoundHttpException('Article was not found'); |
83 | 83 | } |
84 | 84 | |
85 | - $article->setCommentsCount((int)$data['commentsCount']); |
|
85 | + $article->setCommentsCount((int) $data['commentsCount']); |
|
86 | 86 | $article->cancelTimestampable(); |
87 | 87 | $repository->flush(); |
88 | 88 |
@@ -34,36 +34,36 @@ discard block |
||
34 | 34 | |
35 | 35 | class FbiaFeedController extends AbstractController { |
36 | 36 | |
37 | - private FormFactoryInterface $formFactory; |
|
38 | - private RepositoryInterface $facebookInstantArticlesFeedRepository; |
|
39 | - private FactoryInterface $facebookInstantArticlesFeedFactory; |
|
40 | - private EventDispatcherInterface $eventDispatcher; |
|
37 | + private FormFactoryInterface $formFactory; |
|
38 | + private RepositoryInterface $facebookInstantArticlesFeedRepository; |
|
39 | + private FactoryInterface $facebookInstantArticlesFeedFactory; |
|
40 | + private EventDispatcherInterface $eventDispatcher; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param FormFactoryInterface $formFactory |
|
44 | - * @param RepositoryInterface $facebookInstantArticlesFeedRepository |
|
45 | - * @param FactoryInterface $facebookInstantArticlesFeedFactory |
|
46 | - * @param EventDispatcherInterface $eventDispatcher |
|
47 | - */ |
|
48 | - public function __construct(FormFactoryInterface $formFactory, |
|
49 | - RepositoryInterface $facebookInstantArticlesFeedRepository, |
|
50 | - FactoryInterface $facebookInstantArticlesFeedFactory, |
|
51 | - EventDispatcherInterface $eventDispatcher) { |
|
42 | + /** |
|
43 | + * @param FormFactoryInterface $formFactory |
|
44 | + * @param RepositoryInterface $facebookInstantArticlesFeedRepository |
|
45 | + * @param FactoryInterface $facebookInstantArticlesFeedFactory |
|
46 | + * @param EventDispatcherInterface $eventDispatcher |
|
47 | + */ |
|
48 | + public function __construct(FormFactoryInterface $formFactory, |
|
49 | + RepositoryInterface $facebookInstantArticlesFeedRepository, |
|
50 | + FactoryInterface $facebookInstantArticlesFeedFactory, |
|
51 | + EventDispatcherInterface $eventDispatcher) { |
|
52 | 52 | $this->formFactory = $formFactory; |
53 | 53 | $this->facebookInstantArticlesFeedRepository = $facebookInstantArticlesFeedRepository; |
54 | 54 | $this->facebookInstantArticlesFeedFactory = $facebookInstantArticlesFeedFactory; |
55 | 55 | $this->eventDispatcher = $eventDispatcher; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @Route("/api/{version}/facebook/instantarticles/feed/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_instant_articles_feed") |
|
61 | - */ |
|
62 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
59 | + /** |
|
60 | + * @Route("/api/{version}/facebook/instantarticles/feed/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_instant_articles_feed") |
|
61 | + */ |
|
62 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
63 | 63 | $repository = $this->facebookInstantArticlesFeedRepository; |
64 | 64 | $sort = $request->query->all('sorting'); |
65 | 65 | if (empty($sort)) { |
66 | - $sort = ['createdAt' => 'desc']; |
|
66 | + $sort = ['createdAt' => 'desc']; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $items = $repository->getPaginatedByCriteria( |
@@ -74,33 +74,33 @@ discard block |
||
74 | 74 | ); |
75 | 75 | |
76 | 76 | return new ResourcesListResponse($items); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @Route("/api/{version}/facebook/instantarticles/feed/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_instant_articles_feed") |
|
81 | - */ |
|
82 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
79 | + /** |
|
80 | + * @Route("/api/{version}/facebook/instantarticles/feed/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_instant_articles_feed") |
|
81 | + */ |
|
82 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
83 | 83 | /* @var FacebookInstantArticlesFeedInterface $feed */ |
84 | 84 | $feed = $this->facebookInstantArticlesFeedFactory->create(); |
85 | 85 | $form = $this->formFactory->createNamed('', FacebookInstantArticlesFeedType::class, $feed, ['method' => $request->getMethod()]); |
86 | 86 | |
87 | 87 | $form->handleRequest($request); |
88 | 88 | if ($form->isSubmitted() && $form->isValid()) { |
89 | - $this->checkIfFeedExists($feed->getContentBucket(), $feed->getFacebookPage()); |
|
90 | - $this->facebookInstantArticlesFeedRepository->add($feed); |
|
89 | + $this->checkIfFeedExists($feed->getContentBucket(), $feed->getFacebookPage()); |
|
90 | + $this->facebookInstantArticlesFeedRepository->add($feed); |
|
91 | 91 | |
92 | - return new SingleResourceResponse($feed, new ResponseContext(201)); |
|
92 | + return new SingleResourceResponse($feed, new ResponseContext(201)); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | return new SingleResourceResponse($form, new ResponseContext(400)); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - private function checkIfFeedExists($contentBucket, $facebookPage) { |
|
98 | + private function checkIfFeedExists($contentBucket, $facebookPage) { |
|
99 | 99 | if (null !== $this->facebookInstantArticlesFeedRepository->findOneBy([ |
100 | 100 | 'contentBucket' => $contentBucket, |
101 | 101 | 'facebookPage' => $facebookPage, |
102 | 102 | ])) { |
103 | - throw new ConflictHttpException('Feed for that page and content bucket already exists!'); |
|
103 | + throw new ConflictHttpException('Feed for that page and content bucket already exists!'); |
|
104 | + } |
|
104 | 105 | } |
105 | - } |
|
106 | 106 | } |
@@ -34,86 +34,86 @@ discard block |
||
34 | 34 | |
35 | 35 | class RuleController extends FOSRestController { |
36 | 36 | |
37 | - private FormFactoryInterface $formFactory; |
|
38 | - private EntityManagerInterface $entityManager; |
|
39 | - private RuleRepositoryInterface $ruleRepository; |
|
40 | - private FactoryInterface $ruleFactory; |
|
41 | - private EventDispatcherInterface $eventDispatcher; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param FormFactoryInterface $formFactory |
|
45 | - * @param EntityManagerInterface $entityManager |
|
46 | - * @param RuleRepositoryInterface $ruleRepository |
|
47 | - * @param FactoryInterface $ruleFactory |
|
48 | - * @param EventDispatcherInterface $eventDispatcher |
|
49 | - */ |
|
50 | - public function __construct(FormFactoryInterface $formFactory, EntityManagerInterface $entityManager, |
|
51 | - RuleRepositoryInterface $ruleRepository, FactoryInterface $ruleFactory, |
|
52 | - EventDispatcherInterface $eventDispatcher) { |
|
37 | + private FormFactoryInterface $formFactory; |
|
38 | + private EntityManagerInterface $entityManager; |
|
39 | + private RuleRepositoryInterface $ruleRepository; |
|
40 | + private FactoryInterface $ruleFactory; |
|
41 | + private EventDispatcherInterface $eventDispatcher; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param FormFactoryInterface $formFactory |
|
45 | + * @param EntityManagerInterface $entityManager |
|
46 | + * @param RuleRepositoryInterface $ruleRepository |
|
47 | + * @param FactoryInterface $ruleFactory |
|
48 | + * @param EventDispatcherInterface $eventDispatcher |
|
49 | + */ |
|
50 | + public function __construct(FormFactoryInterface $formFactory, EntityManagerInterface $entityManager, |
|
51 | + RuleRepositoryInterface $ruleRepository, FactoryInterface $ruleFactory, |
|
52 | + EventDispatcherInterface $eventDispatcher) { |
|
53 | 53 | $this->formFactory = $formFactory; |
54 | 54 | $this->entityManager = $entityManager; |
55 | 55 | $this->ruleRepository = $ruleRepository; |
56 | 56 | $this->ruleFactory = $ruleFactory; |
57 | 57 | $this->eventDispatcher = $eventDispatcher; |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_rule") |
|
63 | - */ |
|
64 | - public function listAction(Request $request) { |
|
61 | + /** |
|
62 | + * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_rule") |
|
63 | + */ |
|
64 | + public function listAction(Request $request) { |
|
65 | 65 | $rules = $this->ruleRepository |
66 | 66 | ->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
67 | 67 | |
68 | 68 | if (0 === $rules->count()) { |
69 | - throw new NotFoundHttpException('No rules were found.'); |
|
69 | + throw new NotFoundHttpException('No rules were found.'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return new ResourcesListResponse($rules); |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @Route("/api/{version}/rules/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_rule") |
|
77 | - * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
78 | - */ |
|
79 | - public function getAction(RuleInterface $rule) { |
|
75 | + /** |
|
76 | + * @Route("/api/{version}/rules/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_rule") |
|
77 | + * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
78 | + */ |
|
79 | + public function getAction(RuleInterface $rule) { |
|
80 | 80 | return new SingleResourceResponse($rule); |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_rule") |
|
85 | - */ |
|
86 | - public function createAction(Request $request) { |
|
83 | + /** |
|
84 | + * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_rule") |
|
85 | + */ |
|
86 | + public function createAction(Request $request) { |
|
87 | 87 | $ruleRepository = $this->ruleRepository; |
88 | 88 | $rule = $this->ruleFactory->create(); |
89 | 89 | $form = $this->formFactory->createNamed('', RuleType::class, $rule); |
90 | 90 | $form->handleRequest($request); |
91 | 91 | |
92 | 92 | if ($form->isSubmitted() && $form->isValid()) { |
93 | - $ruleRepository->add($rule); |
|
93 | + $ruleRepository->add($rule); |
|
94 | 94 | |
95 | - return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
95 | + return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return new SingleResourceResponse($form, new ResponseContext(400)); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_rule", methods={"DELETE"}, requirements={"id"="\d+"}) |
|
103 | - * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
104 | - */ |
|
105 | - public function deleteAction(RuleInterface $rule) { |
|
101 | + /** |
|
102 | + * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_rule", methods={"DELETE"}, requirements={"id"="\d+"}) |
|
103 | + * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
104 | + */ |
|
105 | + public function deleteAction(RuleInterface $rule) { |
|
106 | 106 | $ruleRepository = $this->ruleRepository; |
107 | 107 | $ruleRepository->remove($rule); |
108 | 108 | |
109 | 109 | return new SingleResourceResponse(null, new ResponseContext(204)); |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_rule", requirements={"id"="\d+"}) |
|
114 | - * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
115 | - */ |
|
116 | - public function updateAction(Request $request, RuleInterface $rule) { |
|
112 | + /** |
|
113 | + * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_rule", requirements={"id"="\d+"}) |
|
114 | + * @ParamConverter("rule", class="SWP\Bundle\CoreBundle\Model\Rule") |
|
115 | + */ |
|
116 | + public function updateAction(Request $request, RuleInterface $rule) { |
|
117 | 117 | $objectManager = $this->entityManager; |
118 | 118 | |
119 | 119 | $form = $this->formFactory->createNamed('', RuleType::class, $rule, [ |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | |
123 | 123 | $form->handleRequest($request); |
124 | 124 | if ($form->isSubmitted() && $form->isValid()) { |
125 | - $objectManager->flush(); |
|
126 | - $objectManager->refresh($rule); |
|
125 | + $objectManager->flush(); |
|
126 | + $objectManager->refresh($rule); |
|
127 | 127 | |
128 | - return new SingleResourceResponse($rule); |
|
128 | + return new SingleResourceResponse($rule); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return new SingleResourceResponse($form, new ResponseContext(400)); |
132 | - } |
|
132 | + } |
|
133 | 133 | } |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | use Symfony\Component\Routing\Annotation\Route; |
14 | 14 | |
15 | 15 | class ExternalOauthController extends Controller { |
16 | - public const PUBLISHER_JWT_COOKIE = 'publisher_jwt'; |
|
16 | + public const PUBLISHER_JWT_COOKIE = 'publisher_jwt'; |
|
17 | 17 | |
18 | - private ClientRegistry $clientRegistry; |
|
18 | + private ClientRegistry $clientRegistry; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param ClientRegistry $clientRegistry |
|
22 | - */ |
|
23 | - public function __construct(ClientRegistry $clientRegistry) { |
|
20 | + /** |
|
21 | + * @param ClientRegistry $clientRegistry |
|
22 | + */ |
|
23 | + public function __construct(ClientRegistry $clientRegistry) { |
|
24 | 24 | $this->clientRegistry = $clientRegistry; |
25 | - } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @Route("/connect/oauth", name="connect_oauth_start") |
|
29 | - */ |
|
30 | - public function connectAction(Request $request): Response { |
|
27 | + /** |
|
28 | + * @Route("/connect/oauth", name="connect_oauth_start") |
|
29 | + */ |
|
30 | + public function connectAction(Request $request): Response { |
|
31 | 31 | $referer = $request->headers->get('referer'); |
32 | 32 | |
33 | 33 | return $this->clientRegistry |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | ->redirect([ |
36 | 36 | 'openid', 'email', 'profile', |
37 | 37 | ], ['state' => $referer]); |
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * This is where the user is redirected after being succesfully authenticated by the OAuth server. |
|
42 | - * |
|
43 | - * @Route("/connect/oauth/check", name="connect_oauth_check") |
|
44 | - */ |
|
45 | - public function connectCheckAction(Request $request, JWTTokenManagerInterface $jwtTokenManager): Response { |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * This is where the user is redirected after being succesfully authenticated by the OAuth server. |
|
42 | + * |
|
43 | + * @Route("/connect/oauth/check", name="connect_oauth_check") |
|
44 | + */ |
|
45 | + public function connectCheckAction(Request $request, JWTTokenManagerInterface $jwtTokenManager): Response { |
|
46 | 46 | // If we didn't log in, something went wrong. Throw an exception! |
47 | 47 | if (!($user = $this->getUser())) { |
48 | - $response = $this->render('bundles/TwigBundle/Exception/error403.html.twig'); |
|
49 | - $response->setStatusCode(403); |
|
48 | + $response = $this->render('bundles/TwigBundle/Exception/error403.html.twig'); |
|
49 | + $response->setStatusCode(403); |
|
50 | 50 | |
51 | - return $response; |
|
51 | + return $response; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $state = $request->query->get('state'); |
@@ -57,5 +57,5 @@ discard block |
||
57 | 57 | $response->headers->setCookie(Cookie::create(self::PUBLISHER_JWT_COOKIE, $jwtTokenManager->create($user))); |
58 | 58 | |
59 | 59 | return $response; |
60 | - } |
|
60 | + } |
|
61 | 61 | } |
@@ -123,7 +123,7 @@ |
||
123 | 123 | $route = $this->findRouteOr404($routeId); |
124 | 124 | |
125 | 125 | /** @var string $content */ |
126 | - $content = (string)$request->getContent(); |
|
126 | + $content = (string) $request->getContent(); |
|
127 | 127 | $dispatcher = $this->eventDispatcher; |
128 | 128 | $package = $this->dataTransformer->transform($content); |
129 | 129 | $dispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
@@ -47,36 +47,36 @@ discard block |
||
47 | 47 | |
48 | 48 | class PackagePreviewController extends Controller { |
49 | 49 | |
50 | - private EventDispatcherInterface $eventDispatcher; |
|
51 | - private DataTransformerInterface $dataTransformer; |
|
52 | - private PackageRepositoryInterface $packageRepository; |
|
53 | - private RouteRepositoryInterface $routeRepository; |
|
54 | - private RepositoryInterface $packagePreviewTokenRepository; |
|
55 | - private PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory; |
|
56 | - private TemplateNameResolverInterface $templateNameResolver; |
|
57 | - private ArticlePreviewerInterface $articlePreviewer; |
|
58 | - private ArticlePreviewContextInterface $articlePreviewContext; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param EventDispatcherInterface $eventDispatcher |
|
62 | - * @param DataTransformerInterface $dataTransformer |
|
63 | - * @param PackageRepositoryInterface $packageRepository |
|
64 | - * @param RouteRepositoryInterface $routeRepository |
|
65 | - * @param RepositoryInterface $packagePreviewTokenRepository |
|
66 | - * @param PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory |
|
67 | - * @param TemplateNameResolverInterface $templateNameResolver |
|
68 | - * @param ArticlePreviewerInterface $articlePreviewer |
|
69 | - * @param ArticlePreviewContextInterface $articlePreviewContext |
|
70 | - */ |
|
71 | - public function __construct(EventDispatcherInterface $eventDispatcher, |
|
72 | - DataTransformerInterface $dataTransformer, |
|
73 | - PackageRepositoryInterface $packageRepository, |
|
74 | - RouteRepositoryInterface $routeRepository, |
|
75 | - RepositoryInterface $packagePreviewTokenRepository, |
|
76 | - PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory, |
|
77 | - TemplateNameResolverInterface $templateNameResolver, |
|
78 | - ArticlePreviewerInterface $articlePreviewer, |
|
79 | - ArticlePreviewContextInterface $articlePreviewContext) { |
|
50 | + private EventDispatcherInterface $eventDispatcher; |
|
51 | + private DataTransformerInterface $dataTransformer; |
|
52 | + private PackageRepositoryInterface $packageRepository; |
|
53 | + private RouteRepositoryInterface $routeRepository; |
|
54 | + private RepositoryInterface $packagePreviewTokenRepository; |
|
55 | + private PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory; |
|
56 | + private TemplateNameResolverInterface $templateNameResolver; |
|
57 | + private ArticlePreviewerInterface $articlePreviewer; |
|
58 | + private ArticlePreviewContextInterface $articlePreviewContext; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param EventDispatcherInterface $eventDispatcher |
|
62 | + * @param DataTransformerInterface $dataTransformer |
|
63 | + * @param PackageRepositoryInterface $packageRepository |
|
64 | + * @param RouteRepositoryInterface $routeRepository |
|
65 | + * @param RepositoryInterface $packagePreviewTokenRepository |
|
66 | + * @param PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory |
|
67 | + * @param TemplateNameResolverInterface $templateNameResolver |
|
68 | + * @param ArticlePreviewerInterface $articlePreviewer |
|
69 | + * @param ArticlePreviewContextInterface $articlePreviewContext |
|
70 | + */ |
|
71 | + public function __construct(EventDispatcherInterface $eventDispatcher, |
|
72 | + DataTransformerInterface $dataTransformer, |
|
73 | + PackageRepositoryInterface $packageRepository, |
|
74 | + RouteRepositoryInterface $routeRepository, |
|
75 | + RepositoryInterface $packagePreviewTokenRepository, |
|
76 | + PackagePreviewTokenFactoryInterface $packagePreviewTokenFactory, |
|
77 | + TemplateNameResolverInterface $templateNameResolver, |
|
78 | + ArticlePreviewerInterface $articlePreviewer, |
|
79 | + ArticlePreviewContextInterface $articlePreviewContext) { |
|
80 | 80 | $this->eventDispatcher = $eventDispatcher; |
81 | 81 | $this->dataTransformer = $dataTransformer; |
82 | 82 | $this->packageRepository = $packageRepository; |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | $this->templateNameResolver = $templateNameResolver; |
87 | 87 | $this->articlePreviewer = $articlePreviewer; |
88 | 88 | $this->articlePreviewContext = $articlePreviewContext; |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @Route("/preview/package/{routeId}/{id}", options={"expose"=true}, requirements={"id"="\d+", "routeId"="\d+", "token"=".+"}, methods={"GET"}, name="swp_package_preview") |
|
94 | - */ |
|
95 | - public function previewAction(int $routeId, $id) { |
|
92 | + /** |
|
93 | + * @Route("/preview/package/{routeId}/{id}", options={"expose"=true}, requirements={"id"="\d+", "routeId"="\d+", "token"=".+"}, methods={"GET"}, name="swp_package_preview") |
|
94 | + */ |
|
95 | + public function previewAction(int $routeId, $id) { |
|
96 | 96 | /** @var RouteInterface $route */ |
97 | 97 | $route = $this->findRouteOr404($routeId); |
98 | 98 | /** @var PackageInterface $package */ |
@@ -106,22 +106,22 @@ discard block |
||
106 | 106 | $this->eventDispatcher->dispatch(new GenericEvent($articlePreview), ArticleEvents::PREVIEW); |
107 | 107 | |
108 | 108 | if (null !== ($url = $articlePreview->getPreviewUrl())) { |
109 | - return new RedirectResponse($url); |
|
109 | + return new RedirectResponse($url); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $route = $this->ensureRouteTemplateExists($route, $article); |
113 | 113 | |
114 | 114 | try { |
115 | - return $this->render($route->getArticlesTemplateName()); |
|
115 | + return $this->render($route->getArticlesTemplateName()); |
|
116 | 116 | } catch (\Exception $e) { |
117 | - throw $this->createNotFoundException(sprintf('Template for route with id "%d" (%s) not found!', $route->getId(), $route->getName())); |
|
117 | + throw $this->createNotFoundException(sprintf('Template for route with id "%d" (%s) not found!', $route->getId(), $route->getName())); |
|
118 | + } |
|
118 | 119 | } |
119 | - } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @FOSRoute("/api/{version}/preview/package/generate_token/{routeId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_preview_package_token", requirements={"routeId"="\d+"}) |
|
123 | - */ |
|
124 | - public function generateTokenAction(Request $request, int $routeId): SingleResourceResponseInterface { |
|
121 | + /** |
|
122 | + * @FOSRoute("/api/{version}/preview/package/generate_token/{routeId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_preview_package_token", requirements={"routeId"="\d+"}) |
|
123 | + */ |
|
124 | + public function generateTokenAction(Request $request, int $routeId): SingleResourceResponseInterface { |
|
125 | 125 | $route = $this->findRouteOr404($routeId); |
126 | 126 | |
127 | 127 | /** @var string $content */ |
@@ -134,27 +134,27 @@ discard block |
||
134 | 134 | $existingPreviewToken = $tokenRepository->findOneBy(['route' => $route]); |
135 | 135 | |
136 | 136 | if (null === $existingPreviewToken) { |
137 | - $packagePreviewToken = $this->packagePreviewTokenFactory->createTokenizedWith($route, $content); |
|
137 | + $packagePreviewToken = $this->packagePreviewTokenFactory->createTokenizedWith($route, $content); |
|
138 | 138 | |
139 | - $tokenRepository->persist($packagePreviewToken); |
|
140 | - $tokenRepository->flush(); |
|
139 | + $tokenRepository->persist($packagePreviewToken); |
|
140 | + $tokenRepository->flush(); |
|
141 | 141 | |
142 | - return $this->returnResponseWithPreviewUrl($packagePreviewToken); |
|
142 | + return $this->returnResponseWithPreviewUrl($packagePreviewToken); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | $this->updatePackagePreviewTokenBody($content, $existingPreviewToken); |
146 | 146 | |
147 | 147 | return $this->returnResponseWithPreviewUrl($existingPreviewToken); |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @Route("/preview/publish/package/{token}", options={"expose"=true}, requirements={"token"=".+"}, methods={"GET"}, name="swp_package_preview_publish") |
|
152 | - */ |
|
153 | - public function publishPreviewAction(string $token) { |
|
150 | + /** |
|
151 | + * @Route("/preview/publish/package/{token}", options={"expose"=true}, requirements={"token"=".+"}, methods={"GET"}, name="swp_package_preview_publish") |
|
152 | + */ |
|
153 | + public function publishPreviewAction(string $token) { |
|
154 | 154 | $existingPreviewToken = $this->packagePreviewTokenRepository->findOneBy(['token' => $token]); |
155 | 155 | |
156 | 156 | if (null === $existingPreviewToken) { |
157 | - throw $this->createNotFoundException(sprintf('Token %s is not valid.', $token)); |
|
157 | + throw $this->createNotFoundException(sprintf('Token %s is not valid.', $token)); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $article = $this->getArticleForPreview($existingPreviewToken); |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | $route = $this->ensureRouteTemplateExists($route, $article); |
163 | 163 | |
164 | 164 | return $this->renderTemplateOr404($route); |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - private function updatePackagePreviewTokenBody(string $content, PackagePreviewTokenInterface $packagePreviewToken) { |
|
167 | + private function updatePackagePreviewTokenBody(string $content, PackagePreviewTokenInterface $packagePreviewToken) { |
|
168 | 168 | if (md5($content) !== md5($packagePreviewToken->getBody())) { |
169 | - $packagePreviewToken->setBody($content); |
|
169 | + $packagePreviewToken->setBody($content); |
|
170 | 170 | |
171 | - $this->packagePreviewTokenRepository->flush(); |
|
171 | + $this->packagePreviewTokenRepository->flush(); |
|
172 | + } |
|
172 | 173 | } |
173 | - } |
|
174 | 174 | |
175 | - private function returnResponseWithPreviewUrl(PackagePreviewTokenInterface $packagePreviewToken): SingleResourceResponseInterface { |
|
175 | + private function returnResponseWithPreviewUrl(PackagePreviewTokenInterface $packagePreviewToken): SingleResourceResponseInterface { |
|
176 | 176 | $article = $this->getArticleForPreview($packagePreviewToken); |
177 | 177 | $articlePreview = new ArticlePreview(); |
178 | 178 | $articlePreview->setArticle($article); |
@@ -182,19 +182,19 @@ discard block |
||
182 | 182 | $url = $articlePreview->getPreviewUrl(); |
183 | 183 | |
184 | 184 | if (null === $url) { |
185 | - $url = $this->generateUrl( |
|
186 | - 'swp_package_preview_publish', |
|
187 | - ['token' => $packagePreviewToken->getToken()], |
|
188 | - UrlGeneratorInterface::ABSOLUTE_URL |
|
189 | - ); |
|
185 | + $url = $this->generateUrl( |
|
186 | + 'swp_package_preview_publish', |
|
187 | + ['token' => $packagePreviewToken->getToken()], |
|
188 | + UrlGeneratorInterface::ABSOLUTE_URL |
|
189 | + ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | return new SingleResourceResponse([ |
193 | 193 | 'preview_url' => $url, |
194 | 194 | ]); |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - private function getArticleForPreview(PackagePreviewTokenInterface $packagePreviewToken): ArticleInterface { |
|
197 | + private function getArticleForPreview(PackagePreviewTokenInterface $packagePreviewToken): ArticleInterface { |
|
198 | 198 | $dispatcher = $this->eventDispatcher; |
199 | 199 | $package = $this->dataTransformer->transform($packagePreviewToken->getBody()); |
200 | 200 | $dispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
@@ -205,40 +205,40 @@ discard block |
||
205 | 205 | $articlePreviewContext->setIsPreview(true); |
206 | 206 | |
207 | 207 | return $articlePreviewer->preview($package, $packagePreviewToken->getRoute()); |
208 | - } |
|
208 | + } |
|
209 | 209 | |
210 | - private function renderTemplateOr404(RouteInterface $route): Response { |
|
210 | + private function renderTemplateOr404(RouteInterface $route): Response { |
|
211 | 211 | try { |
212 | - return $this->render($templateName = $route->getArticlesTemplateName()); |
|
212 | + return $this->render($templateName = $route->getArticlesTemplateName()); |
|
213 | 213 | } catch (\InvalidArgumentException | LoaderError $e) { |
214 | - throw $this->createNotFoundException(sprintf('Template %s for route with id "%d" (%s) not found!', $templateName, $route->getId(), $route->getName())); |
|
214 | + throw $this->createNotFoundException(sprintf('Template %s for route with id "%d" (%s) not found!', $templateName, $route->getId(), $route->getName())); |
|
215 | + } |
|
215 | 216 | } |
216 | - } |
|
217 | 217 | |
218 | - private function ensureRouteTemplateExists(RouteInterface $route, ArticleInterface $article): RouteInterface { |
|
218 | + private function ensureRouteTemplateExists(RouteInterface $route, ArticleInterface $article): RouteInterface { |
|
219 | 219 | if (null === $route->getArticlesTemplateName()) { |
220 | - $templateNameResolver = $this->templateNameResolver; |
|
221 | - $route->setArticlesTemplateName($templateNameResolver->resolve($article)); |
|
220 | + $templateNameResolver = $this->templateNameResolver; |
|
221 | + $route->setArticlesTemplateName($templateNameResolver->resolve($article)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $route; |
225 | - } |
|
225 | + } |
|
226 | 226 | |
227 | - private function findRouteOr404(int $id): RouteInterface { |
|
227 | + private function findRouteOr404(int $id): RouteInterface { |
|
228 | 228 | /** @var RouteInterface $route */ |
229 | 229 | if (null === ($route = $this->routeRepository->findOneBy(['id' => $id]))) { |
230 | - throw $this->createNotFoundException(sprintf('Route with id: "%s" not found!', $id)); |
|
230 | + throw $this->createNotFoundException(sprintf('Route with id: "%s" not found!', $id)); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return $route; |
234 | - } |
|
234 | + } |
|
235 | 235 | |
236 | - private function findPackageOr404(string $id): PackageInterface { |
|
236 | + private function findPackageOr404(string $id): PackageInterface { |
|
237 | 237 | /** @var PackageInterface $package */ |
238 | 238 | if (null === ($package = $this->packageRepository->findOneBy(['id' => $id]))) { |
239 | - throw $this->createNotFoundException(sprintf('Package with id: "%s" not found!', $id)); |
|
239 | + throw $this->createNotFoundException(sprintf('Package with id: "%s" not found!', $id)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | return $package; |
243 | - } |
|
243 | + } |
|
244 | 244 | } |
@@ -35,38 +35,38 @@ discard block |
||
35 | 35 | |
36 | 36 | class FbApplicationController extends Controller { |
37 | 37 | |
38 | - private FormFactoryInterface $formFactory; |
|
39 | - private RepositoryInterface $facebookAppRepository; |
|
40 | - private RepositoryInterface $facebookPageRepository; |
|
41 | - private Factory $facebookAppFactory; |
|
42 | - private EventDispatcherInterface $eventDispatcher; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param FormFactoryInterface $formFactory |
|
46 | - * @param RepositoryInterface $facebookAppRepository |
|
47 | - * @param RepositoryInterface $facebookPageRepository |
|
48 | - * @param Factory $facebookAppFactory |
|
49 | - * @param EventDispatcherInterface $eventDispatcher |
|
50 | - */ |
|
51 | - public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $facebookAppRepository, |
|
52 | - RepositoryInterface $facebookPageRepository, Factory $facebookAppFactory, |
|
53 | - EventDispatcherInterface $eventDispatcher) { |
|
38 | + private FormFactoryInterface $formFactory; |
|
39 | + private RepositoryInterface $facebookAppRepository; |
|
40 | + private RepositoryInterface $facebookPageRepository; |
|
41 | + private Factory $facebookAppFactory; |
|
42 | + private EventDispatcherInterface $eventDispatcher; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param FormFactoryInterface $formFactory |
|
46 | + * @param RepositoryInterface $facebookAppRepository |
|
47 | + * @param RepositoryInterface $facebookPageRepository |
|
48 | + * @param Factory $facebookAppFactory |
|
49 | + * @param EventDispatcherInterface $eventDispatcher |
|
50 | + */ |
|
51 | + public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $facebookAppRepository, |
|
52 | + RepositoryInterface $facebookPageRepository, Factory $facebookAppFactory, |
|
53 | + EventDispatcherInterface $eventDispatcher) { |
|
54 | 54 | $this->formFactory = $formFactory; |
55 | 55 | $this->facebookAppRepository = $facebookAppRepository; |
56 | 56 | $this->facebookPageRepository = $facebookPageRepository; |
57 | 57 | $this->facebookAppFactory = $facebookAppFactory; |
58 | 58 | $this->eventDispatcher = $eventDispatcher; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_applications") |
|
64 | - */ |
|
65 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
62 | + /** |
|
63 | + * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_applications") |
|
64 | + */ |
|
65 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
66 | 66 | $repository = $this->facebookAppRepository; |
67 | 67 | $sort = $request->query->all('sorting'); |
68 | 68 | if (empty($sort)) { |
69 | - $sort = ['id' => 'asc']; |
|
69 | + $sort = ['id' => 'asc']; |
|
70 | 70 | } |
71 | 71 | $items = $repository->getPaginatedByCriteria( |
72 | 72 | $this->eventDispatcher, |
@@ -76,51 +76,51 @@ discard block |
||
76 | 76 | ); |
77 | 77 | |
78 | 78 | return new ResourcesListResponse($items); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_applications") |
|
83 | - */ |
|
84 | - public function createAction(Request $request) { |
|
81 | + /** |
|
82 | + * @Route("/api/{version}/facebook/applications/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_applications") |
|
83 | + */ |
|
84 | + public function createAction(Request $request) { |
|
85 | 85 | /* @var FacebookApplication $feed */ |
86 | 86 | $application = $this->facebookAppFactory->create(); |
87 | 87 | $form = $this->formFactory->createNamed('', FacebookApplicationType::class, $application, ['method' => $request->getMethod()]); |
88 | 88 | |
89 | 89 | $form->handleRequest($request); |
90 | 90 | if ($form->isSubmitted() && $form->isValid()) { |
91 | - $this->checkIfApplicationExists($application); |
|
92 | - $this->facebookAppRepository->add($application); |
|
91 | + $this->checkIfApplicationExists($application); |
|
92 | + $this->facebookAppRepository->add($application); |
|
93 | 93 | |
94 | - return new SingleResourceResponse($application, new ResponseContext(201)); |
|
94 | + return new SingleResourceResponse($application, new ResponseContext(201)); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return new SingleResourceResponse($form, new ResponseContext(400)); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @Route("/api/{version}/facebook/applications/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_applications") |
|
102 | - */ |
|
103 | - public function deleteAction($id) { |
|
100 | + /** |
|
101 | + * @Route("/api/{version}/facebook/applications/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_applications") |
|
102 | + */ |
|
103 | + public function deleteAction($id) { |
|
104 | 104 | $repository = $this->facebookAppRepository; |
105 | 105 | if (null === $application = $repository->findOneBy(['id' => $id])) { |
106 | - throw new NotFoundHttpException('There is no Application with provided id!'); |
|
106 | + throw new NotFoundHttpException('There is no Application with provided id!'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | if (null !== $page = $this->facebookPageRepository->findOneBy(['id' => $id])) { |
110 | - throw new ConflictHttpException(sprintf('This Application is used by page with id: %s!', $page->getId())); |
|
110 | + throw new ConflictHttpException(sprintf('This Application is used by page with id: %s!', $page->getId())); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $repository->remove($application); |
114 | 114 | |
115 | 115 | return new SingleResourceResponse(null, new ResponseContext(204)); |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - private function checkIfApplicationExists(ApplicationInterface $application) { |
|
118 | + private function checkIfApplicationExists(ApplicationInterface $application) { |
|
119 | 119 | if (null !== $this->facebookAppRepository->findOneBy([ |
120 | 120 | 'appId' => $application->getAppId(), |
121 | 121 | ]) |
122 | 122 | ) { |
123 | - throw new ConflictHttpException('This Application already exists!'); |
|
123 | + throw new ConflictHttpException('This Application already exists!'); |
|
124 | + } |
|
124 | 125 | } |
125 | - } |
|
126 | 126 | } |
@@ -37,98 +37,98 @@ discard block |
||
37 | 37 | use Symfony\Component\Security\Core\User\UserProviderInterface; |
38 | 38 | |
39 | 39 | class AuthController extends AbstractController { |
40 | - protected FormFactoryInterface $formFactory; |
|
41 | - protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
42 | - protected ApiKeyFactory $apiKeyFactory; |
|
43 | - protected LockFactory $lockFactory; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param FormFactoryInterface $formFactory |
|
47 | - * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
48 | - * @param ApiKeyFactory $apiKeyFactory |
|
49 | - * @param LockFactory $lockFactory |
|
50 | - */ |
|
51 | - public function __construct(FormFactoryInterface $formFactory, ApiKeyRepositoryInterface $apiKeyRepository, |
|
52 | - ApiKeyFactory $apiKeyFactory, LockFactory $lockFactory) { |
|
40 | + protected FormFactoryInterface $formFactory; |
|
41 | + protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
42 | + protected ApiKeyFactory $apiKeyFactory; |
|
43 | + protected LockFactory $lockFactory; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param FormFactoryInterface $formFactory |
|
47 | + * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
48 | + * @param ApiKeyFactory $apiKeyFactory |
|
49 | + * @param LockFactory $lockFactory |
|
50 | + */ |
|
51 | + public function __construct(FormFactoryInterface $formFactory, ApiKeyRepositoryInterface $apiKeyRepository, |
|
52 | + ApiKeyFactory $apiKeyFactory, LockFactory $lockFactory) { |
|
53 | 53 | $this->formFactory = $formFactory; |
54 | 54 | $this->apiKeyRepository = $apiKeyRepository; |
55 | 55 | $this->apiKeyFactory = $apiKeyFactory; |
56 | 56 | $this->lockFactory = $lockFactory; |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @Route("/api/{version}/auth/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_auth") |
|
62 | - */ |
|
63 | - public function authenticateAction(Request $request, UserProviderInterface $userProvider, |
|
64 | - UserPasswordHasherInterface $userPasswordEncoder) { |
|
60 | + /** |
|
61 | + * @Route("/api/{version}/auth/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_auth") |
|
62 | + */ |
|
63 | + public function authenticateAction(Request $request, UserProviderInterface $userProvider, |
|
64 | + UserPasswordHasherInterface $userPasswordEncoder) { |
|
65 | 65 | $form = $this->formFactory->createNamed('', UserAuthenticationType::class, []); |
66 | 66 | $form->handleRequest($request); |
67 | 67 | if ($form->isSubmitted() && $form->isValid()) { |
68 | - $formData = $form->getData(); |
|
68 | + $formData = $form->getData(); |
|
69 | 69 | |
70 | - try { |
|
70 | + try { |
|
71 | 71 | $user = $userProvider->loadUserByUsername($formData['username']); |
72 | - } catch (AuthenticationException $e) { |
|
72 | + } catch (AuthenticationException $e) { |
|
73 | 73 | $user = null; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
76 | + if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
77 | 77 | return $this->returnApiTokenResponse($user); |
78 | - } |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return new SingleResourceResponse([ |
82 | 82 | 'status' => 401, |
83 | 83 | 'message' => 'Unauthorized', |
84 | 84 | ], new ResponseContext(401)); |
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @Route("/api/{version}/auth/superdesk/", options={"expose"=true}, methods={"POST"}, defaults={"version"="v2"}, name="swp_api_auth_superdesk") |
|
89 | - */ |
|
90 | - public function authenticateWithSuperdeskAction( |
|
91 | - Request $request, |
|
92 | - LoggerInterface $logger, |
|
93 | - array $superdeskServers, |
|
94 | - UserProviderInterface $userProvider, |
|
95 | - UserManagerInterface $userManager |
|
96 | - ) { |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @Route("/api/{version}/auth/superdesk/", options={"expose"=true}, methods={"POST"}, defaults={"version"="v2"}, name="swp_api_auth_superdesk") |
|
89 | + */ |
|
90 | + public function authenticateWithSuperdeskAction( |
|
91 | + Request $request, |
|
92 | + LoggerInterface $logger, |
|
93 | + array $superdeskServers, |
|
94 | + UserProviderInterface $userProvider, |
|
95 | + UserManagerInterface $userManager |
|
96 | + ) { |
|
97 | 97 | $form = $this->formFactory->createNamed('', SuperdeskCredentialAuthenticationType::class, []); |
98 | 98 | $form->handleRequest($request); |
99 | 99 | if ($form->isSubmitted() && $form->isValid()) { |
100 | - $formData = $form->getData(); |
|
101 | - $authorizedSuperdeskHosts = $superdeskServers; |
|
102 | - $superdeskUser = null; |
|
103 | - $client = new GuzzleHttp\Client(); |
|
100 | + $formData = $form->getData(); |
|
101 | + $authorizedSuperdeskHosts = $superdeskServers; |
|
102 | + $superdeskUser = null; |
|
103 | + $client = new GuzzleHttp\Client(); |
|
104 | 104 | |
105 | - foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
105 | + foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
106 | 106 | try { |
107 | - $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
108 | - 'Authorization' => $formData['token'], |
|
109 | - ]); |
|
107 | + $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
108 | + 'Authorization' => $formData['token'], |
|
109 | + ]); |
|
110 | 110 | |
111 | - $apiResponse = $client->send($apiRequest); |
|
112 | - if (200 !== $apiResponse->getStatusCode()) { |
|
111 | + $apiResponse = $client->send($apiRequest); |
|
112 | + if (200 !== $apiResponse->getStatusCode()) { |
|
113 | 113 | $logger->warning(sprintf('[%s] Unsuccessful response from Superdesk Server: %s', $apiResponse->getStatusCode(), $apiResponse->getBody()->getContents())); |
114 | 114 | |
115 | 115 | continue; |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
119 | - if (is_array($content) && array_key_exists('user', $content)) { |
|
118 | + $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
119 | + if (is_array($content) && array_key_exists('user', $content)) { |
|
120 | 120 | $superdeskUser = $content['user']; |
121 | 121 | |
122 | 122 | break; |
123 | - } |
|
123 | + } |
|
124 | 124 | } catch (GuzzleHttp\Exception\ClientException $e) { |
125 | - $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
125 | + $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
126 | 126 | |
127 | - continue; |
|
127 | + continue; |
|
128 | + } |
|
128 | 129 | } |
129 | - } |
|
130 | 130 | |
131 | - if (null === $superdeskUser) { |
|
131 | + if (null === $superdeskUser) { |
|
132 | 132 | return new SingleResourceResponse([ |
133 | 133 | 'status' => 401, |
134 | 134 | 'message' => <<<'MESSAGE' |
@@ -136,18 +136,18 @@ discard block |
||
136 | 136 | Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
137 | 137 | MESSAGE, |
138 | 138 | ], new ResponseContext(401)); |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
142 | - if (null === $publisherUser) { |
|
141 | + $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
142 | + if (null === $publisherUser) { |
|
143 | 143 | try { |
144 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
144 | + $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
145 | 145 | } catch (AuthenticationException $e) { |
146 | - $publisherUser = null; |
|
146 | + $publisherUser = null; |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | |
150 | - if (null === $publisherUser) { |
|
150 | + if (null === $publisherUser) { |
|
151 | 151 | /** @var UserInterface $publisherUser */ |
152 | 152 | $publisherUser = $userManager->createUser(); |
153 | 153 | $publisherUser->setUsername($superdeskUser['username']); |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
158 | 158 | $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
159 | 159 | $userManager->updateUser($publisherUser); |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - if (null !== $publisherUser) { |
|
162 | + if (null !== $publisherUser) { |
|
163 | 163 | return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
164 | - } |
|
164 | + } |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return new SingleResourceResponse([ |
168 | 168 | 'status' => 401, |
169 | 169 | 'message' => 'Unauthorized', |
170 | 170 | ], new ResponseContext(401)); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
173 | + private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
174 | 174 | /** @var ApiKeyInterface $apiKey */ |
175 | 175 | $apiKey = $this->generateOrGetApiKey($user, $token); |
176 | 176 | |
@@ -181,36 +181,36 @@ discard block |
||
181 | 181 | ], |
182 | 182 | 'user' => $user, |
183 | 183 | ]); |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
186 | + private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
187 | 187 | $apiKey = null; |
188 | 188 | if (null !== $token) { |
189 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
189 | + $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
190 | 190 | } else { |
191 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
192 | - if (count($validKeys) > 0) { |
|
191 | + $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
192 | + if (count($validKeys) > 0) { |
|
193 | 193 | $apiKey = reset($validKeys); |
194 | - } |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | if (null === $apiKey) { |
198 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
198 | + $apiKey = $this->apiKeyFactory->create($user, $token); |
|
199 | 199 | |
200 | - try { |
|
200 | + try { |
|
201 | 201 | $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
202 | 202 | if (!$lock->acquire()) { |
203 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
203 | + throw new RuntimeException('Other api key is created right now for this user'); |
|
204 | 204 | } |
205 | 205 | $this->apiKeyRepository->add($apiKey); |
206 | 206 | $lock->release(); |
207 | - } catch (RuntimeException $e) { |
|
207 | + } catch (RuntimeException $e) { |
|
208 | 208 | sleep(2); |
209 | 209 | |
210 | 210 | return $this->generateOrGetApiKey($user, $token); |
211 | - } |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return $apiKey; |
215 | - } |
|
215 | + } |
|
216 | 216 | } |