@@ -15,7 +15,7 @@ |
||
15 | 15 | namespace SWP\Bundle\CoreBundle\EventListener; |
16 | 16 | |
17 | 17 | use SWP\Bundle\CoreBundle\Detection\DeviceDetectionInterface; |
18 | -use Symfony\Component\HttpKernel\Event\RequestEvent ; |
|
18 | +use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
19 | 19 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
20 | 20 | |
21 | 21 | class CurrentDeviceListener |
@@ -28,24 +28,24 @@ discard block |
||
28 | 28 | |
29 | 29 | class SubscriptionController extends Controller { |
30 | 30 | |
31 | - private SubscriptionsProviderInterface $subscriptionsProvider; |
|
32 | - private RepositoryInterface $userRepository; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param SubscriptionsProviderInterface $subscriptionsProvider |
|
36 | - * @param RepositoryInterface $userRepository |
|
37 | - */ |
|
38 | - public function __construct(SubscriptionsProviderInterface $subscriptionsProvider, |
|
39 | - RepositoryInterface $userRepository) { |
|
31 | + private SubscriptionsProviderInterface $subscriptionsProvider; |
|
32 | + private RepositoryInterface $userRepository; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param SubscriptionsProviderInterface $subscriptionsProvider |
|
36 | + * @param RepositoryInterface $userRepository |
|
37 | + */ |
|
38 | + public function __construct(SubscriptionsProviderInterface $subscriptionsProvider, |
|
39 | + RepositoryInterface $userRepository) { |
|
40 | 40 | $this->subscriptionsProvider = $subscriptionsProvider; |
41 | 41 | $this->userRepository = $userRepository; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"}) |
|
47 | - */ |
|
48 | - public function getAction(Request $request, int $userId) { |
|
45 | + /** |
|
46 | + * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"}) |
|
47 | + */ |
|
48 | + public function getAction(Request $request, int $userId) { |
|
49 | 49 | $subscriptionsProvider = $this->subscriptionsProvider; |
50 | 50 | |
51 | 51 | $filters = [ |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | $subscriptions = $subscriptionsProvider->getSubscriptions($user, $filters); |
59 | 59 | |
60 | 60 | return new SingleResourceResponse($subscriptions); |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - private function findOr404(int $id) { |
|
63 | + private function findOr404(int $id) { |
|
64 | 64 | $user = $this->userRepository->findOneById($id); |
65 | 65 | |
66 | 66 | if (!$user instanceof UserInterface) { |
67 | - throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id)); |
|
67 | + throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id)); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | return $user; |
71 | - } |
|
71 | + } |
|
72 | 72 | } |
@@ -29,40 +29,40 @@ discard block |
||
29 | 29 | |
30 | 30 | class ExternalDataController extends AbstractController { |
31 | 31 | |
32 | - private PackageRepositoryInterface $packageRepository; |
|
33 | - private FactoryInterface $factory; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param PackageRepositoryInterface $packageRepository |
|
37 | - * @param FactoryInterface $factory |
|
38 | - */ |
|
39 | - public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) { |
|
32 | + private PackageRepositoryInterface $packageRepository; |
|
33 | + private FactoryInterface $factory; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param PackageRepositoryInterface $packageRepository |
|
37 | + * @param FactoryInterface $factory |
|
38 | + */ |
|
39 | + public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) { |
|
40 | 40 | $this->packageRepository = $packageRepository; |
41 | 41 | $this->factory = $factory; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data") |
|
46 | - */ |
|
47 | - public function setAction(Request $request, string $slug): SingleResourceResponseInterface { |
|
44 | + /** |
|
45 | + * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data") |
|
46 | + */ |
|
47 | + public function setAction(Request $request, string $slug): SingleResourceResponseInterface { |
|
48 | 48 | $packageRepository = $this->packageRepository; |
49 | 49 | $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]); |
50 | 50 | if (null === $existingPackage) { |
51 | - throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug)); |
|
51 | + throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $externalData = $existingPackage->getExternalData(); |
55 | 55 | if (null === $externalData) { |
56 | - foreach ($externalData as $data) { |
|
56 | + foreach ($externalData as $data) { |
|
57 | 57 | $packageRepository->remove($data); |
58 | - } |
|
59 | - $packageRepository->flush(); |
|
58 | + } |
|
59 | + $packageRepository->flush(); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | if (null !== $request->getContent()) { |
63 | - $validJson = self::getArrayFromJson($request->getContent()); |
|
64 | - $responseData = []; |
|
65 | - foreach ($validJson as $key => $value) { |
|
63 | + $validJson = self::getArrayFromJson($request->getContent()); |
|
64 | + $responseData = []; |
|
65 | + foreach ($validJson as $key => $value) { |
|
66 | 66 | /** @var ExternalDataInterface $externalData */ |
67 | 67 | $externalData = $this->factory->create(); |
68 | 68 | $externalData->setKey($key); |
@@ -70,45 +70,45 @@ discard block |
||
70 | 70 | $externalData->setPackage($existingPackage); |
71 | 71 | $packageRepository->persist($externalData); |
72 | 72 | $responseData[$externalData->getKey()] = $externalData->getValue(); |
73 | - } |
|
74 | - $packageRepository->flush(); |
|
73 | + } |
|
74 | + $packageRepository->flush(); |
|
75 | 75 | |
76 | - return new SingleResourceResponse($responseData, new ResponseContext(200)); |
|
76 | + return new SingleResourceResponse($responseData, new ResponseContext(200)); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return new SingleResourceResponse(['Provided request content is not valid JSON'], new ResponseContext(400)); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data") |
|
84 | - */ |
|
85 | - public function getAction(string $slug): SingleResourceResponseInterface { |
|
82 | + /** |
|
83 | + * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data") |
|
84 | + */ |
|
85 | + public function getAction(string $slug): SingleResourceResponseInterface { |
|
86 | 86 | $packageRepository = $this->packageRepository; |
87 | 87 | $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]); |
88 | 88 | if (null === $existingPackage) { |
89 | - throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug)); |
|
89 | + throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug)); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $externalData = $existingPackage->getExternalData(); |
93 | 93 | if (null === $externalData) { |
94 | - return new SingleResourceResponse([], new ResponseContext(200)); |
|
94 | + return new SingleResourceResponse([], new ResponseContext(200)); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $responseData = []; |
98 | 98 | /** @var ExternalDataInterface $data */ |
99 | 99 | foreach ($externalData as $data) { |
100 | - $responseData[$data->getKey()] = $data->getValue(); |
|
100 | + $responseData[$data->getKey()] = $data->getValue(); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | return new SingleResourceResponse($responseData, new ResponseContext(200)); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - private static function getArrayFromJson($jsonString) { |
|
106 | + private static function getArrayFromJson($jsonString) { |
|
107 | 107 | $jsonArray = json_decode($jsonString, true); |
108 | 108 | if (null === $jsonArray || JSON_ERROR_NONE !== json_last_error()) { |
109 | - throw new \UnexpectedValueException('Provided request content is not valid JSON'); |
|
109 | + throw new \UnexpectedValueException('Provided request content is not valid JSON'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return $jsonArray; |
113 | - } |
|
113 | + } |
|
114 | 114 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $currentlyLoggedInUser = $this->getUser(); |
100 | 100 | |
101 | 101 | $now = PublisherDateTime::getCurrentDateTime(); |
102 | - $fileName = 'analytics-' . $now->format('Y-m-d-H:i:s') . '.csv'; |
|
102 | + $fileName = 'analytics-'.$now->format('Y-m-d-H:i:s').'.csv'; |
|
103 | 103 | |
104 | 104 | $form = $this->formFactory->createNamed('', ExportAnalyticsType::class, null, ['method' => $request->getMethod()]); |
105 | 105 | $form->handleRequest($request); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function downloadFile(string $fileName): Response { |
163 | 163 | $cacheKey = md5(serialize(['analytics_report', $fileName])); |
164 | 164 | |
165 | - $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) { |
|
165 | + $analyticsReport = $this->cacheProvider->get($cacheKey, function() use ($fileName) { |
|
166 | 166 | /* @var AnalyticsReportInterface|null $analyticsReport */ |
167 | 167 | return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
168 | 168 | }); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $response->setMaxAge(63072000); |
185 | 185 | $response->setSharedMaxAge(63072000); |
186 | 186 | $response->setLastModified($analyticsReport->getUpdatedAt() ?: $analyticsReport->getCreatedAt()); |
187 | - $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId())); |
|
187 | + $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath().'/'.$analyticsReport->getAssetId())); |
|
188 | 188 | |
189 | 189 | return $response; |
190 | 190 | } |
@@ -51,33 +51,33 @@ discard block |
||
51 | 51 | |
52 | 52 | class AnalyticsExportController extends AbstractController { |
53 | 53 | |
54 | - protected CacheInterface $cacheProvider; |
|
55 | - protected RepositoryInterface $analyticsReportRepository; |
|
56 | - protected Filesystem $filesystem; |
|
57 | - protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | - protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | - protected RouteRepositoryInterface $routeRepository; |
|
60 | - private MessageBusInterface $messageBus; |
|
61 | - private FormFactoryInterface $formFactory; |
|
62 | - private EventDispatcherInterface $eventDispatcher; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param CacheInterface $cacheProvider |
|
66 | - * @param RepositoryInterface $analyticsReportRepository |
|
67 | - * @param Filesystem $filesystem |
|
68 | - * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | - * @param RouteRepositoryInterface $routeRepository |
|
71 | - * @param MessageBusInterface $messageBus |
|
72 | - * @param FormFactoryInterface $formFactory |
|
73 | - * @param EventDispatcherInterface $eventDispatcher |
|
74 | - */ |
|
75 | - public function __construct(CacheInterface $cacheProvider, |
|
76 | - RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | - CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | - CachedTenantContextInterface $cachedTenantContext, |
|
79 | - RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | - FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
54 | + protected CacheInterface $cacheProvider; |
|
55 | + protected RepositoryInterface $analyticsReportRepository; |
|
56 | + protected Filesystem $filesystem; |
|
57 | + protected CsvReportFileLocationResolver $csvReportFileLocationResolver; |
|
58 | + protected CachedTenantContextInterface $cachedTenantContext; |
|
59 | + protected RouteRepositoryInterface $routeRepository; |
|
60 | + private MessageBusInterface $messageBus; |
|
61 | + private FormFactoryInterface $formFactory; |
|
62 | + private EventDispatcherInterface $eventDispatcher; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param CacheInterface $cacheProvider |
|
66 | + * @param RepositoryInterface $analyticsReportRepository |
|
67 | + * @param Filesystem $filesystem |
|
68 | + * @param CsvReportFileLocationResolver $csvReportFileLocationResolver |
|
69 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
70 | + * @param RouteRepositoryInterface $routeRepository |
|
71 | + * @param MessageBusInterface $messageBus |
|
72 | + * @param FormFactoryInterface $formFactory |
|
73 | + * @param EventDispatcherInterface $eventDispatcher |
|
74 | + */ |
|
75 | + public function __construct(CacheInterface $cacheProvider, |
|
76 | + RepositoryInterface $analyticsReportRepository, Filesystem $filesystem, |
|
77 | + CsvReportFileLocationResolver $csvReportFileLocationResolver, |
|
78 | + CachedTenantContextInterface $cachedTenantContext, |
|
79 | + RouteRepositoryInterface $routeRepository, MessageBusInterface $messageBus, |
|
80 | + FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher) { |
|
81 | 81 | $this->cacheProvider = $cacheProvider; |
82 | 82 | $this->analyticsReportRepository = $analyticsReportRepository; |
83 | 83 | $this->filesystem = $filesystem; |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | $this->messageBus = $messageBus; |
88 | 88 | $this->formFactory = $formFactory; |
89 | 89 | $this->eventDispatcher = $eventDispatcher; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | - * |
|
96 | - * @throws \Exception |
|
97 | - */ |
|
98 | - public function post(Request $request): SingleResourceResponseInterface { |
|
93 | + /** |
|
94 | + * @FosRoute("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post") |
|
95 | + * |
|
96 | + * @throws \Exception |
|
97 | + */ |
|
98 | + public function post(Request $request): SingleResourceResponseInterface { |
|
99 | 99 | /** @var UserInterface $currentlyLoggedInUser */ |
100 | 100 | $currentlyLoggedInUser = $this->getUser(); |
101 | 101 | |
@@ -106,46 +106,46 @@ discard block |
||
106 | 106 | $form->handleRequest($request); |
107 | 107 | |
108 | 108 | if ($form->isSubmitted() && $form->isValid()) { |
109 | - $data = $form->getData(); |
|
109 | + $data = $form->getData(); |
|
110 | 110 | |
111 | - $analyticsReport = new AnalyticsReport(); |
|
112 | - $analyticsReport->setAssetId($fileName); |
|
113 | - $analyticsReport->setFileExtension('csv'); |
|
114 | - $analyticsReport->setUser($currentlyLoggedInUser); |
|
111 | + $analyticsReport = new AnalyticsReport(); |
|
112 | + $analyticsReport->setAssetId($fileName); |
|
113 | + $analyticsReport->setFileExtension('csv'); |
|
114 | + $analyticsReport->setUser($currentlyLoggedInUser); |
|
115 | 115 | |
116 | - $exportAnalytics = new ExportAnalytics( |
|
117 | - $data['start'], |
|
118 | - $data['end'], |
|
119 | - $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | - $fileName, |
|
121 | - $currentlyLoggedInUser->getEmail(), |
|
122 | - !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | - !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | - $data['term'] ?? '' |
|
125 | - ); |
|
116 | + $exportAnalytics = new ExportAnalytics( |
|
117 | + $data['start'], |
|
118 | + $data['end'], |
|
119 | + $this->cachedTenantContext->getTenant()->getCode(), |
|
120 | + $fileName, |
|
121 | + $currentlyLoggedInUser->getEmail(), |
|
122 | + !empty($data['routes']) ? $this->toIds($data['routes']) : [], |
|
123 | + !empty($data['authors']) ? $this->toIds($data['authors']) : [], |
|
124 | + $data['term'] ?? '' |
|
125 | + ); |
|
126 | 126 | |
127 | - $filters = $this->processFilters( |
|
128 | - $exportAnalytics->getFilters(), |
|
129 | - !empty($data['routes']) ? $data['routes'] : [], |
|
130 | - !empty($data['authors']) ? $data['authors'] : [] |
|
131 | - ); |
|
127 | + $filters = $this->processFilters( |
|
128 | + $exportAnalytics->getFilters(), |
|
129 | + !empty($data['routes']) ? $data['routes'] : [], |
|
130 | + !empty($data['authors']) ? $data['authors'] : [] |
|
131 | + ); |
|
132 | 132 | |
133 | - $analyticsReport->setFilters($filters); |
|
133 | + $analyticsReport->setFilters($filters); |
|
134 | 134 | |
135 | - $this->analyticsReportRepository->add($analyticsReport); |
|
135 | + $this->analyticsReportRepository->add($analyticsReport); |
|
136 | 136 | |
137 | - $this->messageBus->dispatch($exportAnalytics); |
|
137 | + $this->messageBus->dispatch($exportAnalytics); |
|
138 | 138 | |
139 | - return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
139 | + return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return new SingleResourceResponse($form, new ResponseContext(400)); |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | - */ |
|
148 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
145 | + /** |
|
146 | + * @FosRoute("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports") |
|
147 | + */ |
|
148 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
149 | 149 | $sorting = $request->query->all('sorting'); |
150 | 150 | $reports = $this->analyticsReportRepository->getPaginatedByCriteria( |
151 | 151 | $this->eventDispatcher, |
@@ -155,21 +155,21 @@ discard block |
||
155 | 155 | ); |
156 | 156 | |
157 | 157 | return new ResourcesListResponse($reports); |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | - */ |
|
163 | - public function downloadFile(string $fileName): Response { |
|
160 | + /** |
|
161 | + * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download") |
|
162 | + */ |
|
163 | + public function downloadFile(string $fileName): Response { |
|
164 | 164 | $cacheKey = md5(serialize(['analytics_report', $fileName])); |
165 | 165 | |
166 | 166 | $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) { |
167 | - /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | - return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
167 | + /* @var AnalyticsReportInterface|null $analyticsReport */ |
|
168 | + return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]); |
|
169 | 169 | }); |
170 | 170 | |
171 | 171 | if (null === $analyticsReport) { |
172 | - throw new NotFoundHttpException('Report file was not found.'); |
|
172 | + throw new NotFoundHttpException('Report file was not found.'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $response = new Response(); |
@@ -188,30 +188,30 @@ discard block |
||
188 | 188 | $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId())); |
189 | 189 | |
190 | 190 | return $response; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - private function toIds(array $items): array { |
|
193 | + private function toIds(array $items): array { |
|
194 | 194 | $ids = []; |
195 | 195 | foreach ($items as $item) { |
196 | - foreach ($item as $entity) { |
|
196 | + foreach ($item as $entity) { |
|
197 | 197 | if (!$entity instanceof PersistableInterface) { |
198 | - continue; |
|
198 | + continue; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $ids[] = $entity->getId(); |
202 | - } |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $ids; |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - private function processFilters(array $filters, array $routes, array $authors): array { |
|
208 | + private function processFilters(array $filters, array $routes, array $authors): array { |
|
209 | 209 | $routeNames = []; |
210 | 210 | |
211 | 211 | foreach ($routes as $route) { |
212 | - foreach ($route as $entity) { |
|
212 | + foreach ($route as $entity) { |
|
213 | 213 | $routeNames[] = $entity->getName(); |
214 | - } |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $filters['routes'] = $routeNames; |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $authorNames = []; |
220 | 220 | /** @var ArticleAuthorInterface $author */ |
221 | 221 | foreach ($authors as $author) { |
222 | - foreach ($author as $entity) { |
|
222 | + foreach ($author as $entity) { |
|
223 | 223 | $authorNames[] = $entity->getName(); |
224 | - } |
|
224 | + } |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $filters['authors'] = $authorNames; |
228 | 228 | |
229 | 229 | return $filters; |
230 | - } |
|
230 | + } |
|
231 | 231 | } |
@@ -37,45 +37,45 @@ discard block |
||
37 | 37 | |
38 | 38 | class RedirectRouteController extends AbstractController { |
39 | 39 | |
40 | - private FormFactoryInterface $formFactory; |
|
41 | - private RepositoryInterface $redirectRouteRepository; |
|
42 | - private EntityManagerInterface $entityManager; |
|
43 | - private FactoryInterface $redirectRouteFactory; |
|
44 | - private EventDispatcherInterface $eventDispatcher; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param FormFactoryInterface $formFactory |
|
48 | - * @param RepositoryInterface $redirectRouteRepository |
|
49 | - * @param EntityManagerInterface $entityManager |
|
50 | - * @param FactoryInterface $redirectRouteFactory |
|
51 | - * @param EventDispatcherInterface $eventDispatcher |
|
52 | - */ |
|
53 | - public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $redirectRouteRepository, |
|
54 | - EntityManagerInterface $entityManager, FactoryInterface $redirectRouteFactory, |
|
55 | - EventDispatcherInterface $eventDispatcher) { |
|
40 | + private FormFactoryInterface $formFactory; |
|
41 | + private RepositoryInterface $redirectRouteRepository; |
|
42 | + private EntityManagerInterface $entityManager; |
|
43 | + private FactoryInterface $redirectRouteFactory; |
|
44 | + private EventDispatcherInterface $eventDispatcher; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param FormFactoryInterface $formFactory |
|
48 | + * @param RepositoryInterface $redirectRouteRepository |
|
49 | + * @param EntityManagerInterface $entityManager |
|
50 | + * @param FactoryInterface $redirectRouteFactory |
|
51 | + * @param EventDispatcherInterface $eventDispatcher |
|
52 | + */ |
|
53 | + public function __construct(FormFactoryInterface $formFactory, RepositoryInterface $redirectRouteRepository, |
|
54 | + EntityManagerInterface $entityManager, FactoryInterface $redirectRouteFactory, |
|
55 | + EventDispatcherInterface $eventDispatcher) { |
|
56 | 56 | $this->formFactory = $formFactory; |
57 | 57 | $this->redirectRouteRepository = $redirectRouteRepository; |
58 | 58 | $this->entityManager = $entityManager; |
59 | 59 | $this->redirectRouteFactory = $redirectRouteFactory; |
60 | 60 | $this->eventDispatcher = $eventDispatcher; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * @Route("/api/{version}/redirects/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_redirect_routes") |
|
66 | - */ |
|
67 | - public function listAction(Request $request) { |
|
64 | + /** |
|
65 | + * @Route("/api/{version}/redirects/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_redirect_routes") |
|
66 | + */ |
|
67 | + public function listAction(Request $request) { |
|
68 | 68 | $redirectRouteRepository = $this->redirectRouteRepository; |
69 | 69 | |
70 | 70 | $redirectRoutes = $redirectRouteRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
71 | 71 | |
72 | 72 | return new ResourcesListResponse($redirectRoutes); |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @Route("/api/{version}/redirects/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_redirect_route", requirements={"id"="\d+"}) |
|
77 | - */ |
|
78 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
75 | + /** |
|
76 | + * @Route("/api/{version}/redirects/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_redirect_route", requirements={"id"="\d+"}) |
|
77 | + */ |
|
78 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
79 | 79 | $objectManager = $this->entityManager; |
80 | 80 | $redirectRoute = $this->findOr404($id); |
81 | 81 | |
@@ -83,69 +83,69 @@ discard block |
||
83 | 83 | $objectManager->flush(); |
84 | 84 | |
85 | 85 | return new SingleResourceResponse(null, new ResponseContext(204)); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @Route("/api/{version}/redirects/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_create_redirect_route") |
|
90 | - */ |
|
91 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
88 | + /** |
|
89 | + * @Route("/api/{version}/redirects/", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_create_redirect_route") |
|
90 | + */ |
|
91 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
92 | 92 | $redirectRoute = $this->redirectRouteFactory->create(); |
93 | 93 | $form = $this->formFactory->createNamed('', RedirectRouteType::class, $redirectRoute, ['method' => $request->getMethod()]); |
94 | 94 | |
95 | 95 | $form->handleRequest($request); |
96 | 96 | |
97 | 97 | if ($this->checkIfSourceRouteExists($redirectRoute)) { |
98 | - $this->ensureRedirectRouteExists($redirectRoute->getRouteName()); |
|
98 | + $this->ensureRedirectRouteExists($redirectRoute->getRouteName()); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if ($form->isSubmitted() && $form->isValid()) { |
102 | - if ($this->checkIfSourceRouteExists($redirectRoute)) { |
|
102 | + if ($this->checkIfSourceRouteExists($redirectRoute)) { |
|
103 | 103 | $redirectRoute->setStaticPrefix($redirectRoute->getRouteName()); |
104 | - } else { |
|
104 | + } else { |
|
105 | 105 | $redirectRoute->setStaticPrefix($redirectRoute->getRouteSource()->getStaticPrefix()); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - $this->redirectRouteRepository->add($redirectRoute); |
|
108 | + $this->redirectRouteRepository->add($redirectRoute); |
|
109 | 109 | |
110 | - return new SingleResourceResponse($redirectRoute, new ResponseContext(201)); |
|
110 | + return new SingleResourceResponse($redirectRoute, new ResponseContext(201)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return new SingleResourceResponse($form, new ResponseContext(400)); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @Route("/api/{version}/redirects/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_update_redirect_route", requirements={"id"="\d+"}) |
|
118 | - */ |
|
119 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
116 | + /** |
|
117 | + * @Route("/api/{version}/redirects/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_update_redirect_route", requirements={"id"="\d+"}) |
|
118 | + */ |
|
119 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
120 | 120 | $objectManager = $this->entityManager; |
121 | 121 | $redirectRoute = $this->findOr404($id); |
122 | 122 | $form = $this->formFactory->createNamed('', RedirectRouteType::class, $redirectRoute, ['method' => $request->getMethod()]); |
123 | 123 | $form->handleRequest($request); |
124 | 124 | |
125 | 125 | if ($form->isSubmitted() && $form->isValid()) { |
126 | - $objectManager->flush(); |
|
126 | + $objectManager->flush(); |
|
127 | 127 | |
128 | - return new SingleResourceResponse($redirectRoute, new ResponseContext(200)); |
|
128 | + return new SingleResourceResponse($redirectRoute, new ResponseContext(200)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return new SingleResourceResponse($form, new ResponseContext(400)); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - private function findOr404(int $id): RedirectRouteInterface { |
|
134 | + private function findOr404(int $id): RedirectRouteInterface { |
|
135 | 135 | if (null === $redirectRoute = $this->redirectRouteRepository->findOneById($id)) { |
136 | - throw new NotFoundHttpException('Redirect route was not found.'); |
|
136 | + throw new NotFoundHttpException('Redirect route was not found.'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $redirectRoute; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - private function ensureRedirectRouteExists(?string $name): void { |
|
142 | + private function ensureRedirectRouteExists(?string $name): void { |
|
143 | 143 | if (null !== $this->redirectRouteRepository->findOneBy(['routeName' => $name])) { |
144 | - throw new ConflictHttpException(sprintf('Redirect route "%s" already exists!', $name)); |
|
144 | + throw new ConflictHttpException(sprintf('Redirect route "%s" already exists!', $name)); |
|
145 | + } |
|
145 | 146 | } |
146 | - } |
|
147 | 147 | |
148 | - private function checkIfSourceRouteExists(RedirectRouteInterface $redirectRoute): bool { |
|
148 | + private function checkIfSourceRouteExists(RedirectRouteInterface $redirectRoute): bool { |
|
149 | 149 | return null === $redirectRoute->getRouteSource(); |
150 | - } |
|
150 | + } |
|
151 | 151 | } |
@@ -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 | /** |
@@ -27,73 +27,73 @@ |
||
27 | 27 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
28 | 28 | |
29 | 29 | class WebhookController extends AbstractAPIController { |
30 | - private WebhookRepositoryInterface $webhookRepository; |
|
31 | - private FormFactoryInterface $formFactory; |
|
32 | - private FactoryInterface $webhookFactory; |
|
33 | - private EntityManagerInterface $entityManager; |
|
34 | - private EventDispatcherInterface $eventDispatcher; |
|
30 | + private WebhookRepositoryInterface $webhookRepository; |
|
31 | + private FormFactoryInterface $formFactory; |
|
32 | + private FactoryInterface $webhookFactory; |
|
33 | + private EntityManagerInterface $entityManager; |
|
34 | + private EventDispatcherInterface $eventDispatcher; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param WebhookRepositoryInterface $webhookRepository |
|
38 | - * @param FormFactoryInterface $formFactory |
|
39 | - * @param FactoryInterface $webhookFactory |
|
40 | - * @param EntityManagerInterface $entityManager |
|
41 | - * @param EventDispatcherInterface $eventDispatcher |
|
42 | - */ |
|
43 | - public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
44 | - FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
45 | - EventDispatcherInterface $eventDispatcher) { |
|
36 | + /** |
|
37 | + * @param WebhookRepositoryInterface $webhookRepository |
|
38 | + * @param FormFactoryInterface $formFactory |
|
39 | + * @param FactoryInterface $webhookFactory |
|
40 | + * @param EntityManagerInterface $entityManager |
|
41 | + * @param EventDispatcherInterface $eventDispatcher |
|
42 | + */ |
|
43 | + public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
44 | + FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
45 | + EventDispatcherInterface $eventDispatcher) { |
|
46 | 46 | $this->webhookRepository = $webhookRepository; |
47 | 47 | $this->formFactory = $formFactory; |
48 | 48 | $this->webhookFactory = $webhookFactory; |
49 | 49 | $this->entityManager = $entityManager; |
50 | 50 | $this->eventDispatcher = $eventDispatcher; |
51 | - } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
56 | - */ |
|
57 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
54 | + /** |
|
55 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
56 | + */ |
|
57 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
58 | 58 | return $this->listWebhooks($this->eventDispatcher,$this->webhookRepository, $request); |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
63 | - */ |
|
64 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
61 | + /** |
|
62 | + * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
63 | + */ |
|
64 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
65 | 65 | return $this->getSingleWebhook($this->findOr404($id)); |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
70 | - */ |
|
71 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
68 | + /** |
|
69 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
70 | + */ |
|
71 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
72 | 72 | $ruleRepository = $this->webhookRepository; |
73 | 73 | $ruleFactory = $this->webhookFactory; |
74 | 74 | $formFactory = $this->formFactory; |
75 | 75 | |
76 | 76 | return $this->createWebhook($ruleRepository, $ruleFactory, $request, $formFactory); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
81 | - */ |
|
82 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
79 | + /** |
|
80 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
81 | + */ |
|
82 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
83 | 83 | $webhookRepository = $this->webhookRepository; |
84 | 84 | |
85 | 85 | return $this->deleteWebhook($webhookRepository, $this->findOr404($id)); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
90 | - */ |
|
91 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
88 | + /** |
|
89 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
90 | + */ |
|
91 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
92 | 92 | $objectManager = $this->entityManager; |
93 | 93 | $formFactory = $this->formFactory; |
94 | 94 | |
95 | 95 | return $this->updateWebhook($objectManager, $request, $this->findOr404($id), $formFactory); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | private function findOr404(int $id) |
99 | 99 | { |