Skip to content

Commit

Permalink
Merge pull request #2965 from acrobat/sf5-forward-compatibility
Browse files Browse the repository at this point in the history
[AllBundles] Extra sf5 forward compatibility
  • Loading branch information
acrobat authored Oct 5, 2021
2 parents 2914a34 + a3682db commit 97a0928
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 33 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-5.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class BlogOverviewPageViewDataProvider implements PageViewDataProviderInterface
}
```

* Not passing the "translator" service as the 6th argument of `Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher::__construct` is deprecated and will be required in KunstmaanNodeBundle 6.0. Injected the required service in the constructor.
* `Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher::chooseHowToPublish` is deprecated and replaced by `Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher::handlePublish`
* `Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher::chooseHowToUnpublish` is deprecated and replaced by `Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher::handleUnpublish`

NodeSearchBundle
------------

Expand Down
11 changes: 8 additions & 3 deletions src/Kunstmaan/AdminBundle/Security/OAuthAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class OAuthAuthenticator extends AbstractGuardAuthenticator
{
Expand All @@ -24,7 +25,7 @@ class OAuthAuthenticator extends AbstractGuardAuthenticator
/** @var SessionInterface */
private $session;

/** @var TranslatorInterface */
/** @var TranslatorInterface|LegacyTranslatorInterface */
private $translator;

/** @var OAuthUserCreator */
Expand All @@ -36,8 +37,12 @@ class OAuthAuthenticator extends AbstractGuardAuthenticator
/** @var string */
private $clientSecret;

public function __construct(RouterInterface $router, SessionInterface $session, TranslatorInterface $translator, OAuthUserCreatorInterface $oAuthUserCreator, $clientId, $clientSecret)
public function __construct(RouterInterface $router, SessionInterface $session, /* TranslatorInterface */ $translator, OAuthUserCreatorInterface $oAuthUserCreator, $clientId, $clientSecret)
{
if (null !== $translator && (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface)) {
throw new \InvalidArgumentException(sprintf('Argument 3 passed to "%s" must be of the type "%s" or "%s", "%s" given', __METHOD__, LegacyTranslatorInterface::class, TranslatorInterface::class, get_class($translator)));
}

$this->router = $router;
$this->session = $session;
$this->translator = $translator;
Expand Down
8 changes: 4 additions & 4 deletions src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function publishAction(Request $request, $id)

$nodeTranslation = $node->getNodeTranslation($this->locale, true);
$request = $this->get('request_stack')->getCurrentRequest();
$this->nodePublisher->chooseHowToPublish($request, $nodeTranslation, $this->translator);
$this->nodePublisher->handlePublish($request, $nodeTranslation);

return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', ['id' => $node->getId()]));
}
Expand All @@ -340,7 +340,7 @@ public function unPublishAction(Request $request, $id)

$nodeTranslation = $node->getNodeTranslation($this->locale, true);
$request = $this->get('request_stack')->getCurrentRequest();
$this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator);
$this->nodePublisher->handleUnpublish($request, $nodeTranslation);

return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', ['id' => $node->getId()]));
}
Expand Down Expand Up @@ -971,9 +971,9 @@ public function editAction(Request $request, $id, $subaction)
$this->get('translator')->trans('kuma_node.admin.edit.flash.locked_success')
);
} elseif ($request->request->has('publishing') || $request->request->has('publish_later')) {
$this->nodePublisher->chooseHowToPublish($request, $nodeTranslation, $this->translator);
$this->nodePublisher->handlePublish($request, $nodeTranslation);
} elseif ($request->request->has('unpublishing') || $request->request->has('unpublish_later')) {
$this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator);
$this->nodePublisher->handleUnpublish($request, $nodeTranslation);
} else {
$this->addFlash(
FlashTypes::SUCCESS,
Expand Down
10 changes: 7 additions & 3 deletions src/Kunstmaan/NodeBundle/EventListener/FixDateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Kunstmaan\NodeBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

/**
* Fixes bug with date vs Date headers
Expand All @@ -13,10 +13,14 @@ class FixDateListener
/**
* Make sure response has a timestamp
*
* @param FilterResponseEvent|GetResponseEvent $event
* @param FilterResponseEvent|ResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse($event)
{
if (!$event instanceof FilterResponseEvent && !$event instanceof ResponseEvent) {
throw new \InvalidArgumentException(\sprintf('Expected instance of type %s, %s given', \class_exists(ResponseEvent::class) ? ResponseEvent::class : FilterResponseEvent::class, \is_object($event) ? \get_class($event) : \gettype($event)));
}

$response = $event->getResponse();
if ($response) {
$date = $response->getDate();
Expand Down
74 changes: 56 additions & 18 deletions src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class NodeAdminPublisher
{
Expand Down Expand Up @@ -50,6 +51,9 @@ class NodeAdminPublisher
*/
private $cloneHelper;

/** @var LegacyTranslatorInterface|TranslatorInterface|null */
private $translator;

/**
* @param EntityManager $em The entity manager
* @param TokenStorageInterface $tokenStorage The security token storage
Expand All @@ -62,13 +66,23 @@ public function __construct(
TokenStorageInterface $tokenStorage,
AuthorizationCheckerInterface $authorizationChecker,
EventDispatcherInterface $eventDispatcher,
CloneHelper $cloneHelper
CloneHelper $cloneHelper,
/*TranslatorInterface*/ $translator = null
) {
if (null !== $translator && (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface)) {
throw new \InvalidArgumentException(sprintf('Argument 6 passed to "%s" must be of the type "%s" or "%s", "%s" given', __METHOD__, LegacyTranslatorInterface::class, TranslatorInterface::class, get_class($translator)));
}

if (null === $translator) {
@trigger_error(sprintf('Not passing the "translator" service as the 6th argument of "%s" is deprecated since KunstmaanNodeBundle 5.9 and will be required in KunstmaanNodeBundle 6.0. Injected the required services in the constructor.', __METHOD__), E_USER_DEPRECATED);
}

$this->em = $em;
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
$this->eventDispatcher = $eventDispatcher;
$this->cloneHelper = $cloneHelper;
$this->translator = $translator;
}

/**
Expand Down Expand Up @@ -263,7 +277,7 @@ public function createPublicVersion(
return $newNodeVersion;
}

public function chooseHowToPublish(Request $request, NodeTranslation $nodeTranslation, TranslatorInterface $translator)
public function handlePublish(Request $request, NodeTranslation $nodeTranslation)
{
/** @var Session $session */
$session = $request->getSession();
Expand All @@ -275,18 +289,20 @@ public function chooseHowToPublish(Request $request, NodeTranslation $nodeTransl
$this->publishLater($nodeTranslation, $date);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$translator->trans('kuma_node.admin.publish.flash.success_scheduled')
);
} else {
$this->publish($nodeTranslation);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$translator->trans('kuma_node.admin.publish.flash.success_published')
$this->translator->trans('kuma_node.admin.publish.flash.success_scheduled')
);

return;
}

$this->publish($nodeTranslation);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$this->translator->trans('kuma_node.admin.publish.flash.success_published')
);
}

public function chooseHowToUnpublish(Request $request, NodeTranslation $nodeTranslation, TranslatorInterface $translator)
public function handleUnpublish(Request $request, NodeTranslation $nodeTranslation)
{
/** @var Session $session */
$session = $request->getSession();
Expand All @@ -296,15 +312,37 @@ public function chooseHowToUnpublish(Request $request, NodeTranslation $nodeTran
$this->unPublishLater($nodeTranslation, $date);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$translator->trans('kuma_node.admin.unpublish.flash.success_scheduled')
);
} else {
$this->unPublish($nodeTranslation);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$translator->trans('kuma_node.admin.unpublish.flash.success_unpublished')
$this->translator->trans('kuma_node.admin.unpublish.flash.success_scheduled')
);

return;
}

$this->unPublish($nodeTranslation);
$session->getFlashBag()->add(
FlashTypes::SUCCESS,
$this->translator->trans('kuma_node.admin.unpublish.flash.success_unpublished')
);
}

/**
* @deprecated since KunstmaanNodeBundle 5.9 and will be removed in KunstmaanNodeBundle 6.0. Use `handlePublish` instead.
*/
public function chooseHowToPublish(Request $request, NodeTranslation $nodeTranslation, TranslatorInterface $translator)
{
@trigger_error(sprintf('The "%s" method is deprecated since KunstmaanNodeBundle 5.9 and will be removed in KunstmaanNodeBundle 6.0. Use `handlePublish` instead.', __METHOD__), E_USER_DEPRECATED);

$this->handlePublish($request, $nodeTranslation);
}

/**
* @deprecated since KunstmaanNodeBundle 5.9 and will be removed in KunstmaanNodeBundle 6.0. Use `handleUnpublish` instead.
*/
public function chooseHowToUnpublish(Request $request, NodeTranslation $nodeTranslation, TranslatorInterface $translator)
{
@trigger_error(sprintf('The "%s" method is deprecated since KunstmaanNodeBundle 5.9 and will be removed in KunstmaanNodeBundle 6.0. Use `handleUnpublish` instead.', __METHOD__), E_USER_DEPRECATED);

$this->handleUnpublish($request, $nodeTranslation);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Kunstmaan/NodeBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ services:
- '@security.authorization_checker'
- '@event_dispatcher'
- '@kunstmaan_admin.clone.helper'
- '@translator'

kunstmaan_node.admin_node.node_version_lock_helper:
class: Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeVersionLockHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

final class ImportTranslationsFromFileCommand extends Command
{
/** @var Importer */
private $importer;

/** @var TranslatorInterface */
/** @var TranslatorInterface|LegacyTranslatorInterface */
private $translator;

/** @var array */
private $locales;

/**
* @param Translator $translator
* @param array $locales
* @param Translator|LegacyTranslatorInterface $translator
* @param array $locales
*/
public function __construct(Importer $importer, TranslatorInterface $translator, $locales)
public function __construct(Importer $importer, /*TranslatorInterface*/ $translator, $locales)
{
if (null !== $translator && (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface)) {
throw new \InvalidArgumentException(sprintf('Argument 2 passed to "%s" must be of the type "%s" or "%s", "%s" given', __METHOD__, LegacyTranslatorInterface::class, TranslatorInterface::class, get_class($translator)));
}

parent::__construct();
$this->importer = $importer;
$this->translator = $translator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function addDatabaseResources()
*/
public function warmUp($cacheDir)
{
return [];
}

/**
Expand Down

0 comments on commit 97a0928

Please sign in to comment.