@@ -40,30 +40,30 @@ discard block |
||
40 | 40 | use FOS\RestBundle\Controller\Annotations\Route; |
41 | 41 | |
42 | 42 | class ContentPushController extends AbstractController { |
43 | - private EventDispatcherInterface $eventDispatcher; |
|
44 | - private FormFactoryInterface $formFactory; |
|
45 | - private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
46 | - private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
47 | - private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
48 | - private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
49 | - private PackageRepository $packageRepository;//swp.repository.package |
|
50 | - private FileProviderInterface $fileProvider; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param EventDispatcherInterface $eventDispatcher |
|
54 | - * @param FormFactoryInterface $formFactory |
|
55 | - * @param MessageBusInterface $messageBus |
|
56 | - * @param DataTransformerInterface $dataTransformer |
|
57 | - * @param MediaManagerInterface $mediaManager |
|
58 | - * @param EntityManagerInterface $entityManager |
|
59 | - * @param PackageRepositoryInterface $packageRepository |
|
60 | - * @param FileProviderInterface $fileProvider |
|
61 | - */ |
|
62 | - public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
63 | - MessageBusInterface $messageBus, |
|
64 | - DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
65 | - EntityManagerInterface $entityManager, PackageRepository $packageRepository, |
|
66 | - FileProviderInterface $fileProvider) { |
|
43 | + private EventDispatcherInterface $eventDispatcher; |
|
44 | + private FormFactoryInterface $formFactory; |
|
45 | + private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
46 | + private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
47 | + private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
48 | + private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
49 | + private PackageRepository $packageRepository;//swp.repository.package |
|
50 | + private FileProviderInterface $fileProvider; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param EventDispatcherInterface $eventDispatcher |
|
54 | + * @param FormFactoryInterface $formFactory |
|
55 | + * @param MessageBusInterface $messageBus |
|
56 | + * @param DataTransformerInterface $dataTransformer |
|
57 | + * @param MediaManagerInterface $mediaManager |
|
58 | + * @param EntityManagerInterface $entityManager |
|
59 | + * @param PackageRepositoryInterface $packageRepository |
|
60 | + * @param FileProviderInterface $fileProvider |
|
61 | + */ |
|
62 | + public function __construct(EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, |
|
63 | + MessageBusInterface $messageBus, |
|
64 | + DataTransformerInterface $dataTransformer, MediaManagerInterface $mediaManager, |
|
65 | + EntityManagerInterface $entityManager, PackageRepository $packageRepository, |
|
66 | + FileProviderInterface $fileProvider) { |
|
67 | 67 | $this->eventDispatcher = $eventDispatcher; |
68 | 68 | $this->formFactory = $formFactory; |
69 | 69 | $this->messageBus = $messageBus; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | $this->entityManager = $entityManager; |
73 | 73 | $this->packageRepository = $packageRepository; |
74 | 74 | $this->fileProvider = $fileProvider; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
80 | - */ |
|
81 | - public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
78 | + /** |
|
79 | + * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
80 | + */ |
|
81 | + public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
82 | 82 | $package = $this->dataTransformer->transform($request->getContent()); |
83 | 83 | $this->eventDispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
84 | 84 | |
@@ -87,27 +87,27 @@ discard block |
||
87 | 87 | $this->messageBus->dispatch(new ContentPushMessage($currentTenant->getId(), $request->getContent())); |
88 | 88 | |
89 | 89 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
94 | - */ |
|
95 | - public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
92 | + /** |
|
93 | + * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
94 | + */ |
|
95 | + public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
96 | 96 | $form = $this->formFactory->createNamed('', MediaFileType::class); |
97 | 97 | $form->handleRequest($request); |
98 | 98 | |
99 | 99 | if ($form->isSubmitted() && $form->isValid()) { |
100 | - $mediaManager = $this->mediaManager; |
|
101 | - $uploadedFile = $form->getData()['media']; |
|
102 | - $mediaId = $request->request->get('mediaId'); |
|
100 | + $mediaManager = $this->mediaManager; |
|
101 | + $uploadedFile = $form->getData()['media']; |
|
102 | + $mediaId = $request->request->get('mediaId'); |
|
103 | 103 | |
104 | - if ($uploadedFile->isValid()) { |
|
104 | + if ($uploadedFile->isValid()) { |
|
105 | 105 | $fileProvider = $this->fileProvider; |
106 | 106 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $uploadedFile->guessExtension()); |
107 | 107 | |
108 | 108 | if (null === $file) { |
109 | - $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
110 | - $this->entityManager->flush(); |
|
109 | + $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
110 | + $this->entityManager->flush(); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return new SingleResourceResponse( |
@@ -120,23 +120,23 @@ discard block |
||
120 | 120 | ], |
121 | 121 | new ResponseContext(201) |
122 | 122 | ); |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | - throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
125 | + throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | return new SingleResourceResponse($form); |
129 | - } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
133 | - */ |
|
134 | - public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
131 | + /** |
|
132 | + * @Route("/api/{version}/assets/{action}/{mediaId}.{extension}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, requirements={"mediaId"=".+", "action"="get|push"}, name="swp_api_assets_get") |
|
133 | + */ |
|
134 | + public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
135 | 135 | $fileProvider = $this->fileProvider; |
136 | 136 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension); |
137 | 137 | |
138 | 138 | if (null === $file) { |
139 | - throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
139 | + throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $mediaManager = $this->mediaManager; |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | 'mime_type' => Mime::getMimeFromExtension($file->getFileExtension()), |
149 | 149 | 'filemeta' => [], |
150 | 150 | ]); |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | - protected function getPackageRepository() { |
|
153 | + protected function getPackageRepository() { |
|
154 | 154 | return $this->packageRepository; |
155 | - } |
|
155 | + } |
|
156 | 156 | } |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | class ContentPushController extends AbstractController { |
43 | 43 | private EventDispatcherInterface $eventDispatcher; |
44 | 44 | private FormFactoryInterface $formFactory; |
45 | - private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
45 | + private MessageBusInterface $messageBus; //swp_multi_tenancy.tenant_context |
|
46 | 46 | private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
47 | 47 | private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
48 | 48 | private EntityManagerInterface $entityManager; // swp.object_manager.media |
49 | - private PackageRepository $packageRepository;//swp.repository.package |
|
49 | + private PackageRepository $packageRepository; //swp.repository.package |
|
50 | 50 | private FileProviderInterface $fileProvider; |
51 | 51 | |
52 | 52 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ); |
123 | 123 | } |
124 | 124 | |
125 | - throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
125 | + throw new \Exception('Uploaded file is not valid:'.$uploadedFile->getErrorMessage()); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | return new SingleResourceResponse($form); |
@@ -131,14 +131,14 @@ discard block |
||
131 | 131 | $finder->in($configsPath)->files()->name('*.{yaml,yml}'); |
132 | 132 | $files = []; |
133 | 133 | foreach ($finder as $file) { |
134 | - $files[] = $file->getRealPath(); |
|
134 | + $files[] = $file->getRealPath(); |
|
135 | 135 | } |
136 | 136 | return $files; |
137 | 137 | }); |
138 | 138 | |
139 | - foreach ($files as $file) { |
|
139 | + foreach ($files as $file) { |
|
140 | 140 | $this->addNewConfig($file); |
141 | - } |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | { |
191 | 191 | $cacheKey = md5($filePath); |
192 | 192 | $configuration = $this->metadataCache->get($cacheKey, function () use ($filePath) { |
193 | - if (!is_readable($filePath)) { |
|
194 | - throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
|
195 | - } |
|
196 | - $parser = new Parser(); |
|
197 | - return $parser->parse(file_get_contents($filePath)); |
|
193 | + if (!is_readable($filePath)) { |
|
194 | + throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
|
195 | + } |
|
196 | + $parser = new Parser(); |
|
197 | + return $parser->parse(file_get_contents($filePath)); |
|
198 | 198 | }); |
199 | 199 | $this->addAvailableConfig($configuration); |
200 | 200 | $this->supportedCache = []; |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | { |
223 | 223 | $configuration = $meta->getConfiguration(); |
224 | 224 | if(array_key_exists("name" ,$configuration)) { |
225 | - $name = $configuration['name']; |
|
226 | - if (!array_key_exists($name, $this->registeredMeta)) { |
|
225 | + $name = $configuration['name']; |
|
226 | + if (!array_key_exists($name, $this->registeredMeta)) { |
|
227 | 227 | $this->registeredMeta[$name] = $configuration; |
228 | 228 | if (null !== $meta) { |
229 | - $this[$name] = $meta; |
|
229 | + $this[$name] = $meta; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | return true; |
233 | - } |
|
233 | + } |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return false; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function loadConfigsFromPath($configsPath) |
127 | 127 | { |
128 | 128 | if (file_exists($configsPath)) { |
129 | - $files = $this->metadataCache->get('metadata_config_files', function () use ($configsPath) { |
|
129 | + $files = $this->metadataCache->get('metadata_config_files', function() use ($configsPath) { |
|
130 | 130 | $finder = new Finder(); |
131 | 131 | $finder->in($configsPath)->files()->name('*.{yaml,yml}'); |
132 | 132 | $files = []; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | public function addNewConfig(string $filePath) |
190 | 190 | { |
191 | 191 | $cacheKey = md5($filePath); |
192 | - $configuration = $this->metadataCache->get($cacheKey, function () use ($filePath) { |
|
192 | + $configuration = $this->metadataCache->get($cacheKey, function() use ($filePath) { |
|
193 | 193 | if (!is_readable($filePath)) { |
194 | 194 | throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
195 | 195 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | public function registerMeta(Meta $meta = null) |
222 | 222 | { |
223 | 223 | $configuration = $meta->getConfiguration(); |
224 | - if(array_key_exists("name" ,$configuration)) { |
|
224 | + if (array_key_exists("name", $configuration)) { |
|
225 | 225 | $name = $configuration['name']; |
226 | 226 | if (!array_key_exists($name, $this->registeredMeta)) { |
227 | 227 | $this->registeredMeta[$name] = $configuration; |
@@ -41,29 +41,29 @@ discard block |
||
41 | 41 | use FOS\RestBundle\Controller\Annotations\Route; |
42 | 42 | |
43 | 43 | class OrganizationRuleController extends AbstractController { |
44 | - private FormFactoryInterface $formFactory; |
|
45 | - private EventDispatcherInterface $eventDispatcher; |
|
46 | - private CachedTenantContextInterface $cachedTenantContext; |
|
47 | - private EntityManagerInterface $entityManager; |
|
48 | - private RuleRepositoryInterface $ruleRepository; |
|
49 | - private RulesMatcherInterface $rulesMatcher; |
|
50 | - private FactoryInterface $ruleFactory; |
|
51 | - private DataTransformerInterface $dataTransformer; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param FormFactoryInterface $formFactory |
|
55 | - * @param EventDispatcherInterface $eventDispatcher |
|
56 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
57 | - * @param EntityManagerInterface $entityManager |
|
58 | - * @param RuleRepositoryInterface $ruleRepository |
|
59 | - * @param RulesMatcherInterface $rulesMatcher |
|
60 | - * @param FactoryInterface $ruleFactory |
|
61 | - * @param DataTransformerInterface $dataTransformer |
|
62 | - */ |
|
63 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | - CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
65 | - RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
66 | - FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
44 | + private FormFactoryInterface $formFactory; |
|
45 | + private EventDispatcherInterface $eventDispatcher; |
|
46 | + private CachedTenantContextInterface $cachedTenantContext; |
|
47 | + private EntityManagerInterface $entityManager; |
|
48 | + private RuleRepositoryInterface $ruleRepository; |
|
49 | + private RulesMatcherInterface $rulesMatcher; |
|
50 | + private FactoryInterface $ruleFactory; |
|
51 | + private DataTransformerInterface $dataTransformer; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param FormFactoryInterface $formFactory |
|
55 | + * @param EventDispatcherInterface $eventDispatcher |
|
56 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
57 | + * @param EntityManagerInterface $entityManager |
|
58 | + * @param RuleRepositoryInterface $ruleRepository |
|
59 | + * @param RulesMatcherInterface $rulesMatcher |
|
60 | + * @param FactoryInterface $ruleFactory |
|
61 | + * @param DataTransformerInterface $dataTransformer |
|
62 | + */ |
|
63 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
64 | + CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
65 | + RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
66 | + FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
67 | 67 | $this->formFactory = $formFactory; |
68 | 68 | $this->eventDispatcher = $eventDispatcher; |
69 | 69 | $this->cachedTenantContext = $cachedTenantContext; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | $this->rulesMatcher = $rulesMatcher; |
73 | 73 | $this->ruleFactory = $ruleFactory; |
74 | 74 | $this->dataTransformer = $dataTransformer; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
80 | - */ |
|
81 | - public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
78 | + /** |
|
79 | + * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
80 | + */ |
|
81 | + public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
82 | 82 | $content = $request->getContent(); |
83 | 83 | $dispatcher = $this->eventDispatcher; |
84 | 84 | $package = $this->dataTransformer->transform($content); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | $context = new ResponseContext(); |
90 | 90 | $context->setSerializationGroups(['Default', 'api']); |
91 | 91 | return new SingleResourceResponse($rules, $context); |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
96 | - */ |
|
97 | - public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
94 | + /** |
|
95 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
96 | + */ |
|
97 | + public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
98 | 98 | $tenantContext = $this->cachedTenantContext; |
99 | 99 | |
100 | 100 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | ); |
112 | 112 | |
113 | 113 | return new ResourcesListResponse($rules); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
118 | - */ |
|
119 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
116 | + /** |
|
117 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
118 | + */ |
|
119 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
120 | 120 | $ruleRepository = $this->getRuleRepository(); |
121 | 121 | |
122 | 122 | $rule = $this->ruleFactory->create(); |
@@ -124,54 +124,54 @@ discard block |
||
124 | 124 | $form->handleRequest($request); |
125 | 125 | |
126 | 126 | if ($form->isSubmitted() && $form->isValid()) { |
127 | - $ruleRepository->add($rule); |
|
128 | - $rule->setTenantCode(null); |
|
129 | - $ruleRepository->flush(); |
|
127 | + $ruleRepository->add($rule); |
|
128 | + $rule->setTenantCode(null); |
|
129 | + $ruleRepository->flush(); |
|
130 | 130 | |
131 | - return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
131 | + return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return new SingleResourceResponse($form, new ResponseContext(400)); |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
139 | - */ |
|
140 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
137 | + /** |
|
138 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
139 | + */ |
|
140 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
141 | 141 | return new SingleResourceResponse($this->findOr404($id)); |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
146 | - */ |
|
147 | - public function updateRuleAction(Request $request, int $id) { |
|
144 | + /** |
|
145 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
146 | + */ |
|
147 | + public function updateRuleAction(Request $request, int $id) { |
|
148 | 148 | $objectManager = $this->entityManager; |
149 | 149 | $rule = $this->findOr404($id); |
150 | 150 | $form = $this->formFactory->createNamed('', RuleType::class, $rule, ['method' => $request->getMethod()]); |
151 | 151 | |
152 | 152 | $form->handleRequest($request); |
153 | 153 | if ($form->isSubmitted() && $form->isValid()) { |
154 | - $objectManager->flush(); |
|
155 | - $objectManager->refresh($rule); |
|
154 | + $objectManager->flush(); |
|
155 | + $objectManager->refresh($rule); |
|
156 | 156 | |
157 | - return new SingleResourceResponse($rule); |
|
157 | + return new SingleResourceResponse($rule); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return new SingleResourceResponse($form, new ResponseContext(500)); |
161 | - } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
165 | - */ |
|
166 | - public function deleteAction(int $id) { |
|
163 | + /** |
|
164 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
165 | + */ |
|
166 | + public function deleteAction(int $id) { |
|
167 | 167 | $rule = $this->findOr404($id); |
168 | 168 | $ruleRepository = $this->ruleRepository; |
169 | 169 | $ruleRepository->remove($rule); |
170 | 170 | |
171 | 171 | return new SingleResourceResponse(null, new ResponseContext(204)); |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | - private function findOr404(int $id) { |
|
174 | + private function findOr404(int $id) { |
|
175 | 175 | $tenantContext = $this->cachedTenantContext; |
176 | 176 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
177 | 177 | |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | 'organization' => $tenantContext->getTenant()->getOrganization(), |
181 | 181 | 'tenantCode' => null, |
182 | 182 | ]))) { |
183 | - throw new NotFoundHttpException('Organization rule was not found.'); |
|
183 | + throw new NotFoundHttpException('Organization rule was not found.'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return $rule; |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | - private function getRuleRepository() { |
|
189 | + private function getRuleRepository() { |
|
190 | 190 | return $this->ruleRepository; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - private function getEventDispatcher() { |
|
193 | + private function getEventDispatcher() { |
|
194 | 194 | return $this->eventDispatcher; |
195 | - } |
|
195 | + } |
|
196 | 196 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | { |
334 | 334 | return $this->getExtraCollection() |
335 | 335 | ->map( |
336 | - function (ArticleExtraFieldInterface $field) { |
|
336 | + function(ArticleExtraFieldInterface $field) { |
|
337 | 337 | return $field->toApiFormat(); |
338 | 338 | } |
339 | 339 | )->toArray(); |
@@ -536,8 +536,8 @@ discard block |
||
536 | 536 | if (is_array($value)) { |
537 | 537 | $this->addEmbedExtra(ArticleExtraEmbedField::newFromValue($key, $value)); |
538 | 538 | } else { |
539 | - if(is_int($value)) { |
|
540 | - $value = (string)$value; |
|
539 | + if (is_int($value)) { |
|
540 | + $value = (string) $value; |
|
541 | 541 | } |
542 | 542 | $this->addTextExtra(ArticleExtraTextField::newFromValue($key, $value)); |
543 | 543 | } |
@@ -691,7 +691,7 @@ |
||
691 | 691 | */ |
692 | 692 | public function isCurrent(): bool |
693 | 693 | { |
694 | - return ($this->isCurrent?true:false); |
|
694 | + return ($this->isCurrent ?true:false); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -17,7 +17,7 @@ |
||
17 | 17 | { |
18 | 18 | // this up() migration is auto-generated, please modify it to your needs |
19 | 19 | $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
20 | - $this->addSql('ALTER TABLE swp_article ADD COLUMN IF NOT EXISTS feature_media INT DEFAULT NULL'); |
|
20 | + $this->addSql('ALTER TABLE swp_article ADD COLUMN IF NOT EXISTS feature_media INT DEFAULT NULL'); |
|
21 | 21 | $this->addSql('ALTER TABLE swp_article ADD CONSTRAINT FK_FB21E858A372AB05 FOREIGN KEY (feature_media) REFERENCES swp_article_media (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); |
22 | 22 | $this->addSql('CREATE INDEX IDX_FB21E858A372AB05 ON swp_article (feature_media)'); |
23 | 23 | } |
@@ -126,9 +126,9 @@ |
||
126 | 126 | return $data; |
127 | 127 | } |
128 | 128 | |
129 | - $callback = function ($matches) { |
|
129 | + $callback = function($matches) { |
|
130 | 130 | $matches[2] = trim(preg_replace('/\s\s+/', ' ', $matches[2])); |
131 | - return 's:' . mb_strlen($matches[2]) . ':"' . $matches[2] . '";'; |
|
131 | + return 's:'.mb_strlen($matches[2]).':"'.$matches[2].'";'; |
|
132 | 132 | }; |
133 | 133 | |
134 | 134 | $data = preg_replace_callback('!s:(\d+):"(.*?)";!s', $callback, $data); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if (is_array($extraItem)) { |
74 | 74 | $extra = ArticleExtraEmbedField::newFromValue($key, $extraItem); |
75 | 75 | } else { |
76 | - $extra = ArticleExtraTextField::newFromValue($key, (string)$extraItem); |
|
76 | + $extra = ArticleExtraTextField::newFromValue($key, (string) $extraItem); |
|
77 | 77 | } |
78 | 78 | $extra->setArticle($article); |
79 | 79 | $this->entityManager->persist($extra); |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | return $unserialized; |
114 | 114 | } |
115 | 115 | |
116 | - $callback = function ($matches) { |
|
116 | + $callback = function($matches) { |
|
117 | 117 | $matches[2] = trim(preg_replace('/\s\s+/', ' ', $matches[2])); |
118 | - return 's:' . mb_strlen($matches[2]) . ':"' . $matches[2] . '";'; |
|
118 | + return 's:'.mb_strlen($matches[2]).':"'.$matches[2].'";'; |
|
119 | 119 | }; |
120 | 120 | |
121 | 121 | $fixedData = preg_replace_callback('!s:(\d+):"(.*?)";!s', $callback, $data); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | 'secret' => $token, |
98 | 98 | ]; |
99 | 99 | |
100 | - $response = $client->request('POST', $url, [ |
|
100 | + $response = $client->request('POST', $url, [ |
|
101 | 101 | 'headers' => $headers, |
102 | 102 | 'json' => $data, |
103 | 103 | 'query' => $queryParams |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | ] |
117 | 117 | ]; |
118 | 118 | |
119 | - file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND); |
|
119 | + file_put_contents('/tmp/cache_invalidation.json', json_encode($result).PHP_EOL, FILE_APPEND); |
|
120 | 120 | } catch (\Throwable $e) { |
121 | - file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND); |
|
121 | + file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage().PHP_EOL, FILE_APPEND); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 |
@@ -44,36 +44,36 @@ discard block |
||
44 | 44 | |
45 | 45 | class ContentListController extends AbstractController { |
46 | 46 | |
47 | - private ContentListRepositoryInterface $contentListRepository; |
|
48 | - private ContentListItemRepositoryInterface $contentListItemRepository; |
|
49 | - private ContentListServiceInterface $contentListService; |
|
50 | - private FormFactoryInterface $formFactory; |
|
51 | - private EntityManagerInterface $entityManager; |
|
52 | - private EventDispatcherInterface $eventDispatcher; |
|
53 | - private FactoryInterface $factory; |
|
54 | - private string $invalidationCacheUrl; |
|
55 | - private string $invalidationToken; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param ContentListRepositoryInterface $contentListRepository |
|
59 | - * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
60 | - * @param ContentListServiceInterface $contentListService |
|
61 | - * @param FormFactoryInterface $formFactory |
|
62 | - * @param EntityManagerInterface $entityManager |
|
63 | - * @param EventDispatcherInterface $eventDispatcher |
|
64 | - * @param FactoryInterface $factory |
|
65 | - */ |
|
66 | - public function __construct( |
|
67 | - ContentListRepositoryInterface $contentListRepository, |
|
68 | - ContentListItemRepositoryInterface $contentListItemRepository, |
|
69 | - ContentListServiceInterface $contentListService, |
|
70 | - FormFactoryInterface $formFactory, |
|
71 | - EntityManagerInterface $entityManager, |
|
72 | - EventDispatcherInterface $eventDispatcher, |
|
73 | - FactoryInterface $factory, |
|
74 | - string $invalidationCacheUrl, |
|
75 | - string $invalidationToken |
|
76 | - ) { |
|
47 | + private ContentListRepositoryInterface $contentListRepository; |
|
48 | + private ContentListItemRepositoryInterface $contentListItemRepository; |
|
49 | + private ContentListServiceInterface $contentListService; |
|
50 | + private FormFactoryInterface $formFactory; |
|
51 | + private EntityManagerInterface $entityManager; |
|
52 | + private EventDispatcherInterface $eventDispatcher; |
|
53 | + private FactoryInterface $factory; |
|
54 | + private string $invalidationCacheUrl; |
|
55 | + private string $invalidationToken; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param ContentListRepositoryInterface $contentListRepository |
|
59 | + * @param ContentListItemRepositoryInterface $contentListItemRepository |
|
60 | + * @param ContentListServiceInterface $contentListService |
|
61 | + * @param FormFactoryInterface $formFactory |
|
62 | + * @param EntityManagerInterface $entityManager |
|
63 | + * @param EventDispatcherInterface $eventDispatcher |
|
64 | + * @param FactoryInterface $factory |
|
65 | + */ |
|
66 | + public function __construct( |
|
67 | + ContentListRepositoryInterface $contentListRepository, |
|
68 | + ContentListItemRepositoryInterface $contentListItemRepository, |
|
69 | + ContentListServiceInterface $contentListService, |
|
70 | + FormFactoryInterface $formFactory, |
|
71 | + EntityManagerInterface $entityManager, |
|
72 | + EventDispatcherInterface $eventDispatcher, |
|
73 | + FactoryInterface $factory, |
|
74 | + string $invalidationCacheUrl, |
|
75 | + string $invalidationToken |
|
76 | + ) { |
|
77 | 77 | $this->contentListRepository = $contentListRepository; |
78 | 78 | $this->contentListItemRepository = $contentListItemRepository; |
79 | 79 | $this->contentListService = $contentListService; |
@@ -83,65 +83,65 @@ discard block |
||
83 | 83 | $this->factory = $factory; |
84 | 84 | $this->invalidationCacheUrl = $invalidationCacheUrl; |
85 | 85 | $this->invalidationToken = $invalidationToken; |
86 | - } |
|
87 | - |
|
88 | - public static function invalidateCache(string $url, string $token, array $data = []) |
|
89 | - { |
|
90 | - try { |
|
91 | - $client = new Client(); |
|
92 | - |
|
93 | - $headers = [ |
|
94 | - 'Content-Type' => 'application/json', |
|
95 | - ]; |
|
96 | - $queryParams = [ |
|
97 | - 'secret' => $token, |
|
98 | - ]; |
|
99 | - |
|
100 | - $response = $client->request('POST', $url, [ |
|
101 | - 'headers' => $headers, |
|
102 | - 'json' => $data, |
|
103 | - 'query' => $queryParams |
|
104 | - ]); |
|
105 | - $responseBody = $response->getBody()->getContents(); |
|
106 | - $result = [ |
|
107 | - 'request' => [ |
|
108 | - 'headers' => $headers, |
|
109 | - 'json' => $data, |
|
110 | - 'query' => $queryParams |
|
111 | - ], |
|
112 | - 'response' => [ |
|
113 | - 'status' => $response->getStatusCode(), |
|
114 | - 'body' => $responseBody, |
|
115 | - 'ReasonPhrase' => $response->getReasonPhrase() |
|
116 | - ] |
|
117 | - ]; |
|
118 | - |
|
119 | - file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND); |
|
120 | - } catch (\Throwable $e) { |
|
121 | - file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") |
|
127 | - */ |
|
128 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
86 | + } |
|
87 | + |
|
88 | + public static function invalidateCache(string $url, string $token, array $data = []) |
|
89 | + { |
|
90 | + try { |
|
91 | + $client = new Client(); |
|
92 | + |
|
93 | + $headers = [ |
|
94 | + 'Content-Type' => 'application/json', |
|
95 | + ]; |
|
96 | + $queryParams = [ |
|
97 | + 'secret' => $token, |
|
98 | + ]; |
|
99 | + |
|
100 | + $response = $client->request('POST', $url, [ |
|
101 | + 'headers' => $headers, |
|
102 | + 'json' => $data, |
|
103 | + 'query' => $queryParams |
|
104 | + ]); |
|
105 | + $responseBody = $response->getBody()->getContents(); |
|
106 | + $result = [ |
|
107 | + 'request' => [ |
|
108 | + 'headers' => $headers, |
|
109 | + 'json' => $data, |
|
110 | + 'query' => $queryParams |
|
111 | + ], |
|
112 | + 'response' => [ |
|
113 | + 'status' => $response->getStatusCode(), |
|
114 | + 'body' => $responseBody, |
|
115 | + 'ReasonPhrase' => $response->getReasonPhrase() |
|
116 | + ] |
|
117 | + ]; |
|
118 | + |
|
119 | + file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND); |
|
120 | + } catch (\Throwable $e) { |
|
121 | + file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") |
|
127 | + */ |
|
128 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
129 | 129 | $lists = $this->contentListRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
130 | 130 | |
131 | 131 | return new ResourcesListResponse($lists); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) |
|
136 | - */ |
|
137 | - public function getAction($id): SingleResourceResponseInterface { |
|
134 | + /** |
|
135 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) |
|
136 | + */ |
|
137 | + public function getAction($id): SingleResourceResponseInterface { |
|
138 | 138 | return new SingleResourceResponse($this->findOr404($id)); |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") |
|
143 | - */ |
|
144 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
141 | + /** |
|
142 | + * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") |
|
143 | + */ |
|
144 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
145 | 145 | /* @var ContentListInterface $contentList */ |
146 | 146 | $contentList = $this->factory->create(); |
147 | 147 | $form = $this->formFactory->createNamed('', ContentListType::class, $contentList, ['method' => $request->getMethod()]); |
@@ -150,28 +150,28 @@ discard block |
||
150 | 150 | $this->ensureContentListExists($contentList->getName()); |
151 | 151 | |
152 | 152 | if ($form->isSubmitted() && $form->isValid()) { |
153 | - $this->contentListRepository->add($contentList); |
|
154 | - self::invalidateCache( |
|
155 | - $this->invalidationCacheUrl, |
|
156 | - $this->invalidationToken, |
|
157 | - [ |
|
158 | - 'id' => $contentList->getId(), |
|
159 | - 'name' => $contentList->getName(), |
|
160 | - 'type' => $contentList->getType(), |
|
161 | - 'action' => 'CREATE' |
|
162 | - ] |
|
153 | + $this->contentListRepository->add($contentList); |
|
154 | + self::invalidateCache( |
|
155 | + $this->invalidationCacheUrl, |
|
156 | + $this->invalidationToken, |
|
157 | + [ |
|
158 | + 'id' => $contentList->getId(), |
|
159 | + 'name' => $contentList->getName(), |
|
160 | + 'type' => $contentList->getType(), |
|
161 | + 'action' => 'CREATE' |
|
162 | + ] |
|
163 | 163 | ); |
164 | 164 | |
165 | - return new SingleResourceResponse($contentList, new ResponseContext(201)); |
|
165 | + return new SingleResourceResponse($contentList, new ResponseContext(201)); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return new SingleResourceResponse($form, new ResponseContext(400)); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) |
|
173 | - */ |
|
174 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
171 | + /** |
|
172 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) |
|
173 | + */ |
|
174 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
175 | 175 | $objectManager = $this->entityManager; |
176 | 176 | /** @var ContentListInterface $contentList */ |
177 | 177 | $contentList = $this->findOr404($id); |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | $form->handleRequest($request); |
183 | 183 | |
184 | 184 | if ($form->isSubmitted() && $form->isValid()) { |
185 | - $this->eventDispatcher->dispatch( |
|
186 | - new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), |
|
187 | - ContentListEvents::LIST_CRITERIA_CHANGE |
|
188 | - ); |
|
185 | + $this->eventDispatcher->dispatch( |
|
186 | + new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), |
|
187 | + ContentListEvents::LIST_CRITERIA_CHANGE |
|
188 | + ); |
|
189 | 189 | |
190 | - $objectManager->flush(); |
|
190 | + $objectManager->flush(); |
|
191 | 191 | self::invalidateCache( |
192 | 192 | $this->invalidationCacheUrl, |
193 | 193 | $this->invalidationToken, |
@@ -199,54 +199,54 @@ discard block |
||
199 | 199 | ] |
200 | 200 | ); |
201 | 201 | |
202 | - return new SingleResourceResponse($contentList); |
|
202 | + return new SingleResourceResponse($contentList); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return new SingleResourceResponse($form, new ResponseContext(400)); |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) |
|
210 | - */ |
|
211 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
208 | + /** |
|
209 | + * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) |
|
210 | + */ |
|
211 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
212 | 212 | $repository = $this->contentListRepository; |
213 | 213 | $contentList = $this->findOr404($id); |
214 | 214 | |
215 | 215 | $repository->remove($contentList); |
216 | - self::invalidateCache( |
|
217 | - $this->invalidationCacheUrl, |
|
218 | - $this->invalidationToken, |
|
219 | - [ |
|
220 | - 'id' => $contentList->getId(), |
|
221 | - 'name' => $contentList->getName(), |
|
222 | - 'type' => $contentList->getType(), |
|
223 | - 'action' => 'DELETE' |
|
224 | - ] |
|
225 | - ); |
|
216 | + self::invalidateCache( |
|
217 | + $this->invalidationCacheUrl, |
|
218 | + $this->invalidationToken, |
|
219 | + [ |
|
220 | + 'id' => $contentList->getId(), |
|
221 | + 'name' => $contentList->getName(), |
|
222 | + 'type' => $contentList->getType(), |
|
223 | + 'action' => 'DELETE' |
|
224 | + ] |
|
225 | + ); |
|
226 | 226 | |
227 | 227 | return new SingleResourceResponse(null, new ResponseContext(204)); |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") |
|
232 | - */ |
|
233 | - public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { |
|
230 | + /** |
|
231 | + * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") |
|
232 | + */ |
|
233 | + public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { |
|
234 | 234 | $objectManager = $this->entityManager; |
235 | 235 | /** @var ContentListInterface $contentList */ |
236 | 236 | $contentList = $this->findOr404($id); |
237 | 237 | |
238 | 238 | $matched = false; |
239 | 239 | foreach ($request->attributes->get('links', []) as $key => $objectArray) { |
240 | - if (!is_array($objectArray)) { |
|
240 | + if (!is_array($objectArray)) { |
|
241 | 241 | continue; |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | - $object = $objectArray['object']; |
|
245 | - if ($object instanceof Exception) { |
|
244 | + $object = $objectArray['object']; |
|
245 | + if ($object instanceof Exception) { |
|
246 | 246 | throw $object; |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - if ($object instanceof ArticleInterface) { |
|
249 | + if ($object instanceof ArticleInterface) { |
|
250 | 250 | $contentListItem = $this->contentListItemRepository |
251 | 251 | ->findOneBy([ |
252 | 252 | 'contentList' => $contentList, |
@@ -254,59 +254,59 @@ discard block |
||
254 | 254 | ]); |
255 | 255 | |
256 | 256 | if ('LINK' === $request->getMethod()) { |
257 | - $position = 0; |
|
258 | - if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { |
|
257 | + $position = 0; |
|
258 | + if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { |
|
259 | 259 | foreach ($notConvertedLinks as $link) { |
260 | - if (isset($link['resourceType']) && 'position' === $link['resourceType']) { |
|
260 | + if (isset($link['resourceType']) && 'position' === $link['resourceType']) { |
|
261 | 261 | $position = $link['resource']; |
262 | - } |
|
262 | + } |
|
263 | + } |
|
263 | 264 | } |
264 | - } |
|
265 | 265 | |
266 | - if (false === $position && $contentListItem) { |
|
266 | + if (false === $position && $contentListItem) { |
|
267 | 267 | throw new ConflictHttpException('This content is already linked to Content List'); |
268 | - } |
|
268 | + } |
|
269 | 269 | |
270 | - if (!$contentListItem) { |
|
270 | + if (!$contentListItem) { |
|
271 | 271 | $contentListItem = $this->contentListService->addArticleToContentList($contentList, $object, $position); |
272 | 272 | $objectManager->persist($contentListItem); |
273 | - } else { |
|
273 | + } else { |
|
274 | 274 | $contentListItem->setPosition($position); |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - $objectManager->flush(); |
|
277 | + $objectManager->flush(); |
|
278 | 278 | } elseif ('UNLINK' === $request->getMethod()) { |
279 | - if ($contentListItem->getContentList() !== $contentList) { |
|
279 | + if ($contentListItem->getContentList() !== $contentList) { |
|
280 | 280 | throw new ConflictHttpException('Content is not linked to content list'); |
281 | - } |
|
282 | - $objectManager->remove($contentListItem); |
|
281 | + } |
|
282 | + $objectManager->remove($contentListItem); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $matched = true; |
286 | 286 | |
287 | 287 | break; |
288 | - } |
|
288 | + } |
|
289 | 289 | } |
290 | 290 | if (false === $matched) { |
291 | - throw new NotFoundHttpException('Any supported link object was not found'); |
|
291 | + throw new NotFoundHttpException('Any supported link object was not found'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | $objectManager->flush(); |
295 | 295 | |
296 | 296 | return new SingleResourceResponse($contentList, new ResponseContext(201)); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - private function findOr404($id) { |
|
299 | + private function findOr404($id) { |
|
300 | 300 | if (null === $list = $this->contentListRepository->find($id)) { |
301 | - throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); |
|
301 | + throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | return $list; |
305 | - } |
|
305 | + } |
|
306 | 306 | |
307 | - private function ensureContentListExists($name) { |
|
307 | + private function ensureContentListExists($name) { |
|
308 | 308 | if (null !== $this->contentListRepository->findOneBy(['name' => $name])) { |
309 | - throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); |
|
309 | + throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); |
|
310 | + } |
|
310 | 311 | } |
311 | - } |
|
312 | 312 | } |