@@ -29,50 +29,50 @@ |
||
| 29 | 29 | |
| 30 | 30 | class ThemeLogoController extends Controller { |
| 31 | 31 | |
| 32 | - private Filesystem $filesystem; |
|
| 33 | - private ThemeLogoUploaderInterface $themeLogoUploader; |
|
| 34 | - private CacheInterface $cacheInterface; |
|
| 32 | + private Filesystem $filesystem; |
|
| 33 | + private ThemeLogoUploaderInterface $themeLogoUploader; |
|
| 34 | + private CacheInterface $cacheInterface; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param Filesystem $filesystem |
|
| 38 | - * @param ThemeLogoUploaderInterface $themeLogoUploader |
|
| 39 | - * @param CacheInterface $cacheInterface |
|
| 40 | - */ |
|
| 41 | - public function __construct(Filesystem $filesystem, ThemeLogoUploaderInterface $themeLogoUploader, |
|
| 42 | - CacheInterface $cacheInterface) { |
|
| 36 | + /** |
|
| 37 | + * @param Filesystem $filesystem |
|
| 38 | + * @param ThemeLogoUploaderInterface $themeLogoUploader |
|
| 39 | + * @param CacheInterface $cacheInterface |
|
| 40 | + */ |
|
| 41 | + public function __construct(Filesystem $filesystem, ThemeLogoUploaderInterface $themeLogoUploader, |
|
| 42 | + CacheInterface $cacheInterface) { |
|
| 43 | 43 | $this->filesystem = $filesystem; |
| 44 | 44 | $this->themeLogoUploader = $themeLogoUploader; |
| 45 | 45 | $this->cacheInterface = $cacheInterface; |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @Route("/theme_logo/{id}", options={"expose"=true}, requirements={"id"=".+"}, methods={"GET"}, name="swp_theme_logo_get") |
|
| 50 | - */ |
|
| 51 | - public function getLogoAction(string $id) { |
|
| 48 | + /** |
|
| 49 | + * @Route("/theme_logo/{id}", options={"expose"=true}, requirements={"id"=".+"}, methods={"GET"}, name="swp_theme_logo_get") |
|
| 50 | + */ |
|
| 51 | + public function getLogoAction(string $id) { |
|
| 52 | 52 | $cacheKey = md5(serialize(['upload', $id])); |
| 53 | 53 | return $this->cacheInterface->get($cacheKey, function (CacheItemInterface $item, &$save) use ($id) { |
| 54 | - $item->expiresAfter(63072000); |
|
| 54 | + $item->expiresAfter(63072000); |
|
| 55 | 55 | |
| 56 | - $fileSystem = $this->filesystem; |
|
| 57 | - $themeLogoUploader = $this->themeLogoUploader; |
|
| 58 | - $id = $themeLogoUploader->getThemeLogoUploadPath($id); |
|
| 59 | - $file = $fileSystem->has($id); |
|
| 60 | - if (!$file) { |
|
| 56 | + $fileSystem = $this->filesystem; |
|
| 57 | + $themeLogoUploader = $this->themeLogoUploader; |
|
| 58 | + $id = $themeLogoUploader->getThemeLogoUploadPath($id); |
|
| 59 | + $file = $fileSystem->has($id); |
|
| 60 | + if (!$file) { |
|
| 61 | 61 | $save = false; |
| 62 | 62 | throw new NotFoundHttpException('File was not found.'); |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $path = $fileSystem->get($id)->getPath(); |
|
| 66 | - $response = new Response(); |
|
| 67 | - $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, pathinfo($path, PATHINFO_BASENAME)); |
|
| 68 | - $response->headers->set('Content-Disposition', $disposition); |
|
| 69 | - $response->headers->set('Content-Type', MimeTypeHelper::getByPath($path)); |
|
| 70 | - $response->setPublic(); |
|
| 71 | - $response->setMaxAge(63072000); |
|
| 72 | - $response->setSharedMaxAge(63072000); |
|
| 73 | - $response->setContent($fileSystem->read($path)); |
|
| 65 | + $path = $fileSystem->get($id)->getPath(); |
|
| 66 | + $response = new Response(); |
|
| 67 | + $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, pathinfo($path, PATHINFO_BASENAME)); |
|
| 68 | + $response->headers->set('Content-Disposition', $disposition); |
|
| 69 | + $response->headers->set('Content-Type', MimeTypeHelper::getByPath($path)); |
|
| 70 | + $response->setPublic(); |
|
| 71 | + $response->setMaxAge(63072000); |
|
| 72 | + $response->setSharedMaxAge(63072000); |
|
| 73 | + $response->setContent($fileSystem->read($path)); |
|
| 74 | 74 | |
| 75 | - return $response; |
|
| 75 | + return $response; |
|
| 76 | 76 | }); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -43,53 +43,53 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | class RegistrationController extends AbstractController { |
| 45 | 45 | |
| 46 | - private SettingsManagerInterface $settingsManager; |
|
| 47 | - private ScopeContextInterface $scopeContext; |
|
| 48 | - private EmailVerifier $emailVerifier; |
|
| 49 | - private UserManagerInterface $userManager; |
|
| 50 | - private EntityManagerInterface $entityManager; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param SettingsManagerInterface $settingsManager |
|
| 54 | - * @param ScopeContextInterface $scopeContext |
|
| 55 | - * @param EmailVerifier $emailVerifier |
|
| 56 | - * @param UserManagerInterface $userManager |
|
| 57 | - * @param EntityManagerInterface $entityManager |
|
| 58 | - */ |
|
| 59 | - public function __construct( |
|
| 60 | - SettingsManagerInterface $settingsManager, |
|
| 61 | - ScopeContextInterface $scopeContext, |
|
| 62 | - EmailVerifier $emailVerifier, |
|
| 63 | - UserManagerInterface $userManager, |
|
| 64 | - EntityManagerInterface $entityManager |
|
| 65 | - ) { |
|
| 46 | + private SettingsManagerInterface $settingsManager; |
|
| 47 | + private ScopeContextInterface $scopeContext; |
|
| 48 | + private EmailVerifier $emailVerifier; |
|
| 49 | + private UserManagerInterface $userManager; |
|
| 50 | + private EntityManagerInterface $entityManager; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param SettingsManagerInterface $settingsManager |
|
| 54 | + * @param ScopeContextInterface $scopeContext |
|
| 55 | + * @param EmailVerifier $emailVerifier |
|
| 56 | + * @param UserManagerInterface $userManager |
|
| 57 | + * @param EntityManagerInterface $entityManager |
|
| 58 | + */ |
|
| 59 | + public function __construct( |
|
| 60 | + SettingsManagerInterface $settingsManager, |
|
| 61 | + ScopeContextInterface $scopeContext, |
|
| 62 | + EmailVerifier $emailVerifier, |
|
| 63 | + UserManagerInterface $userManager, |
|
| 64 | + EntityManagerInterface $entityManager |
|
| 65 | + ) { |
|
| 66 | 66 | $this->settingsManager = $settingsManager; |
| 67 | 67 | $this->scopeContext = $scopeContext; |
| 68 | 68 | $this->emailVerifier = $emailVerifier; |
| 69 | 69 | $this->userManager = $userManager; |
| 70 | 70 | $this->entityManager = $entityManager; |
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @FOSRoute( |
|
| 76 | - * "/api/{version}/users/register/", |
|
| 77 | - * methods={"POST"}, |
|
| 78 | - * options={"expose"=true}, |
|
| 79 | - * defaults={"version"="v2"}, |
|
| 80 | - * name="swp_api_core_register_user" |
|
| 81 | - * ) |
|
| 82 | - */ |
|
| 83 | - public function registerAction( |
|
| 84 | - Request $request, |
|
| 85 | - UserPasswordHasherInterface $userPasswordEncoder, |
|
| 86 | - UserManagerInterface $userManager, |
|
| 87 | - MailerInterface $mailer |
|
| 88 | - ) { |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @FOSRoute( |
|
| 76 | + * "/api/{version}/users/register/", |
|
| 77 | + * methods={"POST"}, |
|
| 78 | + * options={"expose"=true}, |
|
| 79 | + * defaults={"version"="v2"}, |
|
| 80 | + * name="swp_api_core_register_user" |
|
| 81 | + * ) |
|
| 82 | + */ |
|
| 83 | + public function registerAction( |
|
| 84 | + Request $request, |
|
| 85 | + UserPasswordHasherInterface $userPasswordEncoder, |
|
| 86 | + UserManagerInterface $userManager, |
|
| 87 | + MailerInterface $mailer |
|
| 88 | + ) { |
|
| 89 | 89 | try { |
| 90 | - $this->ensureThatRegistrationIsEnabled(); |
|
| 90 | + $this->ensureThatRegistrationIsEnabled(); |
|
| 91 | 91 | } catch (NotFoundHttpException $e) { |
| 92 | - return new SingleResourceResponse(null, new ResponseContext(404)); |
|
| 92 | + return new SingleResourceResponse(null, new ResponseContext(404)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $user = $userManager->createUser(); |
@@ -98,69 +98,69 @@ discard block |
||
| 98 | 98 | $form->handleRequest($request); |
| 99 | 99 | |
| 100 | 100 | if ($form->isSubmitted() && $form->isValid()) { |
| 101 | - $user->addRole('ROLE_USER'); |
|
| 102 | - // encode the plain password |
|
| 103 | - $user->setPassword( |
|
| 104 | - $userPasswordEncoder->hashPassword( |
|
| 105 | - $user, |
|
| 106 | - $form->get('plainPassword')->getData() |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - |
|
| 110 | - $entityManager = $this->entityManager; |
|
| 111 | - $entityManager->persist($user); |
|
| 112 | - $entityManager->flush(); |
|
| 113 | - |
|
| 114 | - $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
| 115 | - $url = $signatureComponents->getSignedUrl(); |
|
| 116 | - |
|
| 117 | - $mailer->sendConfirmationEmail($user, $url); |
|
| 118 | - |
|
| 119 | - return new JsonResponse([ |
|
| 120 | - 'message' => sprintf( |
|
| 121 | - 'The user has been created successfully. |
|
| 101 | + $user->addRole('ROLE_USER'); |
|
| 102 | + // encode the plain password |
|
| 103 | + $user->setPassword( |
|
| 104 | + $userPasswordEncoder->hashPassword( |
|
| 105 | + $user, |
|
| 106 | + $form->get('plainPassword')->getData() |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + $entityManager = $this->entityManager; |
|
| 111 | + $entityManager->persist($user); |
|
| 112 | + $entityManager->flush(); |
|
| 113 | + |
|
| 114 | + $signatureComponents = $this->emailVerifier->getSignatureComponents('swp_user_verify_email', $user); |
|
| 115 | + $url = $signatureComponents->getSignedUrl(); |
|
| 116 | + |
|
| 117 | + $mailer->sendConfirmationEmail($user, $url); |
|
| 118 | + |
|
| 119 | + return new JsonResponse([ |
|
| 120 | + 'message' => sprintf( |
|
| 121 | + 'The user has been created successfully. |
|
| 122 | 122 | An email has been sent to %s. It contains an activation link you must click to activate your account.', |
| 123 | - $user->getEmail() |
|
| 124 | - ), |
|
| 125 | - 'url' => $url, |
|
| 126 | - ]); |
|
| 123 | + $user->getEmail() |
|
| 124 | + ), |
|
| 125 | + 'url' => $url, |
|
| 126 | + ]); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @Route("/verify/email", name="swp_user_verify_email") |
|
| 134 | - */ |
|
| 135 | - public function verifyUserEmail( |
|
| 136 | - Request $request, |
|
| 137 | - GuardAuthenticatorHandler $guardHandler, |
|
| 138 | - LoginAuthenticator $authenticator |
|
| 139 | - ): Response { |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @Route("/verify/email", name="swp_user_verify_email") |
|
| 134 | + */ |
|
| 135 | + public function verifyUserEmail( |
|
| 136 | + Request $request, |
|
| 137 | + GuardAuthenticatorHandler $guardHandler, |
|
| 138 | + LoginAuthenticator $authenticator |
|
| 139 | + ): Response { |
|
| 140 | 140 | $id = (int)$request->get('id'); // retrieve the user id from the url |
| 141 | 141 | |
| 142 | 142 | if ($request->isXmlHttpRequest()) { |
| 143 | - return $this->verifyUserEmailFromPWA($id, $request); |
|
| 143 | + return $this->verifyUserEmailFromPWA($id, $request); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Verify the user id exists and is not null |
| 147 | 147 | if (null === $id) { |
| 148 | - return $this->redirectToRoute('homepage'); |
|
| 148 | + return $this->redirectToRoute('homepage'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $user = $this->userManager->find($id); |
| 152 | 152 | |
| 153 | 153 | // Ensure the user exists in persistence |
| 154 | 154 | if (null === $user) { |
| 155 | - return $this->redirectToRoute('homepage'); |
|
| 155 | + return $this->redirectToRoute('homepage'); |
|
| 156 | 156 | } |
| 157 | 157 | // validate email confirmation link, sets User::isVerified=true and persists |
| 158 | 158 | try { |
| 159 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
| 159 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
| 160 | 160 | } catch (VerifyEmailExceptionInterface $exception) { |
| 161 | - $this->addFlash('verify_email_error', $exception->getReason()); |
|
| 161 | + $this->addFlash('verify_email_error', $exception->getReason()); |
|
| 162 | 162 | |
| 163 | - return $this->redirectToRoute('homepage'); |
|
| 163 | + return $this->redirectToRoute('homepage'); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
@@ -174,63 +174,63 @@ discard block |
||
| 174 | 174 | $this->addFlash('success', 'The user has been created successfully.'); |
| 175 | 175 | |
| 176 | 176 | return $this->redirectToRoute('swp_user_registration_confirmed'); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Tell the user his account is now confirmed. |
|
| 181 | - */ |
|
| 182 | - public function confirmedAction(Request $request) { |
|
| 179 | + /** |
|
| 180 | + * Tell the user his account is now confirmed. |
|
| 181 | + */ |
|
| 182 | + public function confirmedAction(Request $request) { |
|
| 183 | 183 | $user = $this->getUser(); |
| 184 | 184 | if (!is_object($user) || !$user instanceof UserInterface) { |
| 185 | - $this->createAccessDeniedException('This user does not have access to this section.'); |
|
| 185 | + $this->createAccessDeniedException('This user does not have access to this section.'); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | return $this->render('@SWPUser/Registration/confirmed.html.twig', [ |
| 189 | 189 | 'user' => $user, |
| 190 | 190 | ]); |
| 191 | - } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @throws NotFoundHttpException |
|
| 195 | - */ |
|
| 196 | - private function ensureThatRegistrationIsEnabled() { |
|
| 193 | + /** |
|
| 194 | + * @throws NotFoundHttpException |
|
| 195 | + */ |
|
| 196 | + private function ensureThatRegistrationIsEnabled() { |
|
| 197 | 197 | $settingName = 'registration_enabled'; |
| 198 | 198 | $setting = $this->settingsManager->getOneSettingByName($settingName); |
| 199 | 199 | $registrationEnabled = $this->settingsManager |
| 200 | 200 | ->get($settingName, $setting['scope'], $this->scopeContext->getScopeOwner($setting['scope'])); |
| 201 | 201 | if (!$registrationEnabled) { |
| 202 | - throw new NotFoundHttpException('Registration is disabled.'); |
|
| 202 | + throw new NotFoundHttpException('Registration is disabled.'); |
|
| 203 | + } |
|
| 203 | 204 | } |
| 204 | - } |
|
| 205 | 205 | |
| 206 | - private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
| 206 | + private function verifyUserEmailFromPWA(int $id, Request $request): JsonResponse { |
|
| 207 | 207 | // Verify the user id exists and is not null |
| 208 | 208 | if (null === $id) { |
| 209 | - return new JsonResponse( |
|
| 210 | - ['error' => 'User does not exist'] |
|
| 211 | - ); |
|
| 209 | + return new JsonResponse( |
|
| 210 | + ['error' => 'User does not exist'] |
|
| 211 | + ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $user = $this->userManager->find($id); |
| 215 | 215 | |
| 216 | 216 | // Ensure the user exists in persistence |
| 217 | 217 | if (null === $user) { |
| 218 | - return new JsonResponse( |
|
| 219 | - ['error' => 'User does not exist'] |
|
| 220 | - ); |
|
| 218 | + return new JsonResponse( |
|
| 219 | + ['error' => 'User does not exist'] |
|
| 220 | + ); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // validate email confirmation link, sets User::isVerified=true and persists |
| 224 | 224 | try { |
| 225 | - $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
| 225 | + $this->emailVerifier->handleEmailConfirmation($request, $user); |
|
| 226 | 226 | } catch (VerifyEmailExceptionInterface $exception) { |
| 227 | - return new JsonResponse( |
|
| 228 | - ['error' => 'Registration confirmation invalid'] |
|
| 229 | - ); |
|
| 227 | + return new JsonResponse( |
|
| 228 | + ['error' => 'Registration confirmation invalid'] |
|
| 229 | + ); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return new JsonResponse( |
| 233 | 233 | ['message' => 'The user has been created successfully.'] |
| 234 | 234 | ); |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -38,117 +38,117 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | class AuthController extends AbstractController |
| 40 | 40 | { |
| 41 | - protected FormFactoryInterface $formFactory; |
|
| 42 | - protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
| 43 | - protected ApiKeyFactory $apiKeyFactory; |
|
| 44 | - protected LockFactory $lockFactory; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param FormFactoryInterface $formFactory |
|
| 48 | - * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
| 49 | - * @param ApiKeyFactory $apiKeyFactory |
|
| 50 | - * @param LockFactory $lockFactory |
|
| 51 | - */ |
|
| 52 | - public function __construct( |
|
| 53 | - FormFactoryInterface $formFactory, |
|
| 54 | - ApiKeyRepositoryInterface $apiKeyRepository, |
|
| 55 | - ApiKeyFactory$apiKeyFactory, |
|
| 56 | - LockFactory $lockFactory |
|
| 57 | - ) { |
|
| 41 | + protected FormFactoryInterface $formFactory; |
|
| 42 | + protected ApiKeyRepositoryInterface $apiKeyRepository; |
|
| 43 | + protected ApiKeyFactory $apiKeyFactory; |
|
| 44 | + protected LockFactory $lockFactory; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param FormFactoryInterface $formFactory |
|
| 48 | + * @param ApiKeyRepositoryInterface $apiKeyRepository |
|
| 49 | + * @param ApiKeyFactory $apiKeyFactory |
|
| 50 | + * @param LockFactory $lockFactory |
|
| 51 | + */ |
|
| 52 | + public function __construct( |
|
| 53 | + FormFactoryInterface $formFactory, |
|
| 54 | + ApiKeyRepositoryInterface $apiKeyRepository, |
|
| 55 | + ApiKeyFactory$apiKeyFactory, |
|
| 56 | + LockFactory $lockFactory |
|
| 57 | + ) { |
|
| 58 | 58 | $this->formFactory = $formFactory; |
| 59 | 59 | $this->apiKeyRepository = $apiKeyRepository; |
| 60 | 60 | $this->apiKeyFactory = $apiKeyFactory; |
| 61 | 61 | $this->lockFactory = $lockFactory; |
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @Route( |
|
| 67 | - * "/api/{version}/auth/", |
|
| 68 | - * options={"expose"=true}, |
|
| 69 | - * defaults={"version"="v2"}, |
|
| 70 | - * methods={"POST"}, |
|
| 71 | - * name="swp_api_auth" |
|
| 72 | - * ) |
|
| 73 | - */ |
|
| 74 | - public function authenticateAction( |
|
| 75 | - Request $request, |
|
| 76 | - UserProviderInterface $userProvider, |
|
| 77 | - UserPasswordHasherInterface $userPasswordEncoder |
|
| 78 | - ) { |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @Route( |
|
| 67 | + * "/api/{version}/auth/", |
|
| 68 | + * options={"expose"=true}, |
|
| 69 | + * defaults={"version"="v2"}, |
|
| 70 | + * methods={"POST"}, |
|
| 71 | + * name="swp_api_auth" |
|
| 72 | + * ) |
|
| 73 | + */ |
|
| 74 | + public function authenticateAction( |
|
| 75 | + Request $request, |
|
| 76 | + UserProviderInterface $userProvider, |
|
| 77 | + UserPasswordHasherInterface $userPasswordEncoder |
|
| 78 | + ) { |
|
| 79 | 79 | $form = $this->formFactory->createNamed('', UserAuthenticationType::class, []); |
| 80 | 80 | $form->handleRequest($request); |
| 81 | 81 | if ($form->isSubmitted() && $form->isValid()) { |
| 82 | - $formData = $form->getData(); |
|
| 82 | + $formData = $form->getData(); |
|
| 83 | 83 | |
| 84 | - try { |
|
| 84 | + try { |
|
| 85 | 85 | $user = $userProvider->loadUserByIdentifier($formData['username']); |
| 86 | - } catch (AuthenticationException $e) { |
|
| 86 | + } catch (AuthenticationException $e) { |
|
| 87 | 87 | $user = null; |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
| 90 | + if ((null !== $user) && $userPasswordEncoder->isPasswordValid($user, $formData['password'])) { |
|
| 91 | 91 | return $this->returnApiTokenResponse($user); |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return new SingleResourceResponse([ |
| 96 | 96 | 'status' => 401, |
| 97 | 97 | 'message' => 'Unauthorized', |
| 98 | 98 | ], new ResponseContext(401)); |
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @Route( |
|
| 103 | - * "/api/{version}/auth/superdesk/", |
|
| 104 | - * options={"expose"=true}, |
|
| 105 | - * methods={"POST"}, |
|
| 106 | - * defaults={"version"="v2"}, |
|
| 107 | - * name="swp_api_auth_superdesk" |
|
| 108 | - * ) |
|
| 109 | - */ |
|
| 110 | - public function authenticateWithSuperdeskAction( |
|
| 111 | - Request $request, |
|
| 112 | - LoggerInterface $logger, |
|
| 113 | - array $superdeskServers, |
|
| 114 | - UserProviderInterface $userProvider, |
|
| 115 | - UserManagerInterface $userManager |
|
| 116 | - ) { |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @Route( |
|
| 103 | + * "/api/{version}/auth/superdesk/", |
|
| 104 | + * options={"expose"=true}, |
|
| 105 | + * methods={"POST"}, |
|
| 106 | + * defaults={"version"="v2"}, |
|
| 107 | + * name="swp_api_auth_superdesk" |
|
| 108 | + * ) |
|
| 109 | + */ |
|
| 110 | + public function authenticateWithSuperdeskAction( |
|
| 111 | + Request $request, |
|
| 112 | + LoggerInterface $logger, |
|
| 113 | + array $superdeskServers, |
|
| 114 | + UserProviderInterface $userProvider, |
|
| 115 | + UserManagerInterface $userManager |
|
| 116 | + ) { |
|
| 117 | 117 | $form = $this->formFactory->createNamed('', SuperdeskCredentialAuthenticationType::class, []); |
| 118 | 118 | $form->handleRequest($request); |
| 119 | 119 | if ($form->isSubmitted() && $form->isValid()) { |
| 120 | - $formData = $form->getData(); |
|
| 121 | - $authorizedSuperdeskHosts = $superdeskServers; |
|
| 122 | - $superdeskUser = null; |
|
| 123 | - $client = new GuzzleHttp\Client(); |
|
| 120 | + $formData = $form->getData(); |
|
| 121 | + $authorizedSuperdeskHosts = $superdeskServers; |
|
| 122 | + $superdeskUser = null; |
|
| 123 | + $client = new GuzzleHttp\Client(); |
|
| 124 | 124 | |
| 125 | - foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
| 125 | + foreach ($authorizedSuperdeskHosts as $baseUrl) { |
|
| 126 | 126 | try { |
| 127 | - $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
| 128 | - 'Authorization' => $formData['token'], |
|
| 129 | - ]); |
|
| 127 | + $apiRequest = new GuzzleHttp\Psr7\Request('GET', sprintf('%s/api/sessions/%s', $baseUrl, $formData['sessionId']), [ |
|
| 128 | + 'Authorization' => $formData['token'], |
|
| 129 | + ]); |
|
| 130 | 130 | |
| 131 | - $apiResponse = $client->send($apiRequest); |
|
| 132 | - if (200 !== $apiResponse->getStatusCode()) { |
|
| 131 | + $apiResponse = $client->send($apiRequest); |
|
| 132 | + if (200 !== $apiResponse->getStatusCode()) { |
|
| 133 | 133 | $logger->warning(sprintf('[%s] Unsuccessful response from Superdesk Server: %s', $apiResponse->getStatusCode(), $apiResponse->getBody()->getContents())); |
| 134 | 134 | |
| 135 | 135 | continue; |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
| 139 | - if (is_array($content) && array_key_exists('user', $content)) { |
|
| 138 | + $content = json_decode($apiResponse->getBody()->getContents(), true); |
|
| 139 | + if (is_array($content) && array_key_exists('user', $content)) { |
|
| 140 | 140 | $superdeskUser = $content['user']; |
| 141 | 141 | |
| 142 | 142 | break; |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | } catch (GuzzleHttp\Exception\ClientException $e) { |
| 145 | - $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
| 145 | + $logger->warning(sprintf('Error when logging in Superdesk: %s', $e->getMessage())); |
|
| 146 | 146 | |
| 147 | - continue; |
|
| 147 | + continue; |
|
| 148 | + } |
|
| 148 | 149 | } |
| 149 | - } |
|
| 150 | 150 | |
| 151 | - if (null === $superdeskUser) { |
|
| 151 | + if (null === $superdeskUser) { |
|
| 152 | 152 | return new SingleResourceResponse([ |
| 153 | 153 | 'status' => 401, |
| 154 | 154 | 'message' => <<<'MESSAGE' |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
| 157 | 157 | MESSAGE, |
| 158 | 158 | ], new ResponseContext(401)); |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 162 | - if (null === $publisherUser) { |
|
| 161 | + $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 162 | + if (null === $publisherUser) { |
|
| 163 | 163 | try { |
| 164 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 164 | + $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 165 | 165 | } catch (AuthenticationException $e) { |
| 166 | - $publisherUser = null; |
|
| 166 | + $publisherUser = null; |
|
| 167 | + } |
|
| 167 | 168 | } |
| 168 | - } |
|
| 169 | 169 | |
| 170 | - if (null === $publisherUser) { |
|
| 170 | + if (null === $publisherUser) { |
|
| 171 | 171 | /** @var UserInterface $publisherUser */ |
| 172 | 172 | $publisherUser = $userManager->createUser(); |
| 173 | 173 | $publisherUser->setUsername($superdeskUser['username']); |
@@ -177,20 +177,20 @@ discard block |
||
| 177 | 177 | $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
| 178 | 178 | $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
| 179 | 179 | $userManager->updateUser($publisherUser); |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - if (null !== $publisherUser) { |
|
| 182 | + if (null !== $publisherUser) { |
|
| 183 | 183 | return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | return new SingleResourceResponse([ |
| 188 | 188 | 'status' => 401, |
| 189 | 189 | 'message' => 'Unauthorized', |
| 190 | 190 | ], new ResponseContext(401)); |
| 191 | - } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
| 193 | + private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface { |
|
| 194 | 194 | /** @var ApiKeyInterface $apiKey */ |
| 195 | 195 | $apiKey = $this->generateOrGetApiKey($user, $token); |
| 196 | 196 | |
@@ -201,36 +201,36 @@ discard block |
||
| 201 | 201 | ], |
| 202 | 202 | 'user' => $user, |
| 203 | 203 | ]); |
| 204 | - } |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
| 206 | + private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface { |
|
| 207 | 207 | $apiKey = null; |
| 208 | 208 | if (null !== $token) { |
| 209 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 209 | + $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 210 | 210 | } else { |
| 211 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 212 | - if (count($validKeys) > 0) { |
|
| 211 | + $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 212 | + if (count($validKeys) > 0) { |
|
| 213 | 213 | $apiKey = reset($validKeys); |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if (null === $apiKey) { |
| 218 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 218 | + $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 219 | 219 | |
| 220 | - try { |
|
| 220 | + try { |
|
| 221 | 221 | $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
| 222 | 222 | if (!$lock->acquire()) { |
| 223 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 223 | + throw new RuntimeException('Other api key is created right now for this user'); |
|
| 224 | 224 | } |
| 225 | 225 | $this->apiKeyRepository->add($apiKey); |
| 226 | 226 | $lock->release(); |
| 227 | - } catch (RuntimeException $e) { |
|
| 227 | + } catch (RuntimeException $e) { |
|
| 228 | 228 | sleep(2); |
| 229 | 229 | |
| 230 | 230 | return $this->generateOrGetApiKey($user, $token); |
| 231 | - } |
|
| 231 | + } |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return $apiKey; |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | use FOS\RestBundle\Controller\Annotations\Route; |
| 21 | 21 | |
| 22 | 22 | class SeoMetadataController extends AbstractController { |
| 23 | - private FormFactoryInterface $formFactory; |
|
| 24 | - private FactoryInterface $seoMetadataFactory; |
|
| 25 | - private RepositoryInterface $seoMetadataRepository; |
|
| 26 | - private EventDispatcherInterface $eventDispatcher; |
|
| 23 | + private FormFactoryInterface $formFactory; |
|
| 24 | + private FactoryInterface $seoMetadataFactory; |
|
| 25 | + private RepositoryInterface $seoMetadataRepository; |
|
| 26 | + private EventDispatcherInterface $eventDispatcher; |
|
| 27 | 27 | protected MediaManagerInterface $mediaManager; |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,29 +33,29 @@ discard block |
||
| 33 | 33 | * @param EventDispatcherInterface $eventDispatcher |
| 34 | 34 | * @param MediaManagerInterface $mediaManager |
| 35 | 35 | */ |
| 36 | - public function __construct( |
|
| 37 | - FormFactoryInterface $formFactory, |
|
| 38 | - FactoryInterface $seoMetadataFactory, |
|
| 39 | - RepositoryInterface $seoMetadataRepository, |
|
| 40 | - EventDispatcherInterface $eventDispatcher, |
|
| 41 | - MediaManagerInterface $mediaManager |
|
| 42 | - ) { |
|
| 36 | + public function __construct( |
|
| 37 | + FormFactoryInterface $formFactory, |
|
| 38 | + FactoryInterface $seoMetadataFactory, |
|
| 39 | + RepositoryInterface $seoMetadataRepository, |
|
| 40 | + EventDispatcherInterface $eventDispatcher, |
|
| 41 | + MediaManagerInterface $mediaManager |
|
| 42 | + ) { |
|
| 43 | 43 | $this->formFactory = $formFactory; |
| 44 | 44 | $this->seoMetadataFactory = $seoMetadataFactory; |
| 45 | 45 | $this->seoMetadataRepository = $seoMetadataRepository; |
| 46 | 46 | $this->eventDispatcher = $eventDispatcher; |
| 47 | - $this->mediaManager = $mediaManager; |
|
| 48 | - } |
|
| 47 | + $this->mediaManager = $mediaManager; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
| 52 | - */ |
|
| 53 | - public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
| 50 | + /** |
|
| 51 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put") |
|
| 52 | + */ |
|
| 53 | + public function put(Request $request, string $packageGuid): SingleResourceResponse { |
|
| 54 | 54 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
| 55 | 55 | |
| 56 | 56 | $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
| 57 | 57 | if (null === $seoMetadata) { |
| 58 | - $seoMetadata = $this->seoMetadataFactory->create(); |
|
| 58 | + $seoMetadata = $this->seoMetadataFactory->create(); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $form = $this->formFactory->createNamed('', SeoMetadataType::class, $seoMetadata, ['method' => $request->getMethod()]); |
@@ -63,48 +63,48 @@ discard block |
||
| 63 | 63 | $form->handleRequest($request); |
| 64 | 64 | |
| 65 | 65 | if ($form->isSubmitted() && $form->isValid()) { |
| 66 | - $seoMetadata->setPackageGuid($packageGuid); |
|
| 67 | - $this->seoMetadataRepository->add($seoMetadata); |
|
| 66 | + $seoMetadata->setPackageGuid($packageGuid); |
|
| 67 | + $this->seoMetadataRepository->add($seoMetadata); |
|
| 68 | 68 | |
| 69 | - return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
| 69 | + return new SingleResourceResponse($seoMetadata, new ResponseContext(200)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
| 77 | - */ |
|
| 78 | - public function getAction(string $packageGuid): SingleResourceResponse { |
|
| 75 | + /** |
|
| 76 | + * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get") |
|
| 77 | + */ |
|
| 78 | + public function getAction(string $packageGuid): SingleResourceResponse { |
|
| 79 | 79 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
| 80 | 80 | |
| 81 | - $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
|
| 81 | + $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid); |
|
| 82 | 82 | if (null === $seoMetadata) { |
| 83 | - throw new NotFoundHttpException('SEO metadata not found!'); |
|
| 83 | + throw new NotFoundHttpException('SEO metadata not found!'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $response = [ |
|
| 87 | - "meta_title" => $seoMetadata->getMetaTitle(), |
|
| 88 | - "meta_description" => $seoMetadata->getMetaDescription(), |
|
| 89 | - "og_title" => $seoMetadata->getOgTitle(), |
|
| 90 | - "og_description" => $seoMetadata->getOgDescription(), |
|
| 91 | - "twitter_title" => $seoMetadata->getTwitterTitle(), |
|
| 92 | - "twitter_description" => $seoMetadata->getTwitterDescription(), |
|
| 93 | - ]; |
|
| 94 | - |
|
| 95 | - if ($seoMetadata->getMetaMedia()) { |
|
| 96 | - $metaImage = $seoMetadata->getMetaMedia()->getImage(); |
|
| 97 | - $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 98 | - } |
|
| 99 | - if ($seoMetadata->getOgMedia()) { |
|
| 100 | - $metaImage = $seoMetadata->getOgMedia()->getImage(); |
|
| 101 | - $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 102 | - } |
|
| 103 | - if ($seoMetadata->getTwitterMedia()) { |
|
| 104 | - $metaImage = $seoMetadata->getTwitterMedia()->getImage(); |
|
| 105 | - $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 106 | - } |
|
| 86 | + $response = [ |
|
| 87 | + "meta_title" => $seoMetadata->getMetaTitle(), |
|
| 88 | + "meta_description" => $seoMetadata->getMetaDescription(), |
|
| 89 | + "og_title" => $seoMetadata->getOgTitle(), |
|
| 90 | + "og_description" => $seoMetadata->getOgDescription(), |
|
| 91 | + "twitter_title" => $seoMetadata->getTwitterTitle(), |
|
| 92 | + "twitter_description" => $seoMetadata->getTwitterDescription(), |
|
| 93 | + ]; |
|
| 94 | + |
|
| 95 | + if ($seoMetadata->getMetaMedia()) { |
|
| 96 | + $metaImage = $seoMetadata->getMetaMedia()->getImage(); |
|
| 97 | + $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 98 | + } |
|
| 99 | + if ($seoMetadata->getOgMedia()) { |
|
| 100 | + $metaImage = $seoMetadata->getOgMedia()->getImage(); |
|
| 101 | + $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 102 | + } |
|
| 103 | + if ($seoMetadata->getTwitterMedia()) { |
|
| 104 | + $metaImage = $seoMetadata->getTwitterMedia()->getImage(); |
|
| 105 | + $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)]; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | return new SingleResourceResponse($response, new ResponseContext(200)); |
| 109 | - } |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -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 | } |
@@ -36,27 +36,27 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | class ArticleController extends AbstractController { |
| 38 | 38 | |
| 39 | - private FormFactoryInterface $formFactory; |
|
| 40 | - private RouteProviderInterface $routeProvider; // swp.provider.route |
|
| 41 | - private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
| 42 | - private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
| 43 | - private EventDispatcherInterface $eventDispatcher; |
|
| 44 | - private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
| 45 | - private ArticleServiceInterface $articleService; // swp.service.article |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param FormFactoryInterface $formFactory |
|
| 49 | - * @param RouteProviderInterface $routeProvider |
|
| 50 | - * @param ArticleRepositoryInterface $articleRepository |
|
| 51 | - * @param ArticleProviderInterface $articleProvider |
|
| 52 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 53 | - * @param EntityManagerInterface $entityManager |
|
| 54 | - * @param ArticleServiceInterface $articleService |
|
| 55 | - */ |
|
| 56 | - public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
| 57 | - ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
| 58 | - EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
| 59 | - ArticleServiceInterface $articleService) { |
|
| 39 | + private FormFactoryInterface $formFactory; |
|
| 40 | + private RouteProviderInterface $routeProvider; // swp.provider.route |
|
| 41 | + private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
| 42 | + private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
| 43 | + private EventDispatcherInterface $eventDispatcher; |
|
| 44 | + private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
| 45 | + private ArticleServiceInterface $articleService; // swp.service.article |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param FormFactoryInterface $formFactory |
|
| 49 | + * @param RouteProviderInterface $routeProvider |
|
| 50 | + * @param ArticleRepositoryInterface $articleRepository |
|
| 51 | + * @param ArticleProviderInterface $articleProvider |
|
| 52 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 53 | + * @param EntityManagerInterface $entityManager |
|
| 54 | + * @param ArticleServiceInterface $articleService |
|
| 55 | + */ |
|
| 56 | + public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
| 57 | + ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
| 58 | + EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
| 59 | + ArticleServiceInterface $articleService) { |
|
| 60 | 60 | $this->formFactory = $formFactory; |
| 61 | 61 | $this->routeProvider = $routeProvider; |
| 62 | 62 | $this->articleRepository = $articleRepository; |
@@ -64,30 +64,30 @@ discard block |
||
| 64 | 64 | $this->eventDispatcher = $eventDispatcher; |
| 65 | 65 | $this->entityManager = $entityManager; |
| 66 | 66 | $this->articleService = $articleService; |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
| 72 | - * |
|
| 73 | - * @throws \Exception |
|
| 74 | - */ |
|
| 75 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 70 | + /** |
|
| 71 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
| 72 | + * |
|
| 73 | + * @throws \Exception |
|
| 74 | + */ |
|
| 75 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 76 | 76 | $authors = ''; |
| 77 | 77 | if (null !== $request->query->get('author', null)) { |
| 78 | - $authors = explode(', ', $request->query->get('author')); |
|
| 78 | + $authors = explode(', ', $request->query->get('author')); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) { |
| 82 | - $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
| 82 | + $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
| 83 | 83 | |
| 84 | - if (null !== $routeObject) { |
|
| 84 | + if (null !== $routeObject) { |
|
| 85 | 85 | $ids = [$routeObject->getId()]; |
| 86 | 86 | foreach ($routeObject->getChildren() as $child) { |
| 87 | - $ids[] = $child->getId(); |
|
| 87 | + $ids[] = $child->getId(); |
|
| 88 | 88 | } |
| 89 | 89 | $request->query->set('route', $ids); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $articles = $this->articleRepository |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | ]), $request->query->all('sorting'), new PaginationData($request)); |
| 103 | 103 | |
| 104 | 104 | return new ResourcesListResponse($articles); |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
| 109 | - */ |
|
| 110 | - public function getAction($id): SingleResourceResponseInterface { |
|
| 107 | + /** |
|
| 108 | + * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
| 109 | + */ |
|
| 110 | + public function getAction($id): SingleResourceResponseInterface { |
|
| 111 | 111 | $article = $this->articleProvider->getOneById($id); |
| 112 | 112 | |
| 113 | 113 | if (null === $article) { |
| 114 | - throw new NotFoundHttpException('Article was not found'); |
|
| 114 | + throw new NotFoundHttpException('Article was not found'); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | return new SingleResourceResponse($article); |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
| 122 | - */ |
|
| 123 | - public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
| 120 | + /** |
|
| 121 | + * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
| 122 | + */ |
|
| 123 | + public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
| 124 | 124 | // Extract parameters from the request |
| 125 | 125 | $code = $request->query->get('code', ''); |
| 126 | 126 | //$tenantCode = $request->query->get('tenant_code', ''); |
@@ -134,16 +134,16 @@ discard block |
||
| 134 | 134 | ->getOneOrNullResult(); |
| 135 | 135 | |
| 136 | 136 | if (null === $article) { |
| 137 | - throw new NotFoundHttpException('Article was not found'); |
|
| 137 | + throw new NotFoundHttpException('Article was not found'); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return new SingleResourceResponse($article); |
| 141 | - } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
| 145 | - */ |
|
| 146 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
| 143 | + /** |
|
| 144 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
| 145 | + */ |
|
| 146 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
| 147 | 147 | $objectManager = $this->entityManager; |
| 148 | 148 | $article = $this->findOr404($id); |
| 149 | 149 | $originalArticleStatus = $article->getStatus(); |
@@ -152,32 +152,32 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | $form->handleRequest($request); |
| 154 | 154 | if ($form->isSubmitted() && $form->isValid()) { |
| 155 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
| 156 | - $objectManager->flush(); |
|
| 157 | - $objectManager->refresh($article); |
|
| 155 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
| 156 | + $objectManager->flush(); |
|
| 157 | + $objectManager->refresh($article); |
|
| 158 | 158 | |
| 159 | - return new SingleResourceResponse($article); |
|
| 159 | + return new SingleResourceResponse($article); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | return new SingleResourceResponse($form, new ResponseContext(500)); |
| 163 | - } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
| 167 | - */ |
|
| 168 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
| 165 | + /** |
|
| 166 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
| 167 | + */ |
|
| 168 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
| 169 | 169 | $objectManager = $this->entityManager; |
| 170 | 170 | $objectManager->remove($this->findOr404($id)); |
| 171 | 171 | $objectManager->flush(); |
| 172 | 172 | |
| 173 | 173 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 174 | - } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - private function findOr404($id) { |
|
| 176 | + private function findOr404($id) { |
|
| 177 | 177 | if (null === $article = $this->articleProvider->getOneById($id)) { |
| 178 | - throw new NotFoundHttpException('Article was not found.'); |
|
| 178 | + throw new NotFoundHttpException('Article was not found.'); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | return $article; |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | } |
@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | use FOS\RestBundle\Controller\Annotations\Route; |
| 43 | 43 | |
| 44 | 44 | class ContentPushController extends AbstractController { |
| 45 | - private EventDispatcherInterface $eventDispatcher; |
|
| 46 | - private FormFactoryInterface $formFactory; |
|
| 47 | - private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
| 48 | - private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
| 49 | - private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
| 50 | - private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
| 51 | - private PackageRepository $packageRepository;//swp.repository.package |
|
| 52 | - private ArticleRepositoryInterface $articleRepository;//swp.repository.article |
|
| 53 | - private FileProviderInterface $fileProvider; |
|
| 45 | + private EventDispatcherInterface $eventDispatcher; |
|
| 46 | + private FormFactoryInterface $formFactory; |
|
| 47 | + private MessageBusInterface $messageBus;//swp_multi_tenancy.tenant_context |
|
| 48 | + private DataTransformerInterface $dataTransformer; // swp_bridge.transformer.json_to_package |
|
| 49 | + private MediaManagerInterface $mediaManager; // swp_content_bundle.manager.media |
|
| 50 | + private EntityManagerInterface $entityManager; // swp.object_manager.media |
|
| 51 | + private PackageRepository $packageRepository;//swp.repository.package |
|
| 52 | + private ArticleRepositoryInterface $articleRepository;//swp.repository.article |
|
| 53 | + private FileProviderInterface $fileProvider; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @param EventDispatcherInterface $eventDispatcher |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | * @param ArticleRepositoryInterface $articleRepository |
| 64 | 64 | * @param FileProviderInterface $fileProvider |
| 65 | 65 | */ |
| 66 | - public function __construct( |
|
| 67 | - EventDispatcherInterface $eventDispatcher, |
|
| 68 | - FormFactoryInterface $formFactory, |
|
| 69 | - MessageBusInterface $messageBus, |
|
| 70 | - DataTransformerInterface $dataTransformer, |
|
| 71 | - MediaManagerInterface $mediaManager, |
|
| 72 | - EntityManagerInterface $entityManager, |
|
| 73 | - PackageRepository $packageRepository, |
|
| 74 | - ArticleRepositoryInterface $articleRepository, |
|
| 75 | - FileProviderInterface $fileProvider |
|
| 76 | - ) { |
|
| 66 | + public function __construct( |
|
| 67 | + EventDispatcherInterface $eventDispatcher, |
|
| 68 | + FormFactoryInterface $formFactory, |
|
| 69 | + MessageBusInterface $messageBus, |
|
| 70 | + DataTransformerInterface $dataTransformer, |
|
| 71 | + MediaManagerInterface $mediaManager, |
|
| 72 | + EntityManagerInterface $entityManager, |
|
| 73 | + PackageRepository $packageRepository, |
|
| 74 | + ArticleRepositoryInterface $articleRepository, |
|
| 75 | + FileProviderInterface $fileProvider |
|
| 76 | + ) { |
|
| 77 | 77 | $this->eventDispatcher = $eventDispatcher; |
| 78 | 78 | $this->formFactory = $formFactory; |
| 79 | 79 | $this->messageBus = $messageBus; |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | $this->packageRepository = $packageRepository; |
| 84 | 84 | $this->articleRepository = $articleRepository; |
| 85 | 85 | $this->fileProvider = $fileProvider; |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
| 91 | - */ |
|
| 92 | - public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
| 89 | + /** |
|
| 90 | + * @Route("/api/{version}/content/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_push") |
|
| 91 | + */ |
|
| 92 | + public function pushContentAction(Request $request, TenantContextInterface $tenantContext): SingleResourceResponseInterface { |
|
| 93 | 93 | $package = $this->dataTransformer->transform($request->getContent()); |
| 94 | 94 | $this->eventDispatcher->dispatch(new GenericEvent($package), Events::SWP_VALIDATION); |
| 95 | 95 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | ); |
| 101 | 101 | |
| 102 | 102 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -128,25 +128,25 @@ discard block |
||
| 128 | 128 | return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201)); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
| 133 | - */ |
|
| 134 | - public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
| 131 | + /** |
|
| 132 | + * @Route("/api/{version}/assets/push", methods={"POST"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_assets_push") |
|
| 133 | + */ |
|
| 134 | + public function pushAssetsAction(Request $request): SingleResourceResponseInterface { |
|
| 135 | 135 | $form = $this->formFactory->createNamed('', MediaFileType::class); |
| 136 | 136 | $form->handleRequest($request); |
| 137 | 137 | |
| 138 | 138 | if ($form->isSubmitted() && $form->isValid()) { |
| 139 | - $mediaManager = $this->mediaManager; |
|
| 140 | - $uploadedFile = $form->getData()['media']; |
|
| 141 | - $mediaId = $request->request->get('mediaId'); |
|
| 139 | + $mediaManager = $this->mediaManager; |
|
| 140 | + $uploadedFile = $form->getData()['media']; |
|
| 141 | + $mediaId = $request->request->get('mediaId'); |
|
| 142 | 142 | |
| 143 | - if ($uploadedFile->isValid()) { |
|
| 143 | + if ($uploadedFile->isValid()) { |
|
| 144 | 144 | $fileProvider = $this->fileProvider; |
| 145 | 145 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $uploadedFile->guessExtension()); |
| 146 | 146 | |
| 147 | 147 | if (null === $file) { |
| 148 | - $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
| 149 | - $this->entityManager->flush(); |
|
| 148 | + $file = $mediaManager->handleUploadedFile($uploadedFile, $mediaId); |
|
| 149 | + $this->entityManager->flush(); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return new SingleResourceResponse( |
@@ -159,23 +159,23 @@ discard block |
||
| 159 | 159 | ], |
| 160 | 160 | new ResponseContext(201) |
| 161 | 161 | ); |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
| 164 | + throw new \Exception('Uploaded file is not valid:' . $uploadedFile->getErrorMessage()); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | return new SingleResourceResponse($form); |
| 168 | - } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @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") |
|
| 172 | - */ |
|
| 173 | - public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
| 170 | + /** |
|
| 171 | + * @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") |
|
| 172 | + */ |
|
| 173 | + public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface { |
|
| 174 | 174 | $fileProvider = $this->fileProvider; |
| 175 | 175 | $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension); |
| 176 | 176 | |
| 177 | 177 | if (null === $file) { |
| 178 | - throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
| 178 | + throw new NotFoundHttpException('Media don\'t exist in storage'); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $mediaManager = $this->mediaManager; |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | 'mime_type' => MimeTypeHelper::getByExtension($file->getFileExtension()), |
| 188 | 188 | 'filemeta' => [], |
| 189 | 189 | ]); |
| 190 | - } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - protected function getPackageRepository() { |
|
| 192 | + protected function getPackageRepository() { |
|
| 193 | 193 | return $this->packageRepository; |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | } |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class ProfileController extends AbstractController { |
| 36 | 36 | |
| 37 | - private EntityManagerInterface $entityManager; |
|
| 38 | - private AuthorizationCheckerInterface $authorizationChecker; |
|
| 39 | - private UserRepository $userRepository; |
|
| 40 | - private PaginatorInterface $paginator; |
|
| 37 | + private EntityManagerInterface $entityManager; |
|
| 38 | + private AuthorizationCheckerInterface $authorizationChecker; |
|
| 39 | + private UserRepository $userRepository; |
|
| 40 | + private PaginatorInterface $paginator; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @param EntityManagerInterface $entityManager |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | return new ResourcesListResponse($pagination); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
| 81 | - */ |
|
| 82 | - public function getAction($id) { |
|
| 79 | + /** |
|
| 80 | + * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile") |
|
| 81 | + */ |
|
| 82 | + public function getAction($id) { |
|
| 83 | 83 | $requestedUser = $this->userRepository->find($id); |
| 84 | 84 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
| 85 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 85 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $this->checkIfCanAccess($requestedUser); |
| 89 | 89 | |
| 90 | 90 | return new SingleResourceResponse($requestedUser); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
| 95 | - */ |
|
| 96 | - public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
| 93 | + /** |
|
| 94 | + * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile") |
|
| 95 | + */ |
|
| 96 | + public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) { |
|
| 97 | 97 | $requestedUser = $this->userRepository->find($id); |
| 98 | 98 | if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) { |
| 99 | - throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 99 | + throw new NotFoundHttpException('Requested user don\'t exists'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $this->checkIfCanAccess($requestedUser); |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | $form->handleRequest($request); |
| 108 | 108 | |
| 109 | 109 | if ($form->isSubmitted() && $form->isValid()) { |
| 110 | - if (!empty($form->get('plainPassword')->getData())) { |
|
| 110 | + if (!empty($form->get('plainPassword')->getData())) { |
|
| 111 | 111 | $requestedUser->setPassword( |
| 112 | 112 | $passwordEncoder->encodePassword( |
| 113 | 113 | $requestedUser, |
| 114 | 114 | $form->get('plainPassword')->getData() |
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $entityManager = $this->entityManager; |
|
| 120 | - $entityManager->flush(); |
|
| 119 | + $entityManager = $this->entityManager; |
|
| 120 | + $entityManager->flush(); |
|
| 121 | 121 | |
| 122 | - return new SingleResourceResponse($requestedUser); |
|
| 122 | + return new SingleResourceResponse($requestedUser); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - private function checkIfCanAccess($requestedUser) { |
|
| 128 | + private function checkIfCanAccess($requestedUser) { |
|
| 129 | 129 | /** @var UserInterface $currentUser */ |
| 130 | 130 | $currentUser = $this->getUser(); |
| 131 | 131 | if ( |
| 132 | 132 | !$this->authorizationChecker->isGranted('ROLE_ADMIN') && |
| 133 | 133 | $requestedUser->getId() !== $currentUser->getId() |
| 134 | 134 | ) { |
| 135 | - throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
| 135 | + throw new AccessDeniedException('This user does not have access to this section. profile'); |
|
| 136 | + } |
|
| 136 | 137 | } |
| 137 | - } |
|
| 138 | 138 | } |
@@ -98,8 +98,8 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | - * @var ErrorDetailsStamp $errorDetailsStamp |
|
| 102 | - */ |
|
| 101 | + * @var ErrorDetailsStamp $errorDetailsStamp |
|
| 102 | + */ |
|
| 103 | 103 | $errorDetailsStamp = $envelope->last(ErrorDetailsStamp::class); |
| 104 | 104 | |
| 105 | 105 | $rows[] = new FailedEntry( |