@@ -28,22 +28,22 @@ discard block |
||
28 | 28 | |
29 | 29 | class ArticleSourceController extends AbstractController { |
30 | 30 | |
31 | - private EntityRepository $entityRepository; |
|
32 | - private EventDispatcherInterface $eventDispatcher; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param EntityRepository $entityRepository |
|
36 | - * @param EventDispatcherInterface $eventDispatcher |
|
37 | - */ |
|
38 | - public function __construct(EntityRepository $entityRepository, EventDispatcherInterface $eventDispatcher) { |
|
31 | + private EntityRepository $entityRepository; |
|
32 | + private EventDispatcherInterface $eventDispatcher; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param EntityRepository $entityRepository |
|
36 | + * @param EventDispatcherInterface $eventDispatcher |
|
37 | + */ |
|
38 | + public function __construct(EntityRepository $entityRepository, EventDispatcherInterface $eventDispatcher) { |
|
39 | 39 | $this->entityRepository = $entityRepository; |
40 | 40 | $this->eventDispatcher = $eventDispatcher; |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @Route("/api/{version}/content/sources/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_article_sources") |
|
45 | - */ |
|
46 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
43 | + /** |
|
44 | + * @Route("/api/{version}/content/sources/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_article_sources") |
|
45 | + */ |
|
46 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
47 | 47 | $sorting = $request->query->all('sorting'); |
48 | 48 | $lists = $this->entityRepository->getPaginatedByCriteria( |
49 | 49 | $this->eventDispatcher, |
@@ -52,5 +52,5 @@ discard block |
||
52 | 52 | new PaginationData($request)); |
53 | 53 | |
54 | 54 | return new ResourcesListResponse($lists); |
55 | - } |
|
55 | + } |
|
56 | 56 | } |
@@ -33,78 +33,78 @@ discard block |
||
33 | 33 | |
34 | 34 | class CurrentThemeController extends AbstractController { |
35 | 35 | |
36 | - private TenantAwareThemeContextInterface $tenantAwareThemeContext; |
|
37 | - private FormFactoryInterface $formFactory; |
|
38 | - private CachedTenantContextInterface $tenantContext; |
|
39 | - private SettingsManagerInterface $settingsManager; |
|
40 | - private ThemeLogoUploaderInterface $themeLogoUploader; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param TenantAwareThemeContextInterface $tenantAwareThemeContext |
|
44 | - * @param FormFactoryInterface $formFactory |
|
45 | - * @param CachedTenantContextInterface $tenantContext |
|
46 | - * @param SettingsManagerInterface $settingsManager |
|
47 | - * @param ThemeLogoUploaderInterface $themeLogoUploader |
|
48 | - */ |
|
49 | - public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, |
|
50 | - FormFactoryInterface $formFactory, |
|
51 | - CachedTenantContextInterface $tenantContext, |
|
52 | - SettingsManagerInterface $settingsManager, |
|
53 | - ThemeLogoUploaderInterface $themeLogoUploader) { |
|
36 | + private TenantAwareThemeContextInterface $tenantAwareThemeContext; |
|
37 | + private FormFactoryInterface $formFactory; |
|
38 | + private CachedTenantContextInterface $tenantContext; |
|
39 | + private SettingsManagerInterface $settingsManager; |
|
40 | + private ThemeLogoUploaderInterface $themeLogoUploader; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param TenantAwareThemeContextInterface $tenantAwareThemeContext |
|
44 | + * @param FormFactoryInterface $formFactory |
|
45 | + * @param CachedTenantContextInterface $tenantContext |
|
46 | + * @param SettingsManagerInterface $settingsManager |
|
47 | + * @param ThemeLogoUploaderInterface $themeLogoUploader |
|
48 | + */ |
|
49 | + public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, |
|
50 | + FormFactoryInterface $formFactory, |
|
51 | + CachedTenantContextInterface $tenantContext, |
|
52 | + SettingsManagerInterface $settingsManager, |
|
53 | + ThemeLogoUploaderInterface $themeLogoUploader) { |
|
54 | 54 | $this->tenantAwareThemeContext = $tenantAwareThemeContext; |
55 | 55 | $this->formFactory = $formFactory; |
56 | 56 | $this->tenantContext = $tenantContext; |
57 | 57 | $this->settingsManager = $settingsManager; |
58 | 58 | $this->themeLogoUploader = $themeLogoUploader; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @Route("/api/{version}/theme/logo_upload/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo_2") |
|
64 | - * @Route("/api/{version}/theme/logo_upload/{type}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo") |
|
65 | - */ |
|
66 | - public function uploadThemeLogoAction(Request $request, |
|
62 | + /** |
|
63 | + * @Route("/api/{version}/theme/logo_upload/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo_2") |
|
64 | + * @Route("/api/{version}/theme/logo_upload/{type}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo") |
|
65 | + */ |
|
66 | + public function uploadThemeLogoAction(Request $request, |
|
67 | 67 | string $type = ThemeLogoProviderInterface::SETTING_NAME_DEFAULT): SingleResourceResponseInterface { |
68 | 68 | $themeContext = $this->tenantAwareThemeContext; |
69 | 69 | |
70 | 70 | if (null === ($theme = $themeContext->getTheme())) { |
71 | - throw new \LogicException('Theme is not set!'); |
|
71 | + throw new \LogicException('Theme is not set!'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $form = $this->formFactory->createNamed('', ThemeLogoUploadType::class, $theme); |
75 | 75 | $form->handleRequest($request); |
76 | 76 | |
77 | 77 | if ($form->isSubmitted() && $form->isValid()) { |
78 | - $tenantContext = $this->tenantContext; |
|
79 | - $currentTenant = $tenantContext->getTenant(); |
|
78 | + $tenantContext = $this->tenantContext; |
|
79 | + $currentTenant = $tenantContext->getTenant(); |
|
80 | 80 | |
81 | - try { |
|
81 | + try { |
|
82 | 82 | $settingsManager = $this->settingsManager; |
83 | 83 | $setting = $settingsManager->get($type, ScopeContextInterface::SCOPE_THEME, $currentTenant); |
84 | 84 | $theme->setLogoPath($setting); |
85 | 85 | $themeLogoUploader = $this->themeLogoUploader; |
86 | 86 | $themeLogoUploader->upload($theme); |
87 | - } catch (\Exception $e) { |
|
87 | + } catch (\Exception $e) { |
|
88 | 88 | return new SingleResourceResponse(['message' => 'Could not upload logo.'], new ResponseContext(400)); |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - $settingsManager = $this->settingsManager; |
|
92 | - $setting = $settingsManager->set($type, $theme->getLogoPath(), ScopeContextInterface::SCOPE_THEME, $currentTenant); |
|
91 | + $settingsManager = $this->settingsManager; |
|
92 | + $setting = $settingsManager->set($type, $theme->getLogoPath(), ScopeContextInterface::SCOPE_THEME, $currentTenant); |
|
93 | 93 | |
94 | - return new SingleResourceResponse($setting, new ResponseContext(201)); |
|
94 | + return new SingleResourceResponse($setting, 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}/theme/settings/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_theme_settings_list") |
|
102 | - */ |
|
103 | - public function listSettingsAction(): SingleResourceResponseInterface { |
|
100 | + /** |
|
101 | + * @Route("/api/{version}/theme/settings/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_theme_settings_list") |
|
102 | + */ |
|
103 | + public function listSettingsAction(): SingleResourceResponseInterface { |
|
104 | 104 | $themeContext = $this->tenantAwareThemeContext; |
105 | 105 | |
106 | 106 | if (null === $themeContext->getTheme()) { |
107 | - throw new \LogicException('Theme is not set!'); |
|
107 | + throw new \LogicException('Theme is not set!'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $tenantContext = $this->tenantContext; |
@@ -112,5 +112,5 @@ discard block |
||
112 | 112 | $settings = $settingsManager->getByScopeAndOwner(ScopeContextInterface::SCOPE_THEME, $tenantContext->getTenant()); |
113 | 113 | |
114 | 114 | return new SingleResourceResponse($settings); |
115 | - } |
|
115 | + } |
|
116 | 116 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
81 | 81 | */ |
82 | 82 | public function getRelatedAction(string $id) { |
83 | - $package = $this->findOr404((int)$id); |
|
83 | + $package = $this->findOr404((int) $id); |
|
84 | 84 | |
85 | 85 | $relatedArticlesList = $this->getRelated($package); |
86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | private function getRelated(PackageInterface $package): RelatedArticleList { |
91 | - $relatedItemsGroups = $package->getItems()->filter(static function ($group) { |
|
91 | + $relatedItemsGroups = $package->getItems()->filter(static function($group) { |
|
92 | 92 | return ItemInterface::TYPE_TEXT === $group->getType(); |
93 | 93 | }); |
94 | 94 |
@@ -35,102 +35,102 @@ |
||
35 | 35 | use FOS\RestBundle\Controller\Annotations\Route; |
36 | 36 | |
37 | 37 | class RelatedArticleOrganizationController extends Controller { |
38 | - private EventDispatcherInterface $eventDispatcher; |
|
39 | - private DataTransformerInterface $dataTransformer; |
|
40 | - private CachedTenantContextInterface $cachedTenantContext; |
|
41 | - private PackageRepositoryInterface $packageRepository; |
|
42 | - private ArticleRepositoryInterface $articleRepository; |
|
43 | - private TenantRepositoryInterface $tenantRepository; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param EventDispatcherInterface $eventDispatcher |
|
47 | - * @param DataTransformerInterface $dataTransformer |
|
48 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | - * @param PackageRepositoryInterface $packageRepository |
|
50 | - * @param ArticleRepositoryInterface $articleRepository |
|
51 | - * @param TenantRepositoryInterface $tenantRepository |
|
52 | - */ |
|
53 | - public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | - DataTransformerInterface $dataTransformer, |
|
55 | - CachedTenantContextInterface $cachedTenantContext, |
|
56 | - PackageRepositoryInterface $packageRepository, |
|
57 | - ArticleRepositoryInterface $articleRepository, |
|
58 | - TenantRepositoryInterface $tenantRepository) { |
|
38 | + private EventDispatcherInterface $eventDispatcher; |
|
39 | + private DataTransformerInterface $dataTransformer; |
|
40 | + private CachedTenantContextInterface $cachedTenantContext; |
|
41 | + private PackageRepositoryInterface $packageRepository; |
|
42 | + private ArticleRepositoryInterface $articleRepository; |
|
43 | + private TenantRepositoryInterface $tenantRepository; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param EventDispatcherInterface $eventDispatcher |
|
47 | + * @param DataTransformerInterface $dataTransformer |
|
48 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | + * @param PackageRepositoryInterface $packageRepository |
|
50 | + * @param ArticleRepositoryInterface $articleRepository |
|
51 | + * @param TenantRepositoryInterface $tenantRepository |
|
52 | + */ |
|
53 | + public function __construct(EventDispatcherInterface $eventDispatcher, |
|
54 | + DataTransformerInterface $dataTransformer, |
|
55 | + CachedTenantContextInterface $cachedTenantContext, |
|
56 | + PackageRepositoryInterface $packageRepository, |
|
57 | + ArticleRepositoryInterface $articleRepository, |
|
58 | + TenantRepositoryInterface $tenantRepository) { |
|
59 | 59 | $this->eventDispatcher = $eventDispatcher; |
60 | 60 | $this->dataTransformer = $dataTransformer; |
61 | 61 | $this->cachedTenantContext = $cachedTenantContext; |
62 | 62 | $this->packageRepository = $packageRepository; |
63 | 63 | $this->articleRepository = $articleRepository; |
64 | 64 | $this->tenantRepository = $tenantRepository; |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | - */ |
|
71 | - public function postAction(Request $request) { |
|
68 | + /** |
|
69 | + * @Route("/api/{version}/organization/articles/related/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_organization_related_articles") |
|
70 | + */ |
|
71 | + public function postAction(Request $request) { |
|
72 | 72 | $content = $request->getContent(); |
73 | 73 | $package = $this->dataTransformer->transform($content); |
74 | 74 | $relatedArticlesList = $this->getRelated($package); |
75 | 75 | |
76 | 76 | return new SingleResourceResponse($relatedArticlesList); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | - */ |
|
82 | - public function getRelatedAction(string $id) { |
|
79 | + /** |
|
80 | + * @Route("/api/{version}/packages/{id}/related/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_packages_related_articles", requirements={"id"="\d+"}) |
|
81 | + */ |
|
82 | + public function getRelatedAction(string $id) { |
|
83 | 83 | $package = $this->findOr404((int)$id); |
84 | 84 | |
85 | 85 | $relatedArticlesList = $this->getRelated($package); |
86 | 86 | |
87 | 87 | return new SingleResourceResponse($relatedArticlesList); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - private function getRelated(PackageInterface $package): RelatedArticleList { |
|
90 | + private function getRelated(PackageInterface $package): RelatedArticleList { |
|
91 | 91 | $relatedItemsGroups = $package->getItems()->filter(static function ($group) { |
92 | - return ItemInterface::TYPE_TEXT === $group->getType(); |
|
92 | + return ItemInterface::TYPE_TEXT === $group->getType(); |
|
93 | 93 | }); |
94 | 94 | |
95 | 95 | $relatedArticlesList = new RelatedArticleList(); |
96 | 96 | |
97 | 97 | if (null === $package || (null !== $package && 0 === \count($relatedItemsGroups))) { |
98 | - return $relatedArticlesList; |
|
98 | + return $relatedArticlesList; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
102 | 102 | $articleRepository = $this->articleRepository; |
103 | 103 | |
104 | 104 | foreach ($relatedItemsGroups as $item) { |
105 | - if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
105 | + if (null === ($existingArticles = $articleRepository->findBy(['code' => $item->getGuid()]))) { |
|
106 | 106 | continue; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - $tenants = []; |
|
110 | - foreach ($existingArticles as $existingArticle) { |
|
109 | + $tenants = []; |
|
110 | + foreach ($existingArticles as $existingArticle) { |
|
111 | 111 | $tenantCode = $existingArticle->getTenantCode(); |
112 | 112 | $tenant = $this->tenantRepository->findOneByCode($tenantCode); |
113 | 113 | |
114 | 114 | $tenants[] = $tenant; |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | - $relatedArticleListItem->setTenants($tenants); |
|
119 | - $relatedArticleListItem->setTitle($item->getHeadline()); |
|
117 | + $relatedArticleListItem = new RelatedArticleListItem(); |
|
118 | + $relatedArticleListItem->setTenants($tenants); |
|
119 | + $relatedArticleListItem->setTitle($item->getHeadline()); |
|
120 | 120 | |
121 | - $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
121 | + $relatedArticlesList->addRelatedArticleItem($relatedArticleListItem); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $relatedArticlesList; |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - private function findOr404(int $id): PackageInterface { |
|
127 | + private function findOr404(int $id): PackageInterface { |
|
128 | 128 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
129 | 129 | $tenantContext = $this->cachedTenantContext; |
130 | 130 | if (null === $package = $this->packageRepository->findOneBy(['id' => $id, 'organization' => $tenantContext->getTenant()->getOrganization()])) { |
131 | - throw new NotFoundHttpException('Package was not found.'); |
|
131 | + throw new NotFoundHttpException('Package was not found.'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $package; |
135 | - } |
|
135 | + } |
|
136 | 136 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
57 | 57 | */ |
58 | 58 | public function listAction(Request $request): ResourcesListResponseInterface { |
59 | - return $this->listWebhooks($this->eventDispatcher,$this->webhookRepository, $request); |
|
59 | + return $this->listWebhooks($this->eventDispatcher, $this->webhookRepository, $request); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -28,77 +28,77 @@ |
||
28 | 28 | use FOS\RestBundle\Controller\Annotations\Route; |
29 | 29 | |
30 | 30 | class WebhookController extends AbstractAPIController { |
31 | - private WebhookRepositoryInterface $webhookRepository; |
|
32 | - private FormFactoryInterface $formFactory; |
|
33 | - private FactoryInterface $webhookFactory; |
|
34 | - private EntityManagerInterface $entityManager; |
|
35 | - private EventDispatcherInterface $eventDispatcher; |
|
31 | + private WebhookRepositoryInterface $webhookRepository; |
|
32 | + private FormFactoryInterface $formFactory; |
|
33 | + private FactoryInterface $webhookFactory; |
|
34 | + private EntityManagerInterface $entityManager; |
|
35 | + private EventDispatcherInterface $eventDispatcher; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param WebhookRepositoryInterface $webhookRepository |
|
39 | - * @param FormFactoryInterface $formFactory |
|
40 | - * @param FactoryInterface $webhookFactory |
|
41 | - * @param EntityManagerInterface $entityManager |
|
42 | - * @param EventDispatcherInterface $eventDispatcher |
|
43 | - */ |
|
44 | - public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
45 | - FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
46 | - EventDispatcherInterface $eventDispatcher) { |
|
37 | + /** |
|
38 | + * @param WebhookRepositoryInterface $webhookRepository |
|
39 | + * @param FormFactoryInterface $formFactory |
|
40 | + * @param FactoryInterface $webhookFactory |
|
41 | + * @param EntityManagerInterface $entityManager |
|
42 | + * @param EventDispatcherInterface $eventDispatcher |
|
43 | + */ |
|
44 | + public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
45 | + FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
46 | + EventDispatcherInterface $eventDispatcher) { |
|
47 | 47 | $this->webhookRepository = $webhookRepository; |
48 | 48 | $this->formFactory = $formFactory; |
49 | 49 | $this->webhookFactory = $webhookFactory; |
50 | 50 | $this->entityManager = $entityManager; |
51 | 51 | $this->eventDispatcher = $eventDispatcher; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
57 | - */ |
|
58 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
55 | + /** |
|
56 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
57 | + */ |
|
58 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
59 | 59 | return $this->listWebhooks($this->eventDispatcher,$this->webhookRepository, $request); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
64 | - * |
|
65 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
66 | - */ |
|
67 | - public function getAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
62 | + /** |
|
63 | + * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
64 | + * |
|
65 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
66 | + */ |
|
67 | + public function getAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
68 | 68 | return $this->getSingleWebhook($webhook); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
73 | - */ |
|
74 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
71 | + /** |
|
72 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
73 | + */ |
|
74 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
75 | 75 | $ruleRepository = $this->webhookRepository; |
76 | 76 | $ruleFactory = $this->webhookFactory; |
77 | 77 | $formFactory = $this->formFactory; |
78 | 78 | |
79 | 79 | return $this->createWebhook($ruleRepository, $ruleFactory, $request, $formFactory); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
84 | - * |
|
85 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
86 | - */ |
|
87 | - public function deleteAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
82 | + /** |
|
83 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
84 | + * |
|
85 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
86 | + */ |
|
87 | + public function deleteAction(WebhookInterface $webhook): SingleResourceResponseInterface { |
|
88 | 88 | $webhookRepository = $this->webhookRepository; |
89 | 89 | |
90 | 90 | return $this->deleteWebhook($webhookRepository, $webhook); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
95 | - * |
|
96 | - * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
97 | - */ |
|
98 | - public function updateAction(Request $request, WebhookInterface $webhook): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
95 | + * |
|
96 | + * @ParamConverter("webhook", class="SWP\Bundle\WebhookBundle\Model\Webhook") |
|
97 | + */ |
|
98 | + public function updateAction(Request $request, WebhookInterface $webhook): SingleResourceResponseInterface { |
|
99 | 99 | $objectManager = $this->entityManager; |
100 | 100 | $formFactory = $this->formFactory; |
101 | 101 | |
102 | 102 | return $this->updateWebhook($objectManager, $request, $webhook, $formFactory); |
103 | - } |
|
103 | + } |
|
104 | 104 | } |
@@ -27,138 +27,138 @@ |
||
27 | 27 | use Symfony\Component\Routing\Annotation\Route; |
28 | 28 | |
29 | 29 | class StaticThemeAssetsController extends Controller { |
30 | - /** |
|
31 | - * Directory with assets inside theme. |
|
32 | - */ |
|
33 | - const ASSETS_DIRECTORY = 'public'; |
|
34 | - |
|
35 | - private TenantAwareThemeContextInterface $tenantAwareThemeContext; |
|
36 | - private ThemeLoaderInterface $themeLoader; |
|
37 | - private ThemeRepositoryInterface $themeRepository; |
|
38 | - |
|
39 | - /** |
|
40 | - * @param TenantAwareThemeContextInterface $tenantAwareThemeContext |
|
41 | - * @param ThemeLoaderInterface $themeLoader |
|
42 | - * @param ThemeRepositoryInterface $themeRepository |
|
43 | - */ |
|
44 | - public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, |
|
45 | - ThemeLoaderInterface $themeLoader, |
|
46 | - ThemeRepositoryInterface $themeRepository) { |
|
30 | + /** |
|
31 | + * Directory with assets inside theme. |
|
32 | + */ |
|
33 | + const ASSETS_DIRECTORY = 'public'; |
|
34 | + |
|
35 | + private TenantAwareThemeContextInterface $tenantAwareThemeContext; |
|
36 | + private ThemeLoaderInterface $themeLoader; |
|
37 | + private ThemeRepositoryInterface $themeRepository; |
|
38 | + |
|
39 | + /** |
|
40 | + * @param TenantAwareThemeContextInterface $tenantAwareThemeContext |
|
41 | + * @param ThemeLoaderInterface $themeLoader |
|
42 | + * @param ThemeRepositoryInterface $themeRepository |
|
43 | + */ |
|
44 | + public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, |
|
45 | + ThemeLoaderInterface $themeLoader, |
|
46 | + ThemeRepositoryInterface $themeRepository) { |
|
47 | 47 | $this->tenantAwareThemeContext = $tenantAwareThemeContext; |
48 | 48 | $this->themeLoader = $themeLoader; |
49 | 49 | $this->themeRepository = $themeRepository; |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) |
|
55 | - * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) |
|
56 | - * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) |
|
57 | - */ |
|
58 | - public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { |
|
53 | + /** |
|
54 | + * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) |
|
55 | + * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) |
|
56 | + * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) |
|
57 | + */ |
|
58 | + public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { |
|
59 | 59 | $themes = $themeHierarchyProvider->getThemeHierarchy( |
60 | 60 | $this->tenantAwareThemeContext->getTheme() |
61 | 61 | ); |
62 | 62 | |
63 | 63 | $fileName = (null === $fileExtension) ? basename($fileName) : $fileName . '.' . $fileExtension; |
64 | 64 | foreach ($themes as $theme) { |
65 | - $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; |
|
66 | - if (null !== $response = $this->handleFileLoading($filePath)) { |
|
65 | + $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; |
|
66 | + if (null !== $response = $this->handleFileLoading($filePath)) { |
|
67 | 67 | return $response; |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | throw new NotFoundHttpException('File was not found.'); |
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ |
|
76 | - * "type": "organization|tenant" |
|
77 | - * }) |
|
78 | - */ |
|
79 | - public function screenshotsAction(string $type, string $themeName, $fileName) { |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ |
|
76 | + * "type": "organization|tenant" |
|
77 | + * }) |
|
78 | + */ |
|
79 | + public function screenshotsAction(string $type, string $themeName, $fileName) { |
|
80 | 80 | if ('organization' === $type) { |
81 | - $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); |
|
81 | + $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); |
|
82 | 82 | } elseif ('tenant' === $type) { |
83 | - $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); |
|
83 | + $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); |
|
84 | 84 | } else { |
85 | - throw new NotFoundHttpException('File was not found.'); |
|
85 | + throw new NotFoundHttpException('File was not found.'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $filePath = $theme->getPath() . '/screenshots/' . $fileName; |
89 | 89 | if (null !== $response = $this->handleFileLoading($filePath)) { |
90 | - return $response; |
|
90 | + return $response; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | throw new NotFoundHttpException('File was not found.'); |
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param $filePath |
|
98 | - * |
|
99 | - * @return Response |
|
100 | - */ |
|
101 | - private function handleFileLoading($filePath) { |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param $filePath |
|
98 | + * |
|
99 | + * @return Response |
|
100 | + */ |
|
101 | + private function handleFileLoading($filePath) { |
|
102 | 102 | if (file_exists($filePath)) { |
103 | - $response = new Response(file_get_contents($filePath)); |
|
104 | - $disposition = $response->headers->makeDisposition( |
|
105 | - ResponseHeaderBag::DISPOSITION_INLINE, |
|
106 | - basename($filePath) |
|
107 | - ); |
|
108 | - $response->headers->set('Content-Disposition', $disposition); |
|
109 | - |
|
110 | - try { |
|
103 | + $response = new Response(file_get_contents($filePath)); |
|
104 | + $disposition = $response->headers->makeDisposition( |
|
105 | + ResponseHeaderBag::DISPOSITION_INLINE, |
|
106 | + basename($filePath) |
|
107 | + ); |
|
108 | + $response->headers->set('Content-Disposition', $disposition); |
|
109 | + |
|
110 | + try { |
|
111 | 111 | $type = new Mime(new Read($filePath)); |
112 | 112 | $mime = str_replace('/x-', '/', Mime::getMimeFromExtension($type->getExtension())); |
113 | - } catch (\Exception $e) { |
|
113 | + } catch (\Exception $e) { |
|
114 | 114 | $mime = 'text/plain'; |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - $response->headers->set('Content-Type', $mime); |
|
118 | - $response->setStatusCode(Response::HTTP_OK); |
|
119 | - $response->setPublic(); |
|
120 | - $response->setMaxAge(3600); |
|
121 | - $response->setSharedMaxAge(7200); |
|
117 | + $response->headers->set('Content-Type', $mime); |
|
118 | + $response->setStatusCode(Response::HTTP_OK); |
|
119 | + $response->setPublic(); |
|
120 | + $response->setMaxAge(3600); |
|
121 | + $response->setSharedMaxAge(7200); |
|
122 | 122 | |
123 | - return $response; |
|
123 | + return $response; |
|
124 | + } |
|
124 | 125 | } |
125 | - } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - private function loadOrganizationTheme(string $themeName) { |
|
127 | + /** |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + private function loadOrganizationTheme(string $themeName) { |
|
131 | 131 | $loadedThemes = $this->themeLoader->load(); |
132 | 132 | |
133 | 133 | return $this->filterThemes($loadedThemes, $themeName); |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return mixed |
|
138 | - */ |
|
139 | - private function loadTenantTheme(string $themeName) { |
|
136 | + /** |
|
137 | + * @return mixed |
|
138 | + */ |
|
139 | + private function loadTenantTheme(string $themeName) { |
|
140 | 140 | $loadedThemes = $this->themeRepository->findAll(); |
141 | 141 | |
142 | 142 | return $this->filterThemes($loadedThemes, $themeName); |
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param array $loadedThemes |
|
147 | - * |
|
148 | - * @return mixed |
|
149 | - */ |
|
150 | - private function filterThemes($loadedThemes, string $themeName) { |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param array $loadedThemes |
|
147 | + * |
|
148 | + * @return mixed |
|
149 | + */ |
|
150 | + private function filterThemes($loadedThemes, string $themeName) { |
|
151 | 151 | $themes = array_filter( |
152 | 152 | $loadedThemes, |
153 | 153 | function ($element) use (&$themeName) { |
154 | - return $element->getName() === $themeName; |
|
154 | + return $element->getName() === $themeName; |
|
155 | 155 | } |
156 | 156 | ); |
157 | 157 | |
158 | 158 | if (0 === count($themes)) { |
159 | - throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); |
|
159 | + throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return reset($themes); |
163 | - } |
|
163 | + } |
|
164 | 164 | } |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | $this->tenantAwareThemeContext->getTheme() |
61 | 61 | ); |
62 | 62 | |
63 | - $fileName = (null === $fileExtension) ? basename($fileName) : $fileName . '.' . $fileExtension; |
|
63 | + $fileName = (null === $fileExtension) ? basename($fileName) : $fileName.'.'.$fileExtension; |
|
64 | 64 | foreach ($themes as $theme) { |
65 | - $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; |
|
65 | + $filePath = $theme->getPath().'/'.self::ASSETS_DIRECTORY.'/'.$fileName; |
|
66 | 66 | if (null !== $response = $this->handleFileLoading($filePath)) { |
67 | 67 | return $response; |
68 | 68 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | throw new NotFoundHttpException('File was not found.'); |
86 | 86 | } |
87 | 87 | |
88 | - $filePath = $theme->getPath() . '/screenshots/' . $fileName; |
|
88 | + $filePath = $theme->getPath().'/screenshots/'.$fileName; |
|
89 | 89 | if (null !== $response = $this->handleFileLoading($filePath)) { |
90 | 90 | return $response; |
91 | 91 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | private function filterThemes($loadedThemes, string $themeName) { |
151 | 151 | $themes = array_filter( |
152 | 152 | $loadedThemes, |
153 | - function ($element) use (&$themeName) { |
|
153 | + function($element) use (&$themeName) { |
|
154 | 154 | return $element->getName() === $themeName; |
155 | 155 | } |
156 | 156 | ); |
@@ -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 PublishDestinationController extends Controller { |
37 | 37 | |
38 | - private FormFactoryInterface $formFactory; |
|
39 | - private EventDispatcherInterface $eventDispatcher; |
|
40 | - private CachedTenantContextInterface $cachedTenantContext; |
|
41 | - private RepositoryInterface $publishDestinationRepository; |
|
42 | - private EntityManagerInterface $entityManager; |
|
43 | - private FactoryInterface $publishDestinationFactory; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param FormFactoryInterface $formFactory |
|
47 | - * @param EventDispatcherInterface $eventDispatcher |
|
48 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | - * @param RepositoryInterface $publishDestinationRepository |
|
50 | - * @param EntityManagerInterface $entityManager |
|
51 | - * @param FactoryInterface $publishDestinationFactory |
|
52 | - */ |
|
53 | - public function __construct(FormFactoryInterface $formFactory, |
|
54 | - EventDispatcherInterface $eventDispatcher, |
|
55 | - CachedTenantContextInterface $cachedTenantContext, |
|
56 | - RepositoryInterface $publishDestinationRepository, |
|
57 | - EntityManagerInterface $entityManager, |
|
58 | - FactoryInterface $publishDestinationFactory) { |
|
38 | + private FormFactoryInterface $formFactory; |
|
39 | + private EventDispatcherInterface $eventDispatcher; |
|
40 | + private CachedTenantContextInterface $cachedTenantContext; |
|
41 | + private RepositoryInterface $publishDestinationRepository; |
|
42 | + private EntityManagerInterface $entityManager; |
|
43 | + private FactoryInterface $publishDestinationFactory; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param FormFactoryInterface $formFactory |
|
47 | + * @param EventDispatcherInterface $eventDispatcher |
|
48 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
49 | + * @param RepositoryInterface $publishDestinationRepository |
|
50 | + * @param EntityManagerInterface $entityManager |
|
51 | + * @param FactoryInterface $publishDestinationFactory |
|
52 | + */ |
|
53 | + public function __construct(FormFactoryInterface $formFactory, |
|
54 | + EventDispatcherInterface $eventDispatcher, |
|
55 | + CachedTenantContextInterface $cachedTenantContext, |
|
56 | + RepositoryInterface $publishDestinationRepository, |
|
57 | + EntityManagerInterface $entityManager, |
|
58 | + FactoryInterface $publishDestinationFactory) { |
|
59 | 59 | $this->formFactory = $formFactory; |
60 | 60 | $this->eventDispatcher = $eventDispatcher; |
61 | 61 | $this->cachedTenantContext = $cachedTenantContext; |
62 | 62 | $this->publishDestinationRepository = $publishDestinationRepository; |
63 | 63 | $this->entityManager = $entityManager; |
64 | 64 | $this->publishDestinationFactory = $publishDestinationFactory; |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") |
|
69 | - */ |
|
70 | - public function createAction(Request $request): SingleResourceResponse { |
|
67 | + /** |
|
68 | + * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") |
|
69 | + */ |
|
70 | + public function createAction(Request $request): SingleResourceResponse { |
|
71 | 71 | $tenantContext = $this->cachedTenantContext; |
72 | 72 | |
73 | 73 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
@@ -78,28 +78,28 @@ discard block |
||
78 | 78 | $form->handleRequest($request); |
79 | 79 | |
80 | 80 | if ($form->isSubmitted() && $form->isValid()) { |
81 | - $repository = $this->publishDestinationRepository; |
|
82 | - /** @var PublishDestinationInterface $publishDestination */ |
|
83 | - $publishDestination = $repository->findOneByTenant($destination->getTenant()); |
|
84 | - if (null !== $publishDestination) { |
|
81 | + $repository = $this->publishDestinationRepository; |
|
82 | + /** @var PublishDestinationInterface $publishDestination */ |
|
83 | + $publishDestination = $repository->findOneByTenant($destination->getTenant()); |
|
84 | + if (null !== $publishDestination) { |
|
85 | 85 | $repository->remove($publishDestination); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - $currentOrganization->addPublishDestination($destination); |
|
89 | - $this->entityManager->flush(); |
|
88 | + $currentOrganization->addPublishDestination($destination); |
|
89 | + $this->entityManager->flush(); |
|
90 | 90 | |
91 | - return new SingleResourceResponse($destination, new ResponseContext(200)); |
|
91 | + return new SingleResourceResponse($destination, new ResponseContext(200)); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return new SingleResourceResponse($form, new ResponseContext(400)); |
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) |
|
99 | - * @ParamConverter("publishDestination", class="SWP\Bundle\CoreBundle\Model\PublishDestination") |
|
100 | - */ |
|
101 | - public function updateAction(Request $request, |
|
102 | - PublishDestinationInterface $publishDestination): SingleResourceResponse { |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) |
|
99 | + * @ParamConverter("publishDestination", class="SWP\Bundle\CoreBundle\Model\PublishDestination") |
|
100 | + */ |
|
101 | + public function updateAction(Request $request, |
|
102 | + PublishDestinationInterface $publishDestination): SingleResourceResponse { |
|
103 | 103 | $objectManager = $this->entityManager; |
104 | 104 | |
105 | 105 | $form = $this->formFactory->createNamed('', PublishDestinationType::class, $publishDestination, [ |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | $form->handleRequest($request); |
110 | 110 | if ($form->isSubmitted() && $form->isValid()) { |
111 | - $objectManager->flush(); |
|
112 | - $objectManager->refresh($publishDestination); |
|
111 | + $objectManager->flush(); |
|
112 | + $objectManager->refresh($publishDestination); |
|
113 | 113 | |
114 | - return new SingleResourceResponse($publishDestination); |
|
114 | + return new SingleResourceResponse($publishDestination); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return new SingleResourceResponse($form, new ResponseContext(400)); |
118 | - } |
|
118 | + } |
|
119 | 119 | } |
@@ -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 | } |
@@ -43,32 +43,32 @@ discard block |
||
43 | 43 | |
44 | 44 | class ContentListController extends AbstractController { |
45 | 45 | |
46 | - private ContentListRepositoryInterface $contentListRepository; |
|
47 | - private ContentListItemRepositoryInterface $contentListItemRepository; |
|
48 | - private ContentListServiceInterface $contentListService; |
|
49 | - private FormFactoryInterface $formFactory; |
|
50 | - private EntityManagerInterface $entityManager; |
|
51 | - private EventDispatcherInterface $eventDispatcher; |
|
52 | - private FactoryInterface $factory; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param ContentListRepositoryInterface $contentListRepository |
|
56 | - * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
57 | - * @param ContentListServiceInterface $contentListService |
|
58 | - * @param FormFactoryInterface $formFactory |
|
59 | - * @param EntityManagerInterface $entityManager |
|
60 | - * @param EventDispatcherInterface $eventDispatcher |
|
61 | - * @param FactoryInterface $factory |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - ContentListRepositoryInterface $contentListRepository, |
|
65 | - ContentListItemRepositoryInterface $contentListItemRepository, |
|
66 | - ContentListServiceInterface $contentListService, |
|
67 | - FormFactoryInterface $formFactory, |
|
68 | - EntityManagerInterface $entityManager, |
|
69 | - EventDispatcherInterface $eventDispatcher, |
|
70 | - FactoryInterface $factory |
|
71 | - ) { |
|
46 | + private ContentListRepositoryInterface $contentListRepository; |
|
47 | + private ContentListItemRepositoryInterface $contentListItemRepository; |
|
48 | + private ContentListServiceInterface $contentListService; |
|
49 | + private FormFactoryInterface $formFactory; |
|
50 | + private EntityManagerInterface $entityManager; |
|
51 | + private EventDispatcherInterface $eventDispatcher; |
|
52 | + private FactoryInterface $factory; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param ContentListRepositoryInterface $contentListRepository |
|
56 | + * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
57 | + * @param ContentListServiceInterface $contentListService |
|
58 | + * @param FormFactoryInterface $formFactory |
|
59 | + * @param EntityManagerInterface $entityManager |
|
60 | + * @param EventDispatcherInterface $eventDispatcher |
|
61 | + * @param FactoryInterface $factory |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + ContentListRepositoryInterface $contentListRepository, |
|
65 | + ContentListItemRepositoryInterface $contentListItemRepository, |
|
66 | + ContentListServiceInterface $contentListService, |
|
67 | + FormFactoryInterface $formFactory, |
|
68 | + EntityManagerInterface $entityManager, |
|
69 | + EventDispatcherInterface $eventDispatcher, |
|
70 | + FactoryInterface $factory |
|
71 | + ) { |
|
72 | 72 | $this->contentListRepository = $contentListRepository; |
73 | 73 | $this->contentListItemRepository = $contentListItemRepository; |
74 | 74 | $this->contentListService = $contentListService; |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | $this->entityManager = $entityManager; |
77 | 77 | $this->eventDispatcher = $eventDispatcher; |
78 | 78 | $this->factory = $factory; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") |
|
83 | - */ |
|
84 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
81 | + /** |
|
82 | + * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") |
|
83 | + */ |
|
84 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
85 | 85 | $lists = $this->contentListRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
86 | 86 | |
87 | 87 | return new ResourcesListResponse($lists); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) |
|
92 | - */ |
|
93 | - public function getAction($id): SingleResourceResponseInterface { |
|
90 | + /** |
|
91 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) |
|
92 | + */ |
|
93 | + public function getAction($id): SingleResourceResponseInterface { |
|
94 | 94 | return new SingleResourceResponse($this->findOr404($id)); |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") |
|
99 | - */ |
|
100 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
97 | + /** |
|
98 | + * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") |
|
99 | + */ |
|
100 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
101 | 101 | /* @var ContentListInterface $contentList */ |
102 | 102 | $contentList = $this->factory->create(); |
103 | 103 | $form = $this->formFactory->createNamed('', ContentListType::class, $contentList, ['method' => $request->getMethod()]); |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | $this->ensureContentListExists($contentList->getName()); |
107 | 107 | |
108 | 108 | if ($form->isSubmitted() && $form->isValid()) { |
109 | - $this->contentListRepository->add($contentList); |
|
109 | + $this->contentListRepository->add($contentList); |
|
110 | 110 | |
111 | - return new SingleResourceResponse($contentList, new ResponseContext(201)); |
|
111 | + return new SingleResourceResponse($contentList, new ResponseContext(201)); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return new SingleResourceResponse($form, new ResponseContext(400)); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) |
|
119 | - */ |
|
120 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
117 | + /** |
|
118 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) |
|
119 | + */ |
|
120 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
121 | 121 | $objectManager = $this->entityManager; |
122 | 122 | /** @var ContentListInterface $contentList */ |
123 | 123 | $contentList = $this->findOr404($id); |
@@ -128,51 +128,51 @@ discard block |
||
128 | 128 | $form->handleRequest($request); |
129 | 129 | |
130 | 130 | if ($form->isSubmitted() && $form->isValid()) { |
131 | - $this->eventDispatcher->dispatch( |
|
132 | - new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), |
|
133 | - ContentListEvents::LIST_CRITERIA_CHANGE |
|
134 | - ); |
|
131 | + $this->eventDispatcher->dispatch( |
|
132 | + new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), |
|
133 | + ContentListEvents::LIST_CRITERIA_CHANGE |
|
134 | + ); |
|
135 | 135 | |
136 | - $objectManager->flush(); |
|
136 | + $objectManager->flush(); |
|
137 | 137 | |
138 | - return new SingleResourceResponse($contentList); |
|
138 | + return new SingleResourceResponse($contentList); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return new SingleResourceResponse($form, new ResponseContext(400)); |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) |
|
146 | - */ |
|
147 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
144 | + /** |
|
145 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) |
|
146 | + */ |
|
147 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
148 | 148 | $repository = $this->contentListRepository; |
149 | 149 | $contentList = $this->findOr404($id); |
150 | 150 | |
151 | 151 | $repository->remove($contentList); |
152 | 152 | |
153 | 153 | return new SingleResourceResponse(null, new ResponseContext(204)); |
154 | - } |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") |
|
158 | - */ |
|
159 | - public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { |
|
156 | + /** |
|
157 | + * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") |
|
158 | + */ |
|
159 | + public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { |
|
160 | 160 | $objectManager = $this->entityManager; |
161 | 161 | /** @var ContentListInterface $contentList */ |
162 | 162 | $contentList = $this->findOr404($id); |
163 | 163 | |
164 | 164 | $matched = false; |
165 | 165 | foreach ($request->attributes->get('links', []) as $key => $objectArray) { |
166 | - if (!is_array($objectArray)) { |
|
166 | + if (!is_array($objectArray)) { |
|
167 | 167 | continue; |
168 | - } |
|
168 | + } |
|
169 | 169 | |
170 | - $object = $objectArray['object']; |
|
171 | - if ($object instanceof Exception) { |
|
170 | + $object = $objectArray['object']; |
|
171 | + if ($object instanceof Exception) { |
|
172 | 172 | throw $object; |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - if ($object instanceof ArticleInterface) { |
|
175 | + if ($object instanceof ArticleInterface) { |
|
176 | 176 | $contentListItem = $this->contentListItemRepository |
177 | 177 | ->findOneBy([ |
178 | 178 | 'contentList' => $contentList, |
@@ -180,59 +180,59 @@ discard block |
||
180 | 180 | ]); |
181 | 181 | |
182 | 182 | if ('LINK' === $request->getMethod()) { |
183 | - $position = 0; |
|
184 | - if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { |
|
183 | + $position = 0; |
|
184 | + if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { |
|
185 | 185 | foreach ($notConvertedLinks as $link) { |
186 | - if (isset($link['resourceType']) && 'position' === $link['resourceType']) { |
|
186 | + if (isset($link['resourceType']) && 'position' === $link['resourceType']) { |
|
187 | 187 | $position = $link['resource']; |
188 | - } |
|
188 | + } |
|
189 | + } |
|
189 | 190 | } |
190 | - } |
|
191 | 191 | |
192 | - if (false === $position && $contentListItem) { |
|
192 | + if (false === $position && $contentListItem) { |
|
193 | 193 | throw new ConflictHttpException('This content is already linked to Content List'); |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - if (!$contentListItem) { |
|
196 | + if (!$contentListItem) { |
|
197 | 197 | $contentListItem = $this->contentListService->addArticleToContentList($contentList, $object, $position); |
198 | 198 | $objectManager->persist($contentListItem); |
199 | - } else { |
|
199 | + } else { |
|
200 | 200 | $contentListItem->setPosition($position); |
201 | - } |
|
201 | + } |
|
202 | 202 | |
203 | - $objectManager->flush(); |
|
203 | + $objectManager->flush(); |
|
204 | 204 | } elseif ('UNLINK' === $request->getMethod()) { |
205 | - if ($contentListItem->getContentList() !== $contentList) { |
|
205 | + if ($contentListItem->getContentList() !== $contentList) { |
|
206 | 206 | throw new ConflictHttpException('Content is not linked to content list'); |
207 | - } |
|
208 | - $objectManager->remove($contentListItem); |
|
207 | + } |
|
208 | + $objectManager->remove($contentListItem); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | $matched = true; |
212 | 212 | |
213 | 213 | break; |
214 | - } |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | if (false === $matched) { |
217 | - throw new NotFoundHttpException('Any supported link object was not found'); |
|
217 | + throw new NotFoundHttpException('Any supported link object was not found'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | $objectManager->flush(); |
221 | 221 | |
222 | 222 | return new SingleResourceResponse($contentList, new ResponseContext(201)); |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - private function findOr404($id) { |
|
225 | + private function findOr404($id) { |
|
226 | 226 | if (null === $list = $this->contentListRepository->find($id)) { |
227 | - throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); |
|
227 | + throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | return $list; |
231 | - } |
|
231 | + } |
|
232 | 232 | |
233 | - private function ensureContentListExists($name) { |
|
233 | + private function ensureContentListExists($name) { |
|
234 | 234 | if (null !== $this->contentListRepository->findOneBy(['name' => $name])) { |
235 | - throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); |
|
235 | + throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); |
|
236 | + } |
|
236 | 237 | } |
237 | - } |
|
238 | 238 | } |