@@ -42,30 +42,30 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | class TenantController extends FOSRestController { |
| 44 | 44 | |
| 45 | - private CachedTenantContextInterface $cachedTenantContext; |
|
| 46 | - private EventDispatcherInterface $eventDispatcher; |
|
| 47 | - private FormFactoryInterface $formFactory; |
|
| 48 | - private TenantRepositoryInterface $tenantRepository; |
|
| 49 | - private EntityManagerInterface $entityManager; |
|
| 50 | - private SettingsManagerInterface $settingsManager; |
|
| 51 | - private TenantFactoryInterface $tenantFactory; |
|
| 52 | - private ArticleRepositoryInterface $articleRepository; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
| 56 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 57 | - * @param FormFactoryInterface $formFactory |
|
| 58 | - * @param TenantRepositoryInterface $tenantRepository |
|
| 59 | - * @param EntityManagerInterface $entityManager |
|
| 60 | - * @param SettingsManagerInterface $settingsManager |
|
| 61 | - * @param TenantFactoryInterface $tenantFactory |
|
| 62 | - * @param ArticleRepositoryInterface $articleRepository |
|
| 63 | - */ |
|
| 64 | - public function __construct(CachedTenantContextInterface $cachedTenantContext, |
|
| 65 | - EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
| 66 | - TenantRepositoryInterface $tenantRepository, EntityManagerInterface $entityManager, |
|
| 67 | - SettingsManagerInterface $settingsManager, TenantFactoryInterface $tenantFactory, |
|
| 68 | - ArticleRepositoryInterface $articleRepository) { |
|
| 45 | + private CachedTenantContextInterface $cachedTenantContext; |
|
| 46 | + private EventDispatcherInterface $eventDispatcher; |
|
| 47 | + private FormFactoryInterface $formFactory; |
|
| 48 | + private TenantRepositoryInterface $tenantRepository; |
|
| 49 | + private EntityManagerInterface $entityManager; |
|
| 50 | + private SettingsManagerInterface $settingsManager; |
|
| 51 | + private TenantFactoryInterface $tenantFactory; |
|
| 52 | + private ArticleRepositoryInterface $articleRepository; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
| 56 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 57 | + * @param FormFactoryInterface $formFactory |
|
| 58 | + * @param TenantRepositoryInterface $tenantRepository |
|
| 59 | + * @param EntityManagerInterface $entityManager |
|
| 60 | + * @param SettingsManagerInterface $settingsManager |
|
| 61 | + * @param TenantFactoryInterface $tenantFactory |
|
| 62 | + * @param ArticleRepositoryInterface $articleRepository |
|
| 63 | + */ |
|
| 64 | + public function __construct(CachedTenantContextInterface $cachedTenantContext, |
|
| 65 | + EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
| 66 | + TenantRepositoryInterface $tenantRepository, EntityManagerInterface $entityManager, |
|
| 67 | + SettingsManagerInterface $settingsManager, TenantFactoryInterface $tenantFactory, |
|
| 68 | + ArticleRepositoryInterface $articleRepository) { |
|
| 69 | 69 | $this->cachedTenantContext = $cachedTenantContext; |
| 70 | 70 | $this->eventDispatcher = $eventDispatcher; |
| 71 | 71 | $this->formFactory = $formFactory; |
@@ -74,32 +74,32 @@ discard block |
||
| 74 | 74 | $this->settingsManager = $settingsManager; |
| 75 | 75 | $this->tenantFactory = $tenantFactory; |
| 76 | 76 | $this->articleRepository = $articleRepository; |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_tenants") |
|
| 82 | - */ |
|
| 83 | - public function listAction(Request $request) { |
|
| 80 | + /** |
|
| 81 | + * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_tenants") |
|
| 82 | + */ |
|
| 83 | + public function listAction(Request $request) { |
|
| 84 | 84 | $tenants = $this->getTenantRepository() |
| 85 | 85 | ->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
| 86 | 86 | $responseContext = new ResponseContext(); |
| 87 | 87 | $responseContext->setSerializationGroups(['Default', 'api', 'details_api']); |
| 88 | 88 | |
| 89 | 89 | return new ResourcesListResponse($tenants, $responseContext); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 94 | - */ |
|
| 95 | - public function getAction($code) { |
|
| 92 | + /** |
|
| 93 | + * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 94 | + */ |
|
| 95 | + public function getAction($code) { |
|
| 96 | 96 | return new SingleResourceResponse($this->findOr404($code)); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 101 | - */ |
|
| 102 | - public function deleteAction(Request $request, $code) { |
|
| 99 | + /** |
|
| 100 | + * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 101 | + */ |
|
| 102 | + public function deleteAction(Request $request, $code) { |
|
| 103 | 103 | $tenantContext = $this->cachedTenantContext; |
| 104 | 104 | $eventDispatcher = $this->eventDispatcher; |
| 105 | 105 | $currentTenant = $tenantContext->getTenant(); |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $forceRemove = $request->query->has('force'); |
| 111 | 111 | if (!$forceRemove) { |
| 112 | - $tenantContext->setTenant($tenant); |
|
| 113 | - $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
|
| 114 | - $articlesRepository = $this->articleRepository; |
|
| 115 | - $existingArticles = $articlesRepository->findAll(); |
|
| 116 | - if (0 !== \count($existingArticles)) { |
|
| 112 | + $tenantContext->setTenant($tenant); |
|
| 113 | + $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
|
| 114 | + $articlesRepository = $this->articleRepository; |
|
| 115 | + $existingArticles = $articlesRepository->findAll(); |
|
| 116 | + if (0 !== \count($existingArticles)) { |
|
| 117 | 117 | throw new ConflictHttpException('This tenant have articles attached to it.'); |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $repository->remove($tenant); |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
| 125 | 125 | |
| 126 | 126 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_tenant") |
|
| 131 | - */ |
|
| 132 | - public function createAction(Request $request) { |
|
| 129 | + /** |
|
| 130 | + * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_tenant") |
|
| 131 | + */ |
|
| 132 | + public function createAction(Request $request) { |
|
| 133 | 133 | $tenant = $this->tenantFactory->create(); |
| 134 | 134 | $tenantContext = $this->cachedTenantContext; |
| 135 | 135 | $tenantObjectManager = $this->entityManager; |
@@ -137,83 +137,83 @@ discard block |
||
| 137 | 137 | $form->handleRequest($request); |
| 138 | 138 | |
| 139 | 139 | if ($form->isSubmitted() && $form->isValid()) { |
| 140 | - $this->ensureTenantDontExists($tenant->getDomainName(), $tenant->getSubdomain()); |
|
| 141 | - if (null === $tenant->getOrganization()) { |
|
| 140 | + $this->ensureTenantDontExists($tenant->getDomainName(), $tenant->getSubdomain()); |
|
| 141 | + if (null === $tenant->getOrganization()) { |
|
| 142 | 142 | $organization = $tenantObjectManager->merge($tenantContext->getTenant()->getOrganization()); |
| 143 | 143 | $tenant->setOrganization($organization); |
| 144 | - } |
|
| 145 | - $this->getTenantRepository()->add($tenant); |
|
| 144 | + } |
|
| 145 | + $this->getTenantRepository()->add($tenant); |
|
| 146 | 146 | |
| 147 | - return new SingleResourceResponse($tenant, new ResponseContext(201)); |
|
| 147 | + return new SingleResourceResponse($tenant, new ResponseContext(201)); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 155 | - */ |
|
| 156 | - public function updateAction(Request $request, $code) { |
|
| 153 | + /** |
|
| 154 | + * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_tenant", requirements={"code"="[a-z0-9]+"}) |
|
| 155 | + */ |
|
| 156 | + public function updateAction(Request $request, $code) { |
|
| 157 | 157 | $tenant = $this->findOr404($code); |
| 158 | 158 | $form = $this->formFactory->createNamed('', TenantType::class, $tenant, ['method' => $request->getMethod()]); |
| 159 | 159 | $form->handleRequest($request); |
| 160 | 160 | |
| 161 | 161 | if ($form->isSubmitted() && $form->isValid()) { |
| 162 | - $formData = $request->request->all(); |
|
| 163 | - $tenant->setUpdatedAt(new DateTime('now')); |
|
| 164 | - $this->entityManager->flush(); |
|
| 162 | + $formData = $request->request->all(); |
|
| 163 | + $tenant->setUpdatedAt(new DateTime('now')); |
|
| 164 | + $this->entityManager->flush(); |
|
| 165 | 165 | |
| 166 | - $tenantContext = $this->cachedTenantContext; |
|
| 167 | - $tenantContext->setTenant($tenant); |
|
| 166 | + $tenantContext = $this->cachedTenantContext; |
|
| 167 | + $tenantContext->setTenant($tenant); |
|
| 168 | 168 | |
| 169 | - $settingsManager = $this->settingsManager; |
|
| 169 | + $settingsManager = $this->settingsManager; |
|
| 170 | 170 | |
| 171 | - if (array_key_exists('fbiaEnabled', $formData)) { |
|
| 171 | + if (array_key_exists('fbiaEnabled', $formData)) { |
|
| 172 | 172 | $settingsManager->set('fbia_enabled', (bool)$formData['fbiaEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
| 173 | - } |
|
| 174 | - if (array_key_exists('paywallEnabled', $formData)) { |
|
| 173 | + } |
|
| 174 | + if (array_key_exists('paywallEnabled', $formData)) { |
|
| 175 | 175 | $settingsManager->set('paywall_enabled', (bool)$formData['paywallEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
| 176 | - } |
|
| 177 | - if (array_key_exists('defaultLanguage', $formData)) { |
|
| 176 | + } |
|
| 177 | + if (array_key_exists('defaultLanguage', $formData)) { |
|
| 178 | 178 | $settingsManager->set('default_language', $formData['defaultLanguage'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
| 179 | - } |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - return new SingleResourceResponse($tenant); |
|
| 181 | + return new SingleResourceResponse($tenant); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param string $code |
|
| 189 | - * |
|
| 190 | - * @return mixed|TenantInterface|null |
|
| 191 | - * @throws NotFoundHttpException |
|
| 192 | - * |
|
| 193 | - */ |
|
| 194 | - private function findOr404($code) { |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param string $code |
|
| 189 | + * |
|
| 190 | + * @return mixed|TenantInterface|null |
|
| 191 | + * @throws NotFoundHttpException |
|
| 192 | + * |
|
| 193 | + */ |
|
| 194 | + private function findOr404($code) { |
|
| 195 | 195 | if (null === $tenant = $this->getTenantRepository()->findOneByCode($code)) { |
| 196 | - throw $this->createNotFoundException(sprintf('Tenant with code "%s" was not found.', $code)); |
|
| 196 | + throw $this->createNotFoundException(sprintf('Tenant with code "%s" was not found.', $code)); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | return $tenant; |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * @return mixed|TenantInterface|null |
|
| 204 | - */ |
|
| 205 | - private function ensureTenantDontExists(string $domain, string $subdomain = null) { |
|
| 202 | + /** |
|
| 203 | + * @return mixed|TenantInterface|null |
|
| 204 | + */ |
|
| 205 | + private function ensureTenantDontExists(string $domain, string $subdomain = null) { |
|
| 206 | 206 | if (null !== $tenant = $this->getTenantRepository()->findOneBySubdomainAndDomain($subdomain, $domain)) { |
| 207 | - throw new ConflictHttpException('Tenant for this host already exists.'); |
|
| 207 | + throw new ConflictHttpException('Tenant for this host already exists.'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | return $tenant; |
| 211 | - } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * @return object|\SWP\Bundle\MultiTenancyBundle\Doctrine\ORM\TenantRepository |
|
| 215 | - */ |
|
| 216 | - private function getTenantRepository() { |
|
| 213 | + /** |
|
| 214 | + * @return object|\SWP\Bundle\MultiTenancyBundle\Doctrine\ORM\TenantRepository |
|
| 215 | + */ |
|
| 216 | + private function getTenantRepository() { |
|
| 217 | 217 | return $this->tenantRepository; |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -169,10 +169,10 @@ |
||
| 169 | 169 | $settingsManager = $this->settingsManager; |
| 170 | 170 | |
| 171 | 171 | if (array_key_exists('fbiaEnabled', $formData)) { |
| 172 | - $settingsManager->set('fbia_enabled', (bool)$formData['fbiaEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
|
| 172 | + $settingsManager->set('fbia_enabled', (bool) $formData['fbiaEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
|
| 173 | 173 | } |
| 174 | 174 | if (array_key_exists('paywallEnabled', $formData)) { |
| 175 | - $settingsManager->set('paywall_enabled', (bool)$formData['paywallEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
|
| 175 | + $settingsManager->set('paywall_enabled', (bool) $formData['paywallEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
|
| 176 | 176 | } |
| 177 | 177 | if (array_key_exists('defaultLanguage', $formData)) { |
| 178 | 178 | $settingsManager->set('default_language', $formData['defaultLanguage'], ScopeContextInterface::SCOPE_TENANT, $tenant); |
@@ -35,39 +35,39 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | class FbPageController extends AbstractController { |
| 37 | 37 | |
| 38 | - private FormFactoryInterface $formFactory; |
|
| 39 | - private RepositoryInterface $facebookInstantArticlesFeedRepository; |
|
| 40 | - private RepositoryInterface $facebookPageRepository; |
|
| 41 | - private FactoryInterface $facebookPageFactory; |
|
| 42 | - private EventDispatcherInterface $eventDispatcher; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param FormFactoryInterface $formFactory |
|
| 46 | - * @param RepositoryInterface $facebookInstantArticlesFeedRepository |
|
| 47 | - * @param RepositoryInterface $facebookPageRepository |
|
| 48 | - * @param FactoryInterface $facebookPageFactory |
|
| 49 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 50 | - */ |
|
| 51 | - public function __construct(FormFactoryInterface $formFactory, |
|
| 52 | - RepositoryInterface $facebookInstantArticlesFeedRepository, |
|
| 53 | - RepositoryInterface $facebookPageRepository, FactoryInterface $facebookPageFactory, |
|
| 54 | - EventDispatcherInterface $eventDispatcher) { |
|
| 38 | + private FormFactoryInterface $formFactory; |
|
| 39 | + private RepositoryInterface $facebookInstantArticlesFeedRepository; |
|
| 40 | + private RepositoryInterface $facebookPageRepository; |
|
| 41 | + private FactoryInterface $facebookPageFactory; |
|
| 42 | + private EventDispatcherInterface $eventDispatcher; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param FormFactoryInterface $formFactory |
|
| 46 | + * @param RepositoryInterface $facebookInstantArticlesFeedRepository |
|
| 47 | + * @param RepositoryInterface $facebookPageRepository |
|
| 48 | + * @param FactoryInterface $facebookPageFactory |
|
| 49 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 50 | + */ |
|
| 51 | + public function __construct(FormFactoryInterface $formFactory, |
|
| 52 | + RepositoryInterface $facebookInstantArticlesFeedRepository, |
|
| 53 | + RepositoryInterface $facebookPageRepository, FactoryInterface $facebookPageFactory, |
|
| 54 | + EventDispatcherInterface $eventDispatcher) { |
|
| 55 | 55 | $this->formFactory = $formFactory; |
| 56 | 56 | $this->facebookInstantArticlesFeedRepository = $facebookInstantArticlesFeedRepository; |
| 57 | 57 | $this->facebookPageRepository = $facebookPageRepository; |
| 58 | 58 | $this->facebookPageFactory = $facebookPageFactory; |
| 59 | 59 | $this->eventDispatcher = $eventDispatcher; |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_pages") |
|
| 65 | - */ |
|
| 66 | - public function listAction(Request $request) { |
|
| 63 | + /** |
|
| 64 | + * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_pages") |
|
| 65 | + */ |
|
| 66 | + public function listAction(Request $request) { |
|
| 67 | 67 | $repository = $this->facebookPageRepository; |
| 68 | 68 | $sort = $request->query->all('sorting'); |
| 69 | 69 | if (empty($sort)) { |
| 70 | - $sort = ['id' => 'asc']; |
|
| 70 | + $sort = ['id' => 'asc']; |
|
| 71 | 71 | } |
| 72 | 72 | $items = $repository->getPaginatedByCriteria( |
| 73 | 73 | $this->eventDispatcher, |
@@ -77,51 +77,51 @@ discard block |
||
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | return new ResourcesListResponse($items); |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_pages") |
|
| 84 | - */ |
|
| 85 | - public function createAction(Request $request) { |
|
| 82 | + /** |
|
| 83 | + * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_pages") |
|
| 84 | + */ |
|
| 85 | + public function createAction(Request $request) { |
|
| 86 | 86 | /* @var FacebookPage $feed */ |
| 87 | 87 | $page = $this->facebookPageFactory->create(); |
| 88 | 88 | $form = $this->formFactory->createNamed('', FacebookPageType::class, $page, ['method' => $request->getMethod()]); |
| 89 | 89 | |
| 90 | 90 | $form->handleRequest($request); |
| 91 | 91 | if ($form->isSubmitted() && $form->isValid()) { |
| 92 | - $this->checkIfPageExists($page); |
|
| 93 | - $this->facebookPageRepository->add($page); |
|
| 92 | + $this->checkIfPageExists($page); |
|
| 93 | + $this->facebookPageRepository->add($page); |
|
| 94 | 94 | |
| 95 | - return new SingleResourceResponse($page, new ResponseContext(201)); |
|
| 95 | + return new SingleResourceResponse($page, 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}/facebook/pages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_pages") |
|
| 103 | - */ |
|
| 104 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
| 101 | + /** |
|
| 102 | + * @Route("/api/{version}/facebook/pages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_pages") |
|
| 103 | + */ |
|
| 104 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
| 105 | 105 | $repository = $this->facebookPageRepository; |
| 106 | 106 | if (null === $page = $this->facebookPageRepository->findOneBy(['id' => $id])) { |
| 107 | - throw new NotFoundHttpException('There is no Page with provided id!'); |
|
| 107 | + throw new NotFoundHttpException('There is no Page with provided id!'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if (null !== $feed = $this->facebookInstantArticlesFeedRepository->findOneBy(['facebookPage' => $id])) { |
| 111 | - throw new ConflictHttpException(sprintf('This Page is used by Instant Articles Feed with id: %s!', $feed->getId())); |
|
| 111 | + throw new ConflictHttpException(sprintf('This Page is used by Instant Articles Feed with id: %s!', $feed->getId())); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $repository->remove($page); |
| 115 | 115 | |
| 116 | 116 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - private function checkIfPageExists(PageInterface $page): void { |
|
| 119 | + private function checkIfPageExists(PageInterface $page): void { |
|
| 120 | 120 | if (null !== $this->facebookPageRepository->findOneBy([ |
| 121 | 121 | 'pageId' => $page->getPageId(), |
| 122 | 122 | ]) |
| 123 | 123 | ) { |
| 124 | - throw new ConflictHttpException('This Page already exists!'); |
|
| 124 | + throw new ConflictHttpException('This Page already exists!'); |
|
| 125 | + } |
|
| 125 | 126 | } |
| 126 | - } |
|
| 127 | 127 | } |
@@ -27,51 +27,51 @@ |
||
| 27 | 27 | |
| 28 | 28 | class RedirectingController extends AbstractController { |
| 29 | 29 | |
| 30 | - private RouterInterface $router; |
|
| 31 | - private ArticleRepositoryInterface $articleRepository; |
|
| 30 | + private RouterInterface $router; |
|
| 31 | + private ArticleRepositoryInterface $articleRepository; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param RouterInterface $router |
|
| 35 | - * @param ArticleRepositoryInterface $articleRepository |
|
| 36 | - */ |
|
| 37 | - public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { |
|
| 33 | + /** |
|
| 34 | + * @param RouterInterface $router |
|
| 35 | + * @param ArticleRepositoryInterface $articleRepository |
|
| 36 | + */ |
|
| 37 | + public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { |
|
| 38 | 38 | $this->router = $router; |
| 39 | 39 | $this->articleRepository = $articleRepository; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { |
|
| 43 | + public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { |
|
| 44 | 44 | try { |
| 45 | - $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
|
| 46 | - if (null === $existingArticle) { |
|
| 45 | + $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
|
| 46 | + if (null === $existingArticle) { |
|
| 47 | 47 | $existingArticle = $this->articleRepository->getArticleByPackageExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | } catch (NonUniqueResultException $e) { |
| 50 | - $existingArticle = null; |
|
| 50 | + $existingArticle = null; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
| 54 | - throw $this->createNotFoundException('Article with provided data was not found.'); |
|
| 54 | + throw $this->createNotFoundException('Article with provided data was not found.'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { |
|
| 60 | + public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { |
|
| 61 | 61 | $existingArticle = $this->articleRepository->findOneBySlug($slug); |
| 62 | 62 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
| 63 | - throw $this->createNotFoundException('Article not found.'); |
|
| 63 | + throw $this->createNotFoundException('Article not found.'); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - private function generateArticleUrl(Request $request, ArticleInterface $article): string { |
|
| 69 | + private function generateArticleUrl(Request $request, ArticleInterface $article): string { |
|
| 70 | 70 | $parameters = ['slug' => $article->getSlug()]; |
| 71 | 71 | if ($request->query->has('amp')) { |
| 72 | - $parameters['amp'] = 1; |
|
| 72 | + $parameters['amp'] = 1; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $this->router->generate($article->getRoute(), $parameters, UrlGeneratorInterface::ABSOLUTE_URL); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -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 | } |
@@ -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 | } |