Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-30405

Cache pool isn't cleared after changing user email via PHP API when cache for email already exists

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 2.5.0, 2.4.2
    • Fix Version/s: Customer request, 2.5.1
    • Component/s: Caching
    • Labels:
      None

      Description

      When enable_email_authentication option is enabled changing the e-mail using PHP API isn't propagated as redis cache isn't cleared.

      Steps to reproduce:
      1. Install EzCoreExtraBundle https://github.com/lolautruche/EzCoreExtraBundle#installation
      2. In ezplatform.yml add the following configuration:

      ezplatform.yml
      ez_core_extra:
          system:
              site_group:
                  enable_email_authentication: true
      

      3. Configure Redis as a persistence cache adapter.
      4. Create a new SiteAccess e.g. pol and add it to site group.
      5. Login to this SiteAccess using administrator account (e-mail and password): everything should work fine.
      7. Use UpdateEmailCommand command by running:

      php bin/console app:change-email
      UpdateEmailCommand.php
      <?php
      /**
       * @copyright Copyright (C) eZ Systems AS. All rights reserved.
       * @license For full copyright and license information view LICENSE file distributed with this source code.
       */
      
      namespace AppBundle\Command;
      
      use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
      use Symfony\Component\Console\Input\InputInterface;
      use Symfony\Component\Console\Input\InputOption;
      use Symfony\Component\Console\Output\OutputInterface;
      
      class UpdateEmailCommand extends ContainerAwareCommand
      {
          protected function configure()
          {
              $this->setName('app:change-email')->setDescription('Change an email of selected user');
          }
      
          protected function execute(InputInterface $input, OutputInterface $output)
          {
              try {
                  $userId = 14;
                  $newEmail = 'test@ez.no';
                  /** @var \eZ\Publish\API\Repository\Repository $repository */
                  $repository = $this->getContainer()->get('ezpublish.api.repository');
                  $userService = $repository->getUserService();
      
                  $userUpdateStruct = $userService->newUserUpdateStruct();
                  $userUpdateStruct->email = $newEmail;
      
                  $repository->sudo(function ($repository) use ($userService, $userId, $userUpdateStruct) {
                      $user = $userService->loadUser($userId);
                      $userService->updateUser($user, $userUpdateStruct);
                  });
      
                  $output->writeln(sprintf('<info>Email for user ID %d changed successfully.</info>', $userId));
      
              } catch (\Exception $e) {
                  $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
              }
          }
      
      }
      

      8. Try to log in to the same SiteAccess using changed e-mail: 'test@ez.no'.

      Result:
      User is unable to log in.

      To be able to log in redis cache needs to be cleared:

      php bin/console cache:pool:clear cache.redis

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              konrad.oboza@ez.no Konrad Oboza
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: