| @@ -33,78 +33,78 @@ discard block | ||
| 33 | 33 | |
| 34 | 34 |  class CurrentThemeController extends AbstractController { | 
| 35 | 35 | |
| 36 | - private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 37 | - private FormFactoryInterface $formFactory; | |
| 38 | - private CachedTenantContextInterface $tenantContext; | |
| 39 | - private SettingsManagerInterface $settingsManager; | |
| 40 | - private ThemeLogoUploaderInterface $themeLogoUploader; | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 44 | - * @param FormFactoryInterface $formFactory | |
| 45 | - * @param CachedTenantContextInterface $tenantContext | |
| 46 | - * @param SettingsManagerInterface $settingsManager | |
| 47 | - * @param ThemeLogoUploaderInterface $themeLogoUploader | |
| 48 | - */ | |
| 49 | - public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 50 | - FormFactoryInterface $formFactory, | |
| 51 | - CachedTenantContextInterface $tenantContext, | |
| 52 | - SettingsManagerInterface $settingsManager, | |
| 53 | -                              ThemeLogoUploaderInterface       $themeLogoUploader) { | |
| 36 | + private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 37 | + private FormFactoryInterface $formFactory; | |
| 38 | + private CachedTenantContextInterface $tenantContext; | |
| 39 | + private SettingsManagerInterface $settingsManager; | |
| 40 | + private ThemeLogoUploaderInterface $themeLogoUploader; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 44 | + * @param FormFactoryInterface $formFactory | |
| 45 | + * @param CachedTenantContextInterface $tenantContext | |
| 46 | + * @param SettingsManagerInterface $settingsManager | |
| 47 | + * @param ThemeLogoUploaderInterface $themeLogoUploader | |
| 48 | + */ | |
| 49 | + public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 50 | + FormFactoryInterface $formFactory, | |
| 51 | + CachedTenantContextInterface $tenantContext, | |
| 52 | + SettingsManagerInterface $settingsManager, | |
| 53 | +                                ThemeLogoUploaderInterface       $themeLogoUploader) { | |
| 54 | 54 | $this->tenantAwareThemeContext = $tenantAwareThemeContext; | 
| 55 | 55 | $this->formFactory = $formFactory; | 
| 56 | 56 | $this->tenantContext = $tenantContext; | 
| 57 | 57 | $this->settingsManager = $settingsManager; | 
| 58 | 58 | $this->themeLogoUploader = $themeLogoUploader; | 
| 59 | - } | |
| 59 | + } | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** | |
| 63 | -   * @Route("/api/{version}/theme/logo_upload/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo_2") | |
| 64 | -   * @Route("/api/{version}/theme/logo_upload/{type}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo") | |
| 65 | - */ | |
| 66 | - public function uploadThemeLogoAction(Request $request, | |
| 62 | + /** | |
| 63 | +     * @Route("/api/{version}/theme/logo_upload/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo_2") | |
| 64 | +     * @Route("/api/{version}/theme/logo_upload/{type}", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme_logo") | |
| 65 | + */ | |
| 66 | + public function uploadThemeLogoAction(Request $request, | |
| 67 | 67 |                                          string  $type = ThemeLogoProviderInterface::SETTING_NAME_DEFAULT): SingleResourceResponseInterface { | 
| 68 | 68 | $themeContext = $this->tenantAwareThemeContext; | 
| 69 | 69 | |
| 70 | 70 |      if (null === ($theme = $themeContext->getTheme())) { | 
| 71 | -      throw new \LogicException('Theme is not set!'); | |
| 71 | +        throw new \LogicException('Theme is not set!'); | |
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | 74 |      $form = $this->formFactory->createNamed('', ThemeLogoUploadType::class, $theme); | 
| 75 | 75 | $form->handleRequest($request); | 
| 76 | 76 | |
| 77 | 77 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 78 | - $tenantContext = $this->tenantContext; | |
| 79 | - $currentTenant = $tenantContext->getTenant(); | |
| 78 | + $tenantContext = $this->tenantContext; | |
| 79 | + $currentTenant = $tenantContext->getTenant(); | |
| 80 | 80 | |
| 81 | -      try { | |
| 81 | +        try { | |
| 82 | 82 | $settingsManager = $this->settingsManager; | 
| 83 | 83 | $setting = $settingsManager->get($type, ScopeContextInterface::SCOPE_THEME, $currentTenant); | 
| 84 | 84 | $theme->setLogoPath($setting); | 
| 85 | 85 | $themeLogoUploader = $this->themeLogoUploader; | 
| 86 | 86 | $themeLogoUploader->upload($theme); | 
| 87 | -      } catch (\Exception $e) { | |
| 87 | +        } catch (\Exception $e) { | |
| 88 | 88 | return new SingleResourceResponse(['message' => 'Could not upload logo.'], new ResponseContext(400)); | 
| 89 | - } | |
| 89 | + } | |
| 90 | 90 | |
| 91 | - $settingsManager = $this->settingsManager; | |
| 92 | - $setting = $settingsManager->set($type, $theme->getLogoPath(), ScopeContextInterface::SCOPE_THEME, $currentTenant); | |
| 91 | + $settingsManager = $this->settingsManager; | |
| 92 | + $setting = $settingsManager->set($type, $theme->getLogoPath(), ScopeContextInterface::SCOPE_THEME, $currentTenant); | |
| 93 | 93 | |
| 94 | - return new SingleResourceResponse($setting, new ResponseContext(201)); | |
| 94 | + return new SingleResourceResponse($setting, new ResponseContext(201)); | |
| 95 | 95 | } | 
| 96 | 96 | |
| 97 | 97 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 98 | - } | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - /** | |
| 101 | -   * @Route("/api/{version}/theme/settings/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_theme_settings_list") | |
| 102 | - */ | |
| 103 | -  public function listSettingsAction(): SingleResourceResponseInterface { | |
| 100 | + /** | |
| 101 | +     * @Route("/api/{version}/theme/settings/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_theme_settings_list") | |
| 102 | + */ | |
| 103 | +    public function listSettingsAction(): SingleResourceResponseInterface { | |
| 104 | 104 | $themeContext = $this->tenantAwareThemeContext; | 
| 105 | 105 | |
| 106 | 106 |      if (null === $themeContext->getTheme()) { | 
| 107 | -      throw new \LogicException('Theme is not set!'); | |
| 107 | +        throw new \LogicException('Theme is not set!'); | |
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | $tenantContext = $this->tenantContext; | 
| @@ -112,5 +112,5 @@ discard block | ||
| 112 | 112 | $settings = $settingsManager->getByScopeAndOwner(ScopeContextInterface::SCOPE_THEME, $tenantContext->getTenant()); | 
| 113 | 113 | |
| 114 | 114 | return new SingleResourceResponse($settings); | 
| 115 | - } | |
| 115 | + } | |
| 116 | 116 | } | 
| @@ -27,138 +27,138 @@ | ||
| 27 | 27 | use Symfony\Component\Routing\Annotation\Route; | 
| 28 | 28 | |
| 29 | 29 |  class StaticThemeAssetsController extends Controller { | 
| 30 | - /** | |
| 31 | - * Directory with assets inside theme. | |
| 32 | - */ | |
| 33 | - const ASSETS_DIRECTORY = 'public'; | |
| 34 | - | |
| 35 | - private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 36 | - private ThemeLoaderInterface $themeLoader; | |
| 37 | - private ThemeRepositoryInterface $themeRepository; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 41 | - * @param ThemeLoaderInterface $themeLoader | |
| 42 | - * @param ThemeRepositoryInterface $themeRepository | |
| 43 | - */ | |
| 44 | - public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 45 | - ThemeLoaderInterface $themeLoader, | |
| 46 | -                              ThemeRepositoryInterface         $themeRepository) { | |
| 30 | + /** | |
| 31 | + * Directory with assets inside theme. | |
| 32 | + */ | |
| 33 | + const ASSETS_DIRECTORY = 'public'; | |
| 34 | + | |
| 35 | + private TenantAwareThemeContextInterface $tenantAwareThemeContext; | |
| 36 | + private ThemeLoaderInterface $themeLoader; | |
| 37 | + private ThemeRepositoryInterface $themeRepository; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @param TenantAwareThemeContextInterface $tenantAwareThemeContext | |
| 41 | + * @param ThemeLoaderInterface $themeLoader | |
| 42 | + * @param ThemeRepositoryInterface $themeRepository | |
| 43 | + */ | |
| 44 | + public function __construct(TenantAwareThemeContextInterface $tenantAwareThemeContext, | |
| 45 | + ThemeLoaderInterface $themeLoader, | |
| 46 | +                                ThemeRepositoryInterface         $themeRepository) { | |
| 47 | 47 | $this->tenantAwareThemeContext = $tenantAwareThemeContext; | 
| 48 | 48 | $this->themeLoader = $themeLoader; | 
| 49 | 49 | $this->themeRepository = $themeRepository; | 
| 50 | - } | |
| 50 | + } | |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** | |
| 54 | -   * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) | |
| 55 | -   * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) | |
| 56 | -   * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) | |
| 57 | - */ | |
| 58 | -  public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { | |
| 53 | + /** | |
| 54 | +     * @Route("/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root", requirements={"fileName": "sw|manifest|favicon|ads|OneSignalSDKWorker|OneSignalSDKUpdaterWorker|amp-web-push-helper-frame|amp-web-push-permission-dialog"}) | |
| 55 | +     * @Route("/public-{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_root_public", requirements={"fileName"=".+"}) | |
| 56 | +     * @Route("/public/{fileName}.{fileExtension}", methods={"GET"}, name="static_theme_assets_public", requirements={"fileName"=".+"}) | |
| 57 | + */ | |
| 58 | +    public function rootAction($fileName, $fileExtension, ThemeHierarchyProviderInterface $themeHierarchyProvider) { | |
| 59 | 59 | $themes = $themeHierarchyProvider->getThemeHierarchy( | 
| 60 | 60 | $this->tenantAwareThemeContext->getTheme() | 
| 61 | 61 | ); | 
| 62 | 62 | |
| 63 | 63 | $fileName = (null === $fileExtension) ? basename($fileName) : $fileName . '.' . $fileExtension; | 
| 64 | 64 |      foreach ($themes as $theme) { | 
| 65 | - $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; | |
| 66 | -      if (null !== $response = $this->handleFileLoading($filePath)) { | |
| 65 | + $filePath = $theme->getPath() . '/' . self::ASSETS_DIRECTORY . '/' . $fileName; | |
| 66 | +        if (null !== $response = $this->handleFileLoading($filePath)) { | |
| 67 | 67 | return $response; | 
| 68 | - } | |
| 68 | + } | |
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | 71 |      throw new NotFoundHttpException('File was not found.'); | 
| 72 | - } | |
| 73 | - | |
| 74 | - /** | |
| 75 | -   * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ | |
| 76 | - * "type": "organization|tenant" | |
| 77 | - * }) | |
| 78 | - */ | |
| 79 | -  public function screenshotsAction(string $type, string $themeName, $fileName) { | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | +     * @Route("/themes/{type}/{themeName}/screenshots/{fileName}", methods={"GET"}, name="static_theme_screenshots", requirements={ | |
| 76 | + * "type": "organization|tenant" | |
| 77 | + * }) | |
| 78 | + */ | |
| 79 | +    public function screenshotsAction(string $type, string $themeName, $fileName) { | |
| 80 | 80 |      if ('organization' === $type) { | 
| 81 | -      $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); | |
| 81 | +        $theme = $this->loadOrganizationTheme(str_replace('__', '/', $themeName)); | |
| 82 | 82 |      } elseif ('tenant' === $type) { | 
| 83 | -      $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); | |
| 83 | +        $theme = $this->loadTenantTheme(str_replace('__', '/', $themeName)); | |
| 84 | 84 |      } else { | 
| 85 | -      throw new NotFoundHttpException('File was not found.'); | |
| 85 | +        throw new NotFoundHttpException('File was not found.'); | |
| 86 | 86 | } | 
| 87 | 87 | |
| 88 | 88 | $filePath = $theme->getPath() . '/screenshots/' . $fileName; | 
| 89 | 89 |      if (null !== $response = $this->handleFileLoading($filePath)) { | 
| 90 | - return $response; | |
| 90 | + return $response; | |
| 91 | 91 | } | 
| 92 | 92 | |
| 93 | 93 |      throw new NotFoundHttpException('File was not found.'); | 
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * @param $filePath | |
| 98 | - * | |
| 99 | - * @return Response | |
| 100 | - */ | |
| 101 | -  private function handleFileLoading($filePath) { | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @param $filePath | |
| 98 | + * | |
| 99 | + * @return Response | |
| 100 | + */ | |
| 101 | +    private function handleFileLoading($filePath) { | |
| 102 | 102 |      if (file_exists($filePath)) { | 
| 103 | - $response = new Response(file_get_contents($filePath)); | |
| 104 | - $disposition = $response->headers->makeDisposition( | |
| 105 | - ResponseHeaderBag::DISPOSITION_INLINE, | |
| 106 | - basename($filePath) | |
| 107 | - ); | |
| 108 | -      $response->headers->set('Content-Disposition', $disposition); | |
| 109 | - | |
| 110 | -      try { | |
| 103 | + $response = new Response(file_get_contents($filePath)); | |
| 104 | + $disposition = $response->headers->makeDisposition( | |
| 105 | + ResponseHeaderBag::DISPOSITION_INLINE, | |
| 106 | + basename($filePath) | |
| 107 | + ); | |
| 108 | +        $response->headers->set('Content-Disposition', $disposition); | |
| 109 | + | |
| 110 | +        try { | |
| 111 | 111 | $type = new Mime(new Read($filePath)); | 
| 112 | 112 |          $mime = str_replace('/x-', '/', Mime::getMimeFromExtension($type->getExtension())); | 
| 113 | -      } catch (\Exception $e) { | |
| 113 | +        } catch (\Exception $e) { | |
| 114 | 114 | $mime = 'text/plain'; | 
| 115 | - } | |
| 115 | + } | |
| 116 | 116 | |
| 117 | -      $response->headers->set('Content-Type', $mime); | |
| 118 | - $response->setStatusCode(Response::HTTP_OK); | |
| 119 | - $response->setPublic(); | |
| 120 | - $response->setMaxAge(3600); | |
| 121 | - $response->setSharedMaxAge(7200); | |
| 117 | +        $response->headers->set('Content-Type', $mime); | |
| 118 | + $response->setStatusCode(Response::HTTP_OK); | |
| 119 | + $response->setPublic(); | |
| 120 | + $response->setMaxAge(3600); | |
| 121 | + $response->setSharedMaxAge(7200); | |
| 122 | 122 | |
| 123 | - return $response; | |
| 123 | + return $response; | |
| 124 | + } | |
| 124 | 125 | } | 
| 125 | - } | |
| 126 | 126 | |
| 127 | - /** | |
| 128 | - * @return mixed | |
| 129 | - */ | |
| 130 | -  private function loadOrganizationTheme(string $themeName) { | |
| 127 | + /** | |
| 128 | + * @return mixed | |
| 129 | + */ | |
| 130 | +    private function loadOrganizationTheme(string $themeName) { | |
| 131 | 131 | $loadedThemes = $this->themeLoader->load(); | 
| 132 | 132 | |
| 133 | 133 | return $this->filterThemes($loadedThemes, $themeName); | 
| 134 | - } | |
| 134 | + } | |
| 135 | 135 | |
| 136 | - /** | |
| 137 | - * @return mixed | |
| 138 | - */ | |
| 139 | -  private function loadTenantTheme(string $themeName) { | |
| 136 | + /** | |
| 137 | + * @return mixed | |
| 138 | + */ | |
| 139 | +    private function loadTenantTheme(string $themeName) { | |
| 140 | 140 | $loadedThemes = $this->themeRepository->findAll(); | 
| 141 | 141 | |
| 142 | 142 | return $this->filterThemes($loadedThemes, $themeName); | 
| 143 | - } | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * @param array $loadedThemes | |
| 147 | - * | |
| 148 | - * @return mixed | |
| 149 | - */ | |
| 150 | -  private function filterThemes($loadedThemes, string $themeName) { | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * @param array $loadedThemes | |
| 147 | + * | |
| 148 | + * @return mixed | |
| 149 | + */ | |
| 150 | +    private function filterThemes($loadedThemes, string $themeName) { | |
| 151 | 151 | $themes = array_filter( | 
| 152 | 152 | $loadedThemes, | 
| 153 | 153 |          function ($element) use (&$themeName) { | 
| 154 | - return $element->getName() === $themeName; | |
| 154 | + return $element->getName() === $themeName; | |
| 155 | 155 | } | 
| 156 | 156 | ); | 
| 157 | 157 | |
| 158 | 158 |      if (0 === count($themes)) { | 
| 159 | -      throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); | |
| 159 | +        throw new NotFoundHttpException(sprintf('Theme with name "%s" was not found in organization themes.', $themeName)); | |
| 160 | 160 | } | 
| 161 | 161 | |
| 162 | 162 | return reset($themes); | 
| 163 | - } | |
| 163 | + } | |
| 164 | 164 | } | 
| @@ -42,30 +42,30 @@ discard block | ||
| 42 | 42 | |
| 43 | 43 |  class TenantController extends FOSRestController { | 
| 44 | 44 | |
| 45 | - private CachedTenantContextInterface $cachedTenantContext; | |
| 46 | - private EventDispatcherInterface $eventDispatcher; | |
| 47 | - private FormFactoryInterface $formFactory; | |
| 48 | - private TenantRepositoryInterface $tenantRepository; | |
| 49 | - private EntityManagerInterface $entityManager; | |
| 50 | - private SettingsManagerInterface $settingsManager; | |
| 51 | - private TenantFactoryInterface $tenantFactory; | |
| 52 | - private ArticleRepositoryInterface $articleRepository; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @param CachedTenantContextInterface $cachedTenantContext | |
| 56 | - * @param EventDispatcherInterface $eventDispatcher | |
| 57 | - * @param FormFactoryInterface $formFactory | |
| 58 | - * @param TenantRepositoryInterface $tenantRepository | |
| 59 | - * @param EntityManagerInterface $entityManager | |
| 60 | - * @param SettingsManagerInterface $settingsManager | |
| 61 | - * @param TenantFactoryInterface $tenantFactory | |
| 62 | - * @param ArticleRepositoryInterface $articleRepository | |
| 63 | - */ | |
| 64 | - public function __construct(CachedTenantContextInterface $cachedTenantContext, | |
| 65 | - EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, | |
| 66 | - TenantRepositoryInterface $tenantRepository, EntityManagerInterface $entityManager, | |
| 67 | - SettingsManagerInterface $settingsManager, TenantFactoryInterface $tenantFactory, | |
| 68 | -                              ArticleRepositoryInterface   $articleRepository) { | |
| 45 | + private CachedTenantContextInterface $cachedTenantContext; | |
| 46 | + private EventDispatcherInterface $eventDispatcher; | |
| 47 | + private FormFactoryInterface $formFactory; | |
| 48 | + private TenantRepositoryInterface $tenantRepository; | |
| 49 | + private EntityManagerInterface $entityManager; | |
| 50 | + private SettingsManagerInterface $settingsManager; | |
| 51 | + private TenantFactoryInterface $tenantFactory; | |
| 52 | + private ArticleRepositoryInterface $articleRepository; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @param CachedTenantContextInterface $cachedTenantContext | |
| 56 | + * @param EventDispatcherInterface $eventDispatcher | |
| 57 | + * @param FormFactoryInterface $formFactory | |
| 58 | + * @param TenantRepositoryInterface $tenantRepository | |
| 59 | + * @param EntityManagerInterface $entityManager | |
| 60 | + * @param SettingsManagerInterface $settingsManager | |
| 61 | + * @param TenantFactoryInterface $tenantFactory | |
| 62 | + * @param ArticleRepositoryInterface $articleRepository | |
| 63 | + */ | |
| 64 | + public function __construct(CachedTenantContextInterface $cachedTenantContext, | |
| 65 | + EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, | |
| 66 | + TenantRepositoryInterface $tenantRepository, EntityManagerInterface $entityManager, | |
| 67 | + SettingsManagerInterface $settingsManager, TenantFactoryInterface $tenantFactory, | |
| 68 | +                                ArticleRepositoryInterface   $articleRepository) { | |
| 69 | 69 | $this->cachedTenantContext = $cachedTenantContext; | 
| 70 | 70 | $this->eventDispatcher = $eventDispatcher; | 
| 71 | 71 | $this->formFactory = $formFactory; | 
| @@ -74,32 +74,32 @@ discard block | ||
| 74 | 74 | $this->settingsManager = $settingsManager; | 
| 75 | 75 | $this->tenantFactory = $tenantFactory; | 
| 76 | 76 | $this->articleRepository = $articleRepository; | 
| 77 | - } | |
| 77 | + } | |
| 78 | 78 | |
| 79 | 79 | |
| 80 | - /** | |
| 81 | -   * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_tenants") | |
| 82 | - */ | |
| 83 | -  public function listAction(Request $request) { | |
| 80 | + /** | |
| 81 | +     * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_tenants") | |
| 82 | + */ | |
| 83 | +    public function listAction(Request $request) { | |
| 84 | 84 | $tenants = $this->getTenantRepository() | 
| 85 | 85 |          ->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); | 
| 86 | 86 | $responseContext = new ResponseContext(); | 
| 87 | 87 | $responseContext->setSerializationGroups(['Default', 'api', 'details_api']); | 
| 88 | 88 | |
| 89 | 89 | return new ResourcesListResponse($tenants, $responseContext); | 
| 90 | - } | |
| 90 | + } | |
| 91 | 91 | |
| 92 | - /** | |
| 93 | -   * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 94 | - */ | |
| 95 | -  public function getAction($code) { | |
| 92 | + /** | |
| 93 | +     * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 94 | + */ | |
| 95 | +    public function getAction($code) { | |
| 96 | 96 | return new SingleResourceResponse($this->findOr404($code)); | 
| 97 | - } | |
| 97 | + } | |
| 98 | 98 | |
| 99 | - /** | |
| 100 | -   * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 101 | - */ | |
| 102 | -  public function deleteAction(Request $request, $code) { | |
| 99 | + /** | |
| 100 | +     * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 101 | + */ | |
| 102 | +    public function deleteAction(Request $request, $code) { | |
| 103 | 103 | $tenantContext = $this->cachedTenantContext; | 
| 104 | 104 | $eventDispatcher = $this->eventDispatcher; | 
| 105 | 105 | $currentTenant = $tenantContext->getTenant(); | 
| @@ -109,13 +109,13 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 |      $forceRemove = $request->query->has('force'); | 
| 111 | 111 |      if (!$forceRemove) { | 
| 112 | - $tenantContext->setTenant($tenant); | |
| 113 | - $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); | |
| 114 | - $articlesRepository = $this->articleRepository; | |
| 115 | - $existingArticles = $articlesRepository->findAll(); | |
| 116 | -      if (0 !== \count($existingArticles)) { | |
| 112 | + $tenantContext->setTenant($tenant); | |
| 113 | + $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); | |
| 114 | + $articlesRepository = $this->articleRepository; | |
| 115 | + $existingArticles = $articlesRepository->findAll(); | |
| 116 | +        if (0 !== \count($existingArticles)) { | |
| 117 | 117 |          throw new ConflictHttpException('This tenant have articles attached to it.'); | 
| 118 | - } | |
| 118 | + } | |
| 119 | 119 | } | 
| 120 | 120 | |
| 121 | 121 | $repository->remove($tenant); | 
| @@ -124,12 +124,12 @@ discard block | ||
| 124 | 124 | $eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); | 
| 125 | 125 | |
| 126 | 126 | return new SingleResourceResponse(null, new ResponseContext(204)); | 
| 127 | - } | |
| 127 | + } | |
| 128 | 128 | |
| 129 | - /** | |
| 130 | -   * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_tenant") | |
| 131 | - */ | |
| 132 | -  public function createAction(Request $request) { | |
| 129 | + /** | |
| 130 | +     * @Route("/api/{version}/tenants/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_tenant") | |
| 131 | + */ | |
| 132 | +    public function createAction(Request $request) { | |
| 133 | 133 | $tenant = $this->tenantFactory->create(); | 
| 134 | 134 | $tenantContext = $this->cachedTenantContext; | 
| 135 | 135 | $tenantObjectManager = $this->entityManager; | 
| @@ -137,83 +137,83 @@ discard block | ||
| 137 | 137 | $form->handleRequest($request); | 
| 138 | 138 | |
| 139 | 139 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 140 | - $this->ensureTenantDontExists($tenant->getDomainName(), $tenant->getSubdomain()); | |
| 141 | -      if (null === $tenant->getOrganization()) { | |
| 140 | + $this->ensureTenantDontExists($tenant->getDomainName(), $tenant->getSubdomain()); | |
| 141 | +        if (null === $tenant->getOrganization()) { | |
| 142 | 142 | $organization = $tenantObjectManager->merge($tenantContext->getTenant()->getOrganization()); | 
| 143 | 143 | $tenant->setOrganization($organization); | 
| 144 | - } | |
| 145 | - $this->getTenantRepository()->add($tenant); | |
| 144 | + } | |
| 145 | + $this->getTenantRepository()->add($tenant); | |
| 146 | 146 | |
| 147 | - return new SingleResourceResponse($tenant, new ResponseContext(201)); | |
| 147 | + return new SingleResourceResponse($tenant, new ResponseContext(201)); | |
| 148 | 148 | } | 
| 149 | 149 | |
| 150 | 150 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 151 | - } | |
| 151 | + } | |
| 152 | 152 | |
| 153 | - /** | |
| 154 | -   * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 155 | - */ | |
| 156 | -  public function updateAction(Request $request, $code) { | |
| 153 | + /** | |
| 154 | +     * @Route("/api/{version}/tenants/{code}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_tenant", requirements={"code"="[a-z0-9]+"}) | |
| 155 | + */ | |
| 156 | +    public function updateAction(Request $request, $code) { | |
| 157 | 157 | $tenant = $this->findOr404($code); | 
| 158 | 158 |      $form = $this->formFactory->createNamed('', TenantType::class, $tenant, ['method' => $request->getMethod()]); | 
| 159 | 159 | $form->handleRequest($request); | 
| 160 | 160 | |
| 161 | 161 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 162 | - $formData = $request->request->all(); | |
| 163 | -      $tenant->setUpdatedAt(new DateTime('now')); | |
| 164 | - $this->entityManager->flush(); | |
| 162 | + $formData = $request->request->all(); | |
| 163 | +        $tenant->setUpdatedAt(new DateTime('now')); | |
| 164 | + $this->entityManager->flush(); | |
| 165 | 165 | |
| 166 | - $tenantContext = $this->cachedTenantContext; | |
| 167 | - $tenantContext->setTenant($tenant); | |
| 166 | + $tenantContext = $this->cachedTenantContext; | |
| 167 | + $tenantContext->setTenant($tenant); | |
| 168 | 168 | |
| 169 | - $settingsManager = $this->settingsManager; | |
| 169 | + $settingsManager = $this->settingsManager; | |
| 170 | 170 | |
| 171 | -      if (array_key_exists('fbiaEnabled', $formData)) { | |
| 171 | +        if (array_key_exists('fbiaEnabled', $formData)) { | |
| 172 | 172 |          $settingsManager->set('fbia_enabled', (bool)$formData['fbiaEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); | 
| 173 | - } | |
| 174 | -      if (array_key_exists('paywallEnabled', $formData)) { | |
| 173 | + } | |
| 174 | +        if (array_key_exists('paywallEnabled', $formData)) { | |
| 175 | 175 |          $settingsManager->set('paywall_enabled', (bool)$formData['paywallEnabled'], ScopeContextInterface::SCOPE_TENANT, $tenant); | 
| 176 | - } | |
| 177 | -      if (array_key_exists('defaultLanguage', $formData)) { | |
| 176 | + } | |
| 177 | +        if (array_key_exists('defaultLanguage', $formData)) { | |
| 178 | 178 |          $settingsManager->set('default_language', $formData['defaultLanguage'], ScopeContextInterface::SCOPE_TENANT, $tenant); | 
| 179 | - } | |
| 179 | + } | |
| 180 | 180 | |
| 181 | - return new SingleResourceResponse($tenant); | |
| 181 | + return new SingleResourceResponse($tenant); | |
| 182 | 182 | } | 
| 183 | 183 | |
| 184 | 184 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * @param string $code | |
| 189 | - * | |
| 190 | - * @return mixed|TenantInterface|null | |
| 191 | - * @throws NotFoundHttpException | |
| 192 | - * | |
| 193 | - */ | |
| 194 | -  private function findOr404($code) { | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * @param string $code | |
| 189 | + * | |
| 190 | + * @return mixed|TenantInterface|null | |
| 191 | + * @throws NotFoundHttpException | |
| 192 | + * | |
| 193 | + */ | |
| 194 | +    private function findOr404($code) { | |
| 195 | 195 |      if (null === $tenant = $this->getTenantRepository()->findOneByCode($code)) { | 
| 196 | -      throw $this->createNotFoundException(sprintf('Tenant with code "%s" was not found.', $code)); | |
| 196 | +        throw $this->createNotFoundException(sprintf('Tenant with code "%s" was not found.', $code)); | |
| 197 | 197 | } | 
| 198 | 198 | |
| 199 | 199 | return $tenant; | 
| 200 | - } | |
| 200 | + } | |
| 201 | 201 | |
| 202 | - /** | |
| 203 | - * @return mixed|TenantInterface|null | |
| 204 | - */ | |
| 205 | -  private function ensureTenantDontExists(string $domain, string $subdomain = null) { | |
| 202 | + /** | |
| 203 | + * @return mixed|TenantInterface|null | |
| 204 | + */ | |
| 205 | +    private function ensureTenantDontExists(string $domain, string $subdomain = null) { | |
| 206 | 206 |      if (null !== $tenant = $this->getTenantRepository()->findOneBySubdomainAndDomain($subdomain, $domain)) { | 
| 207 | -      throw new ConflictHttpException('Tenant for this host already exists.'); | |
| 207 | +        throw new ConflictHttpException('Tenant for this host already exists.'); | |
| 208 | 208 | } | 
| 209 | 209 | |
| 210 | 210 | return $tenant; | 
| 211 | - } | |
| 211 | + } | |
| 212 | 212 | |
| 213 | - /** | |
| 214 | - * @return object|\SWP\Bundle\MultiTenancyBundle\Doctrine\ORM\TenantRepository | |
| 215 | - */ | |
| 216 | -  private function getTenantRepository() { | |
| 213 | + /** | |
| 214 | + * @return object|\SWP\Bundle\MultiTenancyBundle\Doctrine\ORM\TenantRepository | |
| 215 | + */ | |
| 216 | +    private function getTenantRepository() { | |
| 217 | 217 | return $this->tenantRepository; | 
| 218 | - } | |
| 218 | + } | |
| 219 | 219 | } | 
| @@ -35,39 +35,39 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |  class PublishDestinationController extends Controller { | 
| 37 | 37 | |
| 38 | - private FormFactoryInterface $formFactory; | |
| 39 | - private EventDispatcherInterface $eventDispatcher; | |
| 40 | - private CachedTenantContextInterface $cachedTenantContext; | |
| 41 | - private RepositoryInterface $publishDestinationRepository; | |
| 42 | - private EntityManagerInterface $entityManager; | |
| 43 | - private FactoryInterface $publishDestinationFactory; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * @param FormFactoryInterface $formFactory | |
| 47 | - * @param EventDispatcherInterface $eventDispatcher | |
| 48 | - * @param CachedTenantContextInterface $cachedTenantContext | |
| 49 | - * @param RepositoryInterface $publishDestinationRepository | |
| 50 | - * @param EntityManagerInterface $entityManager | |
| 51 | - * @param FactoryInterface $publishDestinationFactory | |
| 52 | - */ | |
| 53 | - public function __construct(FormFactoryInterface $formFactory, | |
| 54 | - EventDispatcherInterface $eventDispatcher, | |
| 55 | - CachedTenantContextInterface $cachedTenantContext, | |
| 56 | - RepositoryInterface $publishDestinationRepository, | |
| 57 | - EntityManagerInterface $entityManager, | |
| 58 | -                              FactoryInterface             $publishDestinationFactory) { | |
| 38 | + private FormFactoryInterface $formFactory; | |
| 39 | + private EventDispatcherInterface $eventDispatcher; | |
| 40 | + private CachedTenantContextInterface $cachedTenantContext; | |
| 41 | + private RepositoryInterface $publishDestinationRepository; | |
| 42 | + private EntityManagerInterface $entityManager; | |
| 43 | + private FactoryInterface $publishDestinationFactory; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @param FormFactoryInterface $formFactory | |
| 47 | + * @param EventDispatcherInterface $eventDispatcher | |
| 48 | + * @param CachedTenantContextInterface $cachedTenantContext | |
| 49 | + * @param RepositoryInterface $publishDestinationRepository | |
| 50 | + * @param EntityManagerInterface $entityManager | |
| 51 | + * @param FactoryInterface $publishDestinationFactory | |
| 52 | + */ | |
| 53 | + public function __construct(FormFactoryInterface $formFactory, | |
| 54 | + EventDispatcherInterface $eventDispatcher, | |
| 55 | + CachedTenantContextInterface $cachedTenantContext, | |
| 56 | + RepositoryInterface $publishDestinationRepository, | |
| 57 | + EntityManagerInterface $entityManager, | |
| 58 | +                                FactoryInterface             $publishDestinationFactory) { | |
| 59 | 59 | $this->formFactory = $formFactory; | 
| 60 | 60 | $this->eventDispatcher = $eventDispatcher; | 
| 61 | 61 | $this->cachedTenantContext = $cachedTenantContext; | 
| 62 | 62 | $this->publishDestinationRepository = $publishDestinationRepository; | 
| 63 | 63 | $this->entityManager = $entityManager; | 
| 64 | 64 | $this->publishDestinationFactory = $publishDestinationFactory; | 
| 65 | - } | |
| 65 | + } | |
| 66 | 66 | |
| 67 | - /** | |
| 68 | -   * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") | |
| 69 | - */ | |
| 70 | -  public function createAction(Request $request): SingleResourceResponse { | |
| 67 | + /** | |
| 68 | +     * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") | |
| 69 | + */ | |
| 70 | +    public function createAction(Request $request): SingleResourceResponse { | |
| 71 | 71 | $tenantContext = $this->cachedTenantContext; | 
| 72 | 72 | |
| 73 | 73 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| @@ -78,28 +78,28 @@ discard block | ||
| 78 | 78 | $form->handleRequest($request); | 
| 79 | 79 | |
| 80 | 80 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 81 | - $repository = $this->publishDestinationRepository; | |
| 82 | - /** @var PublishDestinationInterface $publishDestination */ | |
| 83 | - $publishDestination = $repository->findOneByTenant($destination->getTenant()); | |
| 84 | -      if (null !== $publishDestination) { | |
| 81 | + $repository = $this->publishDestinationRepository; | |
| 82 | + /** @var PublishDestinationInterface $publishDestination */ | |
| 83 | + $publishDestination = $repository->findOneByTenant($destination->getTenant()); | |
| 84 | +        if (null !== $publishDestination) { | |
| 85 | 85 | $repository->remove($publishDestination); | 
| 86 | - } | |
| 86 | + } | |
| 87 | 87 | |
| 88 | - $currentOrganization->addPublishDestination($destination); | |
| 89 | - $this->entityManager->flush(); | |
| 88 | + $currentOrganization->addPublishDestination($destination); | |
| 89 | + $this->entityManager->flush(); | |
| 90 | 90 | |
| 91 | - return new SingleResourceResponse($destination, new ResponseContext(200)); | |
| 91 | + return new SingleResourceResponse($destination, new ResponseContext(200)); | |
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | -   * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) | |
| 99 | -   * @ParamConverter("publishDestination", class="SWP\Bundle\CoreBundle\Model\PublishDestination") | |
| 100 | - */ | |
| 101 | - public function updateAction(Request $request, | |
| 102 | -                               PublishDestinationInterface $publishDestination): SingleResourceResponse { | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | +     * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) | |
| 99 | +     * @ParamConverter("publishDestination", class="SWP\Bundle\CoreBundle\Model\PublishDestination") | |
| 100 | + */ | |
| 101 | + public function updateAction(Request $request, | |
| 102 | +                                PublishDestinationInterface $publishDestination): SingleResourceResponse { | |
| 103 | 103 | $objectManager = $this->entityManager; | 
| 104 | 104 | |
| 105 | 105 |      $form = $this->formFactory->createNamed('', PublishDestinationType::class, $publishDestination, [ | 
| @@ -108,12 +108,12 @@ discard block | ||
| 108 | 108 | |
| 109 | 109 | $form->handleRequest($request); | 
| 110 | 110 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 111 | - $objectManager->flush(); | |
| 112 | - $objectManager->refresh($publishDestination); | |
| 111 | + $objectManager->flush(); | |
| 112 | + $objectManager->refresh($publishDestination); | |
| 113 | 113 | |
| 114 | - return new SingleResourceResponse($publishDestination); | |
| 114 | + return new SingleResourceResponse($publishDestination); | |
| 115 | 115 | } | 
| 116 | 116 | |
| 117 | 117 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 118 | - } | |
| 118 | + } | |
| 119 | 119 | } | 
| @@ -35,39 +35,39 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |  class FbPageController extends AbstractController { | 
| 37 | 37 | |
| 38 | - private FormFactoryInterface $formFactory; | |
| 39 | - private RepositoryInterface $facebookInstantArticlesFeedRepository; | |
| 40 | - private RepositoryInterface $facebookPageRepository; | |
| 41 | - private FactoryInterface $facebookPageFactory; | |
| 42 | - private EventDispatcherInterface $eventDispatcher; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @param FormFactoryInterface $formFactory | |
| 46 | - * @param RepositoryInterface $facebookInstantArticlesFeedRepository | |
| 47 | - * @param RepositoryInterface $facebookPageRepository | |
| 48 | - * @param FactoryInterface $facebookPageFactory | |
| 49 | - * @param EventDispatcherInterface $eventDispatcher | |
| 50 | - */ | |
| 51 | - public function __construct(FormFactoryInterface $formFactory, | |
| 52 | - RepositoryInterface $facebookInstantArticlesFeedRepository, | |
| 53 | - RepositoryInterface $facebookPageRepository, FactoryInterface $facebookPageFactory, | |
| 54 | -                              EventDispatcherInterface      $eventDispatcher) { | |
| 38 | + private FormFactoryInterface $formFactory; | |
| 39 | + private RepositoryInterface $facebookInstantArticlesFeedRepository; | |
| 40 | + private RepositoryInterface $facebookPageRepository; | |
| 41 | + private FactoryInterface $facebookPageFactory; | |
| 42 | + private EventDispatcherInterface $eventDispatcher; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @param FormFactoryInterface $formFactory | |
| 46 | + * @param RepositoryInterface $facebookInstantArticlesFeedRepository | |
| 47 | + * @param RepositoryInterface $facebookPageRepository | |
| 48 | + * @param FactoryInterface $facebookPageFactory | |
| 49 | + * @param EventDispatcherInterface $eventDispatcher | |
| 50 | + */ | |
| 51 | + public function __construct(FormFactoryInterface $formFactory, | |
| 52 | + RepositoryInterface $facebookInstantArticlesFeedRepository, | |
| 53 | + RepositoryInterface $facebookPageRepository, FactoryInterface $facebookPageFactory, | |
| 54 | +                                EventDispatcherInterface      $eventDispatcher) { | |
| 55 | 55 | $this->formFactory = $formFactory; | 
| 56 | 56 | $this->facebookInstantArticlesFeedRepository = $facebookInstantArticlesFeedRepository; | 
| 57 | 57 | $this->facebookPageRepository = $facebookPageRepository; | 
| 58 | 58 | $this->facebookPageFactory = $facebookPageFactory; | 
| 59 | 59 | $this->eventDispatcher = $eventDispatcher; | 
| 60 | - } | |
| 60 | + } | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** | |
| 64 | -   * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_pages") | |
| 65 | - */ | |
| 66 | -  public function listAction(Request $request) { | |
| 63 | + /** | |
| 64 | +     * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_facebook_pages") | |
| 65 | + */ | |
| 66 | +    public function listAction(Request $request) { | |
| 67 | 67 | $repository = $this->facebookPageRepository; | 
| 68 | 68 |      $sort = $request->query->all('sorting'); | 
| 69 | 69 |      if (empty($sort)) { | 
| 70 | - $sort = ['id' => 'asc']; | |
| 70 | + $sort = ['id' => 'asc']; | |
| 71 | 71 | } | 
| 72 | 72 | $items = $repository->getPaginatedByCriteria( | 
| 73 | 73 | $this->eventDispatcher, | 
| @@ -77,51 +77,51 @@ discard block | ||
| 77 | 77 | ); | 
| 78 | 78 | |
| 79 | 79 | return new ResourcesListResponse($items); | 
| 80 | - } | |
| 80 | + } | |
| 81 | 81 | |
| 82 | - /** | |
| 83 | -   * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_pages") | |
| 84 | - */ | |
| 85 | -  public function createAction(Request $request) { | |
| 82 | + /** | |
| 83 | +     * @Route("/api/{version}/facebook/pages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_create_facebook_pages") | |
| 84 | + */ | |
| 85 | +    public function createAction(Request $request) { | |
| 86 | 86 | /* @var FacebookPage $feed */ | 
| 87 | 87 | $page = $this->facebookPageFactory->create(); | 
| 88 | 88 |      $form = $this->formFactory->createNamed('', FacebookPageType::class, $page, ['method' => $request->getMethod()]); | 
| 89 | 89 | |
| 90 | 90 | $form->handleRequest($request); | 
| 91 | 91 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 92 | - $this->checkIfPageExists($page); | |
| 93 | - $this->facebookPageRepository->add($page); | |
| 92 | + $this->checkIfPageExists($page); | |
| 93 | + $this->facebookPageRepository->add($page); | |
| 94 | 94 | |
| 95 | - return new SingleResourceResponse($page, new ResponseContext(201)); | |
| 95 | + return new SingleResourceResponse($page, new ResponseContext(201)); | |
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | 98 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 99 | - } | |
| 99 | + } | |
| 100 | 100 | |
| 101 | - /** | |
| 102 | -   * @Route("/api/{version}/facebook/pages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_pages") | |
| 103 | - */ | |
| 104 | -  public function deleteAction(int $id): SingleResourceResponseInterface { | |
| 101 | + /** | |
| 102 | +     * @Route("/api/{version}/facebook/pages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_delete_facebook_pages") | |
| 103 | + */ | |
| 104 | +    public function deleteAction(int $id): SingleResourceResponseInterface { | |
| 105 | 105 | $repository = $this->facebookPageRepository; | 
| 106 | 106 |      if (null === $page = $this->facebookPageRepository->findOneBy(['id' => $id])) { | 
| 107 | -      throw new NotFoundHttpException('There is no Page with provided id!'); | |
| 107 | +        throw new NotFoundHttpException('There is no Page with provided id!'); | |
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 |      if (null !== $feed = $this->facebookInstantArticlesFeedRepository->findOneBy(['facebookPage' => $id])) { | 
| 111 | -      throw new ConflictHttpException(sprintf('This Page is used by Instant Articles Feed with id: %s!', $feed->getId())); | |
| 111 | +        throw new ConflictHttpException(sprintf('This Page is used by Instant Articles Feed with id: %s!', $feed->getId())); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | $repository->remove($page); | 
| 115 | 115 | |
| 116 | 116 | return new SingleResourceResponse(null, new ResponseContext(204)); | 
| 117 | - } | |
| 117 | + } | |
| 118 | 118 | |
| 119 | -  private function checkIfPageExists(PageInterface $page): void { | |
| 119 | +    private function checkIfPageExists(PageInterface $page): void { | |
| 120 | 120 | if (null !== $this->facebookPageRepository->findOneBy([ | 
| 121 | 121 | 'pageId' => $page->getPageId(), | 
| 122 | 122 | ]) | 
| 123 | 123 |      ) { | 
| 124 | -      throw new ConflictHttpException('This Page already exists!'); | |
| 124 | +        throw new ConflictHttpException('This Page already exists!'); | |
| 125 | + } | |
| 125 | 126 | } | 
| 126 | - } | |
| 127 | 127 | } | 
| @@ -43,32 +43,32 @@ discard block | ||
| 43 | 43 | |
| 44 | 44 |  class ContentListController extends AbstractController { | 
| 45 | 45 | |
| 46 | - private ContentListRepositoryInterface $contentListRepository; | |
| 47 | - private ContentListItemRepositoryInterface $contentListItemRepository; | |
| 48 | - private ContentListServiceInterface $contentListService; | |
| 49 | - private FormFactoryInterface $formFactory; | |
| 50 | - private EntityManagerInterface $entityManager; | |
| 51 | - private EventDispatcherInterface $eventDispatcher; | |
| 52 | - private FactoryInterface $factory; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @param ContentListRepositoryInterface $contentListRepository | |
| 56 | - * @param ContentListItemRepositoryInterface $contentListItemRepository | |
| 57 | - * @param ContentListServiceInterface $contentListService | |
| 58 | - * @param FormFactoryInterface $formFactory | |
| 59 | - * @param EntityManagerInterface $entityManager | |
| 60 | - * @param EventDispatcherInterface $eventDispatcher | |
| 61 | - * @param FactoryInterface $factory | |
| 62 | - */ | |
| 63 | - public function __construct( | |
| 64 | - ContentListRepositoryInterface $contentListRepository, | |
| 65 | - ContentListItemRepositoryInterface $contentListItemRepository, | |
| 66 | - ContentListServiceInterface $contentListService, | |
| 67 | - FormFactoryInterface $formFactory, | |
| 68 | - EntityManagerInterface $entityManager, | |
| 69 | - EventDispatcherInterface $eventDispatcher, | |
| 70 | - FactoryInterface $factory | |
| 71 | -  ) { | |
| 46 | + private ContentListRepositoryInterface $contentListRepository; | |
| 47 | + private ContentListItemRepositoryInterface $contentListItemRepository; | |
| 48 | + private ContentListServiceInterface $contentListService; | |
| 49 | + private FormFactoryInterface $formFactory; | |
| 50 | + private EntityManagerInterface $entityManager; | |
| 51 | + private EventDispatcherInterface $eventDispatcher; | |
| 52 | + private FactoryInterface $factory; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @param ContentListRepositoryInterface $contentListRepository | |
| 56 | + * @param ContentListItemRepositoryInterface $contentListItemRepository | |
| 57 | + * @param ContentListServiceInterface $contentListService | |
| 58 | + * @param FormFactoryInterface $formFactory | |
| 59 | + * @param EntityManagerInterface $entityManager | |
| 60 | + * @param EventDispatcherInterface $eventDispatcher | |
| 61 | + * @param FactoryInterface $factory | |
| 62 | + */ | |
| 63 | + public function __construct( | |
| 64 | + ContentListRepositoryInterface $contentListRepository, | |
| 65 | + ContentListItemRepositoryInterface $contentListItemRepository, | |
| 66 | + ContentListServiceInterface $contentListService, | |
| 67 | + FormFactoryInterface $formFactory, | |
| 68 | + EntityManagerInterface $entityManager, | |
| 69 | + EventDispatcherInterface $eventDispatcher, | |
| 70 | + FactoryInterface $factory | |
| 71 | +    ) { | |
| 72 | 72 | $this->contentListRepository = $contentListRepository; | 
| 73 | 73 | $this->contentListItemRepository = $contentListItemRepository; | 
| 74 | 74 | $this->contentListService = $contentListService; | 
| @@ -76,28 +76,28 @@ discard block | ||
| 76 | 76 | $this->entityManager = $entityManager; | 
| 77 | 77 | $this->eventDispatcher = $eventDispatcher; | 
| 78 | 78 | $this->factory = $factory; | 
| 79 | - } | |
| 79 | + } | |
| 80 | 80 | |
| 81 | - /** | |
| 82 | -   * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") | |
| 83 | - */ | |
| 84 | -  public function listAction(Request $request): ResourcesListResponseInterface { | |
| 81 | + /** | |
| 82 | +     * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists") | |
| 83 | + */ | |
| 84 | +    public function listAction(Request $request): ResourcesListResponseInterface { | |
| 85 | 85 |      $lists = $this->contentListRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); | 
| 86 | 86 | |
| 87 | 87 | return new ResourcesListResponse($lists); | 
| 88 | - } | |
| 88 | + } | |
| 89 | 89 | |
| 90 | - /** | |
| 91 | -   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) | |
| 92 | - */ | |
| 93 | -  public function getAction($id): SingleResourceResponseInterface { | |
| 90 | + /** | |
| 91 | +     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"}) | |
| 92 | + */ | |
| 93 | +    public function getAction($id): SingleResourceResponseInterface { | |
| 94 | 94 | return new SingleResourceResponse($this->findOr404($id)); | 
| 95 | - } | |
| 95 | + } | |
| 96 | 96 | |
| 97 | - /** | |
| 98 | -   * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") | |
| 99 | - */ | |
| 100 | -  public function createAction(Request $request): SingleResourceResponseInterface { | |
| 97 | + /** | |
| 98 | +     * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists") | |
| 99 | + */ | |
| 100 | +    public function createAction(Request $request): SingleResourceResponseInterface { | |
| 101 | 101 | /* @var ContentListInterface $contentList */ | 
| 102 | 102 | $contentList = $this->factory->create(); | 
| 103 | 103 |      $form = $this->formFactory->createNamed('', ContentListType::class, $contentList, ['method' => $request->getMethod()]); | 
| @@ -106,18 +106,18 @@ discard block | ||
| 106 | 106 | $this->ensureContentListExists($contentList->getName()); | 
| 107 | 107 | |
| 108 | 108 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 109 | - $this->contentListRepository->add($contentList); | |
| 109 | + $this->contentListRepository->add($contentList); | |
| 110 | 110 | |
| 111 | - return new SingleResourceResponse($contentList, new ResponseContext(201)); | |
| 111 | + return new SingleResourceResponse($contentList, new ResponseContext(201)); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 115 | - } | |
| 115 | + } | |
| 116 | 116 | |
| 117 | - /** | |
| 118 | -   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) | |
| 119 | - */ | |
| 120 | -  public function updateAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 117 | + /** | |
| 118 | +     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"}) | |
| 119 | + */ | |
| 120 | +    public function updateAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 121 | 121 | $objectManager = $this->entityManager; | 
| 122 | 122 | /** @var ContentListInterface $contentList */ | 
| 123 | 123 | $contentList = $this->findOr404($id); | 
| @@ -128,51 +128,51 @@ discard block | ||
| 128 | 128 | $form->handleRequest($request); | 
| 129 | 129 | |
| 130 | 130 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 131 | - $this->eventDispatcher->dispatch( | |
| 132 | - new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), | |
| 133 | - ContentListEvents::LIST_CRITERIA_CHANGE | |
| 134 | - ); | |
| 131 | + $this->eventDispatcher->dispatch( | |
| 132 | + new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]), | |
| 133 | + ContentListEvents::LIST_CRITERIA_CHANGE | |
| 134 | + ); | |
| 135 | 135 | |
| 136 | - $objectManager->flush(); | |
| 136 | + $objectManager->flush(); | |
| 137 | 137 | |
| 138 | - return new SingleResourceResponse($contentList); | |
| 138 | + return new SingleResourceResponse($contentList); | |
| 139 | 139 | } | 
| 140 | 140 | |
| 141 | 141 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 142 | - } | |
| 142 | + } | |
| 143 | 143 | |
| 144 | - /** | |
| 145 | -   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) | |
| 146 | - */ | |
| 147 | -  public function deleteAction($id): SingleResourceResponseInterface { | |
| 144 | + /** | |
| 145 | +     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"}) | |
| 146 | + */ | |
| 147 | +    public function deleteAction($id): SingleResourceResponseInterface { | |
| 148 | 148 | $repository = $this->contentListRepository; | 
| 149 | 149 | $contentList = $this->findOr404($id); | 
| 150 | 150 | |
| 151 | 151 | $repository->remove($contentList); | 
| 152 | 152 | |
| 153 | 153 | return new SingleResourceResponse(null, new ResponseContext(204)); | 
| 154 | - } | |
| 154 | + } | |
| 155 | 155 | |
| 156 | - /** | |
| 157 | -   * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") | |
| 158 | - */ | |
| 159 | -  public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { | |
| 156 | + /** | |
| 157 | +     * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink") | |
| 158 | + */ | |
| 159 | +    public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface { | |
| 160 | 160 | $objectManager = $this->entityManager; | 
| 161 | 161 | /** @var ContentListInterface $contentList */ | 
| 162 | 162 | $contentList = $this->findOr404($id); | 
| 163 | 163 | |
| 164 | 164 | $matched = false; | 
| 165 | 165 |      foreach ($request->attributes->get('links', []) as $key => $objectArray) { | 
| 166 | -      if (!is_array($objectArray)) { | |
| 166 | +        if (!is_array($objectArray)) { | |
| 167 | 167 | continue; | 
| 168 | - } | |
| 168 | + } | |
| 169 | 169 | |
| 170 | - $object = $objectArray['object']; | |
| 171 | -      if ($object instanceof Exception) { | |
| 170 | + $object = $objectArray['object']; | |
| 171 | +        if ($object instanceof Exception) { | |
| 172 | 172 | throw $object; | 
| 173 | - } | |
| 173 | + } | |
| 174 | 174 | |
| 175 | -      if ($object instanceof ArticleInterface) { | |
| 175 | +        if ($object instanceof ArticleInterface) { | |
| 176 | 176 | $contentListItem = $this->contentListItemRepository | 
| 177 | 177 | ->findOneBy([ | 
| 178 | 178 | 'contentList' => $contentList, | 
| @@ -180,59 +180,59 @@ discard block | ||
| 180 | 180 | ]); | 
| 181 | 181 | |
| 182 | 182 |          if ('LINK' === $request->getMethod()) { | 
| 183 | - $position = 0; | |
| 184 | -          if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { | |
| 183 | + $position = 0; | |
| 184 | +            if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) { | |
| 185 | 185 |              foreach ($notConvertedLinks as $link) { | 
| 186 | -              if (isset($link['resourceType']) && 'position' === $link['resourceType']) { | |
| 186 | +                if (isset($link['resourceType']) && 'position' === $link['resourceType']) { | |
| 187 | 187 | $position = $link['resource']; | 
| 188 | - } | |
| 188 | + } | |
| 189 | + } | |
| 189 | 190 | } | 
| 190 | - } | |
| 191 | 191 | |
| 192 | -          if (false === $position && $contentListItem) { | |
| 192 | +            if (false === $position && $contentListItem) { | |
| 193 | 193 |              throw new ConflictHttpException('This content is already linked to Content List'); | 
| 194 | - } | |
| 194 | + } | |
| 195 | 195 | |
| 196 | -          if (!$contentListItem) { | |
| 196 | +            if (!$contentListItem) { | |
| 197 | 197 | $contentListItem = $this->contentListService->addArticleToContentList($contentList, $object, $position); | 
| 198 | 198 | $objectManager->persist($contentListItem); | 
| 199 | -          } else { | |
| 199 | +            } else { | |
| 200 | 200 | $contentListItem->setPosition($position); | 
| 201 | - } | |
| 201 | + } | |
| 202 | 202 | |
| 203 | - $objectManager->flush(); | |
| 203 | + $objectManager->flush(); | |
| 204 | 204 |          } elseif ('UNLINK' === $request->getMethod()) { | 
| 205 | -          if ($contentListItem->getContentList() !== $contentList) { | |
| 205 | +            if ($contentListItem->getContentList() !== $contentList) { | |
| 206 | 206 |              throw new ConflictHttpException('Content is not linked to content list'); | 
| 207 | - } | |
| 208 | - $objectManager->remove($contentListItem); | |
| 207 | + } | |
| 208 | + $objectManager->remove($contentListItem); | |
| 209 | 209 | } | 
| 210 | 210 | |
| 211 | 211 | $matched = true; | 
| 212 | 212 | |
| 213 | 213 | break; | 
| 214 | - } | |
| 214 | + } | |
| 215 | 215 | } | 
| 216 | 216 |      if (false === $matched) { | 
| 217 | -      throw new NotFoundHttpException('Any supported link object was not found'); | |
| 217 | +        throw new NotFoundHttpException('Any supported link object was not found'); | |
| 218 | 218 | } | 
| 219 | 219 | |
| 220 | 220 | $objectManager->flush(); | 
| 221 | 221 | |
| 222 | 222 | return new SingleResourceResponse($contentList, new ResponseContext(201)); | 
| 223 | - } | |
| 223 | + } | |
| 224 | 224 | |
| 225 | -  private function findOr404($id) { | |
| 225 | +    private function findOr404($id) { | |
| 226 | 226 |      if (null === $list = $this->contentListRepository->find($id)) { | 
| 227 | -      throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); | |
| 227 | +        throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id)); | |
| 228 | 228 | } | 
| 229 | 229 | |
| 230 | 230 | return $list; | 
| 231 | - } | |
| 231 | + } | |
| 232 | 232 | |
| 233 | -  private function ensureContentListExists($name) { | |
| 233 | +    private function ensureContentListExists($name) { | |
| 234 | 234 |      if (null !== $this->contentListRepository->findOneBy(['name' => $name])) { | 
| 235 | -      throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); | |
| 235 | +        throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name)); | |
| 236 | + } | |
| 236 | 237 | } | 
| 237 | - } | |
| 238 | 238 | } | 
| @@ -27,51 +27,51 @@ | ||
| 27 | 27 | |
| 28 | 28 |  class RedirectingController extends AbstractController { | 
| 29 | 29 | |
| 30 | - private RouterInterface $router; | |
| 31 | - private ArticleRepositoryInterface $articleRepository; | |
| 30 | + private RouterInterface $router; | |
| 31 | + private ArticleRepositoryInterface $articleRepository; | |
| 32 | 32 | |
| 33 | - /** | |
| 34 | - * @param RouterInterface $router | |
| 35 | - * @param ArticleRepositoryInterface $articleRepository | |
| 36 | - */ | |
| 37 | -  public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { | |
| 33 | + /** | |
| 34 | + * @param RouterInterface $router | |
| 35 | + * @param ArticleRepositoryInterface $articleRepository | |
| 36 | + */ | |
| 37 | +    public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) { | |
| 38 | 38 | $this->router = $router; | 
| 39 | 39 | $this->articleRepository = $articleRepository; | 
| 40 | - } | |
| 40 | + } | |
| 41 | 41 | |
| 42 | 42 | |
| 43 | -  public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { | |
| 43 | +    public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse { | |
| 44 | 44 |      try { | 
| 45 | - $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); | |
| 46 | -      if (null === $existingArticle) { | |
| 45 | + $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); | |
| 46 | +        if (null === $existingArticle) { | |
| 47 | 47 | $existingArticle = $this->articleRepository->getArticleByPackageExtraData($key, $value)->getQuery()->getOneOrNullResult(); | 
| 48 | - } | |
| 48 | + } | |
| 49 | 49 |      } catch (NonUniqueResultException $e) { | 
| 50 | - $existingArticle = null; | |
| 50 | + $existingArticle = null; | |
| 51 | 51 | } | 
| 52 | 52 | |
| 53 | 53 |      if (null === $existingArticle || null === $existingArticle->getRoute()) { | 
| 54 | -      throw $this->createNotFoundException('Article with provided data was not found.'); | |
| 54 | +        throw $this->createNotFoundException('Article with provided data was not found.'); | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); | 
| 58 | - } | |
| 58 | + } | |
| 59 | 59 | |
| 60 | -  public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { | |
| 60 | +    public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse { | |
| 61 | 61 | $existingArticle = $this->articleRepository->findOneBySlug($slug); | 
| 62 | 62 |      if (null === $existingArticle || null === $existingArticle->getRoute()) { | 
| 63 | -      throw $this->createNotFoundException('Article not found.'); | |
| 63 | +        throw $this->createNotFoundException('Article not found.'); | |
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); | 
| 67 | - } | |
| 67 | + } | |
| 68 | 68 | |
| 69 | -  private function generateArticleUrl(Request $request, ArticleInterface $article): string { | |
| 69 | +    private function generateArticleUrl(Request $request, ArticleInterface $article): string { | |
| 70 | 70 | $parameters = ['slug' => $article->getSlug()]; | 
| 71 | 71 |      if ($request->query->has('amp')) { | 
| 72 | - $parameters['amp'] = 1; | |
| 72 | + $parameters['amp'] = 1; | |
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | 75 | return $this->router->generate($article->getRoute(), $parameters, UrlGeneratorInterface::ABSOLUTE_URL); | 
| 76 | - } | |
| 76 | + } | |
| 77 | 77 | } | 
| @@ -28,40 +28,40 @@ discard block | ||
| 28 | 28 | |
| 29 | 29 |  class DefaultController extends AbstractController { | 
| 30 | 30 | |
| 31 | - private CachedTenantContextInterface $tenantContext; | |
| 32 | - private MetaFactoryInterface $metaFactory; | |
| 33 | - private Context $templateEngineContext; | |
| 34 | - private RouteFactoryInterface $routeFactory; | |
| 31 | + private CachedTenantContextInterface $tenantContext; | |
| 32 | + private MetaFactoryInterface $metaFactory; | |
| 33 | + private Context $templateEngineContext; | |
| 34 | + private RouteFactoryInterface $routeFactory; | |
| 35 | 35 | |
| 36 | - public function __construct( | |
| 37 | - CachedTenantContextInterface $tenantContext, | |
| 38 | - MetaFactoryInterface $metaFactory, | |
| 39 | - Context $templateEngineContext, | |
| 40 | - RouteFactoryInterface $routeFactory | |
| 41 | -  ) { | |
| 36 | + public function __construct( | |
| 37 | + CachedTenantContextInterface $tenantContext, | |
| 38 | + MetaFactoryInterface $metaFactory, | |
| 39 | + Context $templateEngineContext, | |
| 40 | + RouteFactoryInterface $routeFactory | |
| 41 | +    ) { | |
| 42 | 42 | $this->tenantContext = $tenantContext; | 
| 43 | 43 | $this->metaFactory = $metaFactory; | 
| 44 | 44 | $this->templateEngineContext = $templateEngineContext; | 
| 45 | 45 | $this->routeFactory = $routeFactory; | 
| 46 | - } | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | -   * @Route("/", methods={"GET","POST"}, name="homepage") | |
| 50 | - */ | |
| 51 | -  public function indexAction(Request $request): Response { | |
| 48 | + /** | |
| 49 | +     * @Route("/", methods={"GET","POST"}, name="homepage") | |
| 50 | + */ | |
| 51 | +    public function indexAction(Request $request): Response { | |
| 52 | 52 | /** @var TenantInterface $currentTenant */ | 
| 53 | 53 | $currentTenant = $this->tenantContext->getTenant(); | 
| 54 | 54 | $route = $currentTenant->getHomepage(); | 
| 55 | 55 | |
| 56 | 56 |      if (null === $route) { | 
| 57 | - /** @var RouteInterface $route */ | |
| 58 | - $route = $this->routeFactory->create(); | |
| 59 | -      $route->setStaticPrefix('/'); | |
| 60 | -      $route->setName('Homepage'); | |
| 61 | -      $route->setType('content'); | |
| 62 | -      $route->setTemplateName('index.html.twig'); | |
| 63 | - $route->setCacheTimeInSeconds(360); | |
| 64 | - $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); | |
| 57 | + /** @var RouteInterface $route */ | |
| 58 | + $route = $this->routeFactory->create(); | |
| 59 | +        $route->setStaticPrefix('/'); | |
| 60 | +        $route->setName('Homepage'); | |
| 61 | +        $route->setType('content'); | |
| 62 | +        $route->setTemplateName('index.html.twig'); | |
| 63 | + $route->setCacheTimeInSeconds(360); | |
| 64 | + $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | $this->templateEngineContext->setCurrentPage($this->metaFactory->create($route)); | 
| @@ -70,5 +70,5 @@ discard block | ||
| 70 | 70 |      $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); | 
| 71 | 71 | |
| 72 | 72 |      return $this->render('index.html.twig', [], $response); | 
| 73 | - } | |
| 73 | + } | |
| 74 | 74 | } | 
| @@ -45,39 +45,39 @@ discard block | ||
| 45 | 45 | |
| 46 | 46 |  class PackageController extends Controller { | 
| 47 | 47 | |
| 48 | - private FormFactoryInterface $formFactory; | |
| 49 | - private EventDispatcherInterface $eventDispatcher; | |
| 50 | - private CachedTenantContextInterface $cachedTenantContext; | |
| 51 | - private ArticlePublisherInterface $articlePublisher; | |
| 52 | - private PersisterRegistry $elasticaPersisterRegistry; | |
| 53 | - private PackageRepositoryInterface $packageRepository; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * @param FormFactoryInterface $formFactory | |
| 57 | - * @param EventDispatcherInterface $eventDispatcher | |
| 58 | - * @param CachedTenantContextInterface $cachedTenantContext | |
| 59 | - * @param ArticlePublisherInterface $articlePublisher | |
| 60 | - * @param PersisterRegistry $elasticaPersisterRegistry | |
| 61 | - * @param PackageRepositoryInterface $packageRepository | |
| 62 | - */ | |
| 63 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, | |
| 64 | - CachedTenantContextInterface $cachedTenantContext, | |
| 65 | - ArticlePublisherInterface $articlePublisher, | |
| 66 | - PersisterRegistry $elasticaPersisterRegistry, | |
| 67 | -                              PackageRepositoryInterface   $packageRepository) { | |
| 48 | + private FormFactoryInterface $formFactory; | |
| 49 | + private EventDispatcherInterface $eventDispatcher; | |
| 50 | + private CachedTenantContextInterface $cachedTenantContext; | |
| 51 | + private ArticlePublisherInterface $articlePublisher; | |
| 52 | + private PersisterRegistry $elasticaPersisterRegistry; | |
| 53 | + private PackageRepositoryInterface $packageRepository; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * @param FormFactoryInterface $formFactory | |
| 57 | + * @param EventDispatcherInterface $eventDispatcher | |
| 58 | + * @param CachedTenantContextInterface $cachedTenantContext | |
| 59 | + * @param ArticlePublisherInterface $articlePublisher | |
| 60 | + * @param PersisterRegistry $elasticaPersisterRegistry | |
| 61 | + * @param PackageRepositoryInterface $packageRepository | |
| 62 | + */ | |
| 63 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, | |
| 64 | + CachedTenantContextInterface $cachedTenantContext, | |
| 65 | + ArticlePublisherInterface $articlePublisher, | |
| 66 | + PersisterRegistry $elasticaPersisterRegistry, | |
| 67 | +                                PackageRepositoryInterface   $packageRepository) { | |
| 68 | 68 | $this->formFactory = $formFactory; | 
| 69 | 69 | $this->eventDispatcher = $eventDispatcher; | 
| 70 | 70 | $this->cachedTenantContext = $cachedTenantContext; | 
| 71 | 71 | $this->articlePublisher = $articlePublisher; | 
| 72 | 72 | $this->elasticaPersisterRegistry = $elasticaPersisterRegistry; | 
| 73 | 73 | $this->packageRepository = $packageRepository; | 
| 74 | - } | |
| 74 | + } | |
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** | |
| 78 | -   * @Route("/api/{version}/packages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_packages") | |
| 79 | - */ | |
| 80 | -  public function listAction(Request $request) { | |
| 77 | + /** | |
| 78 | +     * @Route("/api/{version}/packages/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_packages") | |
| 79 | + */ | |
| 80 | +    public function listAction(Request $request) { | |
| 81 | 81 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| 82 | 82 | $tenantContext = $this->cachedTenantContext; | 
| 83 | 83 | |
| @@ -88,19 +88,19 @@ discard block | ||
| 88 | 88 |          ]), $request->query->all('sorting'), new PaginationData($request)); | 
| 89 | 89 | |
| 90 | 90 | return new ResourcesListResponse($packages); | 
| 91 | - } | |
| 91 | + } | |
| 92 | 92 | |
| 93 | - /** | |
| 94 | -   * @Route("/api/{version}/packages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_package", requirements={"id"="\d+"}) | |
| 95 | - */ | |
| 96 | -  public function getAction(int $id): SingleResourceResponseInterface { | |
| 93 | + /** | |
| 94 | +     * @Route("/api/{version}/packages/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_package", requirements={"id"="\d+"}) | |
| 95 | + */ | |
| 96 | +    public function getAction(int $id): SingleResourceResponseInterface { | |
| 97 | 97 | return new SingleResourceResponse($this->findOr404($id)); | 
| 98 | - } | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - /** | |
| 101 | -   * @Route("/api/{version}/packages/{id}/publish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publish_package", requirements={"id"="\d+"}) | |
| 102 | - */ | |
| 103 | -  public function publishAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 100 | + /** | |
| 101 | +     * @Route("/api/{version}/packages/{id}/publish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publish_package", requirements={"id"="\d+"}) | |
| 102 | + */ | |
| 103 | +    public function publishAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 104 | 104 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| 105 | 105 | /** @var PackageInterface $package */ | 
| 106 | 106 | $package = $this->findOr404($id); | 
| @@ -109,74 +109,74 @@ discard block | ||
| 109 | 109 | $form->handleRequest($request); | 
| 110 | 110 | |
| 111 | 111 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 112 | - $this->articlePublisher->publish($package, $form->getData()); | |
| 113 | -      $this->elasticaPersisterRegistry->getPersister('swp_package')->replaceOne($package); | |
| 112 | + $this->articlePublisher->publish($package, $form->getData()); | |
| 113 | +        $this->elasticaPersisterRegistry->getPersister('swp_package')->replaceOne($package); | |
| 114 | 114 | |
| 115 | - return new SingleResourceResponse(null, new ResponseContext(201)); | |
| 115 | + return new SingleResourceResponse(null, new ResponseContext(201)); | |
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 119 | - } | |
| 119 | + } | |
| 120 | 120 | |
| 121 | - /** | |
| 122 | -   * @Route("/api/{version}/packages/{id}/unpublish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_unpublish_package", requirements={"id"="\d+"}) | |
| 123 | - */ | |
| 124 | -  public function unpublishAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 121 | + /** | |
| 122 | +     * @Route("/api/{version}/packages/{id}/unpublish/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_unpublish_package", requirements={"id"="\d+"}) | |
| 123 | + */ | |
| 124 | +    public function unpublishAction(Request $request, int $id): SingleResourceResponseInterface { | |
| 125 | 125 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| 126 | 126 | $package = $this->findOr404($id); | 
| 127 | 127 |      $form = $this->formFactory->createNamed('', UnpublishFromTenantsType::class, null, ['method' => $request->getMethod()]); | 
| 128 | 128 | |
| 129 | 129 | $form->handleRequest($request); | 
| 130 | 130 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 131 | - $formData = $form->getData(); | |
| 132 | - /** @var Collection $tenants */ | |
| 133 | - $tenants = $formData['tenants']; | |
| 134 | - $this->articlePublisher->unpublish($package, $tenants->toArray()); | |
| 131 | + $formData = $form->getData(); | |
| 132 | + /** @var Collection $tenants */ | |
| 133 | + $tenants = $formData['tenants']; | |
| 134 | + $this->articlePublisher->unpublish($package, $tenants->toArray()); | |
| 135 | 135 | |
| 136 | - return new SingleResourceResponse(null, new ResponseContext(200)); | |
| 136 | + return new SingleResourceResponse(null, new ResponseContext(200)); | |
| 137 | 137 | } | 
| 138 | 138 | |
| 139 | 139 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | -   * @Route("/api/{version}/packages/{id}/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_package", requirements={"id"="\d+"}) | |
| 144 | - * | |
| 145 | - * @return SingleResourceResponse | |
| 146 | - */ | |
| 147 | -  public function updateAction(Request $request, int $id) { | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | +     * @Route("/api/{version}/packages/{id}/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_package", requirements={"id"="\d+"}) | |
| 144 | + * | |
| 145 | + * @return SingleResourceResponse | |
| 146 | + */ | |
| 147 | +    public function updateAction(Request $request, int $id) { | |
| 148 | 148 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| 149 | 149 | $package = $this->findOr404($id); | 
| 150 | 150 |      $form = $this->formFactory->createNamed('', PackageType::class, $package, ['method' => $request->getMethod()]); | 
| 151 | 151 | |
| 152 | 152 | $form->handleRequest($request); | 
| 153 | 153 |      if ($form->isSubmitted() && $form->isValid()) { | 
| 154 | -      if (ContentInterface::STATUS_CANCELED === $package->getPubStatus()) { | |
| 154 | +        if (ContentInterface::STATUS_CANCELED === $package->getPubStatus()) { | |
| 155 | 155 | $package->setStatus(ContentInterface::STATUS_CANCELED); | 
| 156 | - } | |
| 157 | - $this->getPackageRepository()->flush(); | |
| 156 | + } | |
| 157 | + $this->getPackageRepository()->flush(); | |
| 158 | 158 | |
| 159 | - return new SingleResourceResponse($package, new ResponseContext(200)); | |
| 159 | + return new SingleResourceResponse($package, new ResponseContext(200)); | |
| 160 | 160 | } | 
| 161 | 161 | |
| 162 | 162 | return new SingleResourceResponse($form, new ResponseContext(400)); | 
| 163 | - } | |
| 163 | + } | |
| 164 | 164 | |
| 165 | - /** | |
| 166 | - * @return object|null | |
| 167 | - */ | |
| 168 | -  private function findOr404(int $id) { | |
| 165 | + /** | |
| 166 | + * @return object|null | |
| 167 | + */ | |
| 168 | +    private function findOr404(int $id) { | |
| 169 | 169 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); | 
| 170 | 170 | $tenantContext = $this->cachedTenantContext; | 
| 171 | 171 | |
| 172 | 172 |      if (null === $package = $this->getPackageRepository()->findOneBy(['id' => $id, 'organization' => $tenantContext->getTenant()->getOrganization()])) { | 
| 173 | -      throw new NotFoundHttpException('Package was not found.'); | |
| 173 | +        throw new NotFoundHttpException('Package was not found.'); | |
| 174 | 174 | } | 
| 175 | 175 | |
| 176 | 176 | return $package; | 
| 177 | - } | |
| 177 | + } | |
| 178 | 178 | |
| 179 | -  protected function getPackageRepository() { | |
| 179 | +    protected function getPackageRepository() { | |
| 180 | 180 | return $this->packageRepository; | 
| 181 | - } | |
| 181 | + } | |
| 182 | 182 | } |