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

urlAliasGenerator::generate issues in console command / cli

    XMLWordPrintable

Details

    Description

      Problem:

      When generating a siteaccess url from a command (see bellow), urlAliasGenerator::generate() requires that the 'siteaccess' parameter is passed, otherwise the current SA is ignored and the function returns an invalid/incorrect link ( 'http://localhost/' )

      $ php ezpublish/console test:url --siteaccess=fre --verbose
      Siteaccess url: http://localhost/
      

      In addition, when given the 'siteaccess' parameter, urlAliasGenerator will try to take the siteaccess into account but will fail with a notice in SiteAccess/Router:

      [Symfony\Component\Debug\Exception\ContextErrorException]
      Notice: Trying to get property of non-object

      Exception trace:
      () at /var/www/ezp54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/SiteAccess/Router.php:220
      Symfony\Component\Debug\ErrorHandler->handleError() at /var/www/ezp54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/SiteAccess/Router.php:220
      eZ\Publish\Core\MVC\Symfony\SiteAccess\Router->matchByName() at /var/www/ezp54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/Routing/Generator.php:91

      In order for urlAliasGenerator to work properly a cli command, it is necessary to set the current siteaccess both in the router and as a parameter to the generate function,
      which is unexpected and should not be necessary.

          protected function execute(InputInterface $input, OutputInterface $output)
          {
              $this->siteaccess = $this->getContainer()->get('ezpublish.siteaccess');
      
              // we are required to set the current siteaccess in router (5.x)
              $this->getContainer()->get('ezpublish.siteaccess_router')->setSiteAccess( $this->siteaccess );
      
              // load root ('/') location
              $this->repository = $this->getContainer()->get('ezpublish.api.repository');
              $this->locationService = $this->repository->getLocationService();
              $location = $this->locationService->loadLocation(2);
      
              $this->urlAliasGenerator = $this->getContainer()->get('ezpublish.urlalias_generator');
      
              // generate url for the location. current siteaccess is again required
              $url = $this->urlAliasGenerator->generate( $location, array( 'siteaccess' => $this->siteaccess->name ), true );
      
              $output->writeln( "Siteaccess url: $url");
          }
      

      The above outputs "Siteaccess url: http://ezp54.server.local/fr/"

      For the purpose of the test, the following matching config was used:

              match:
                  Compound\LogicalAnd:
                      -
                          matchers:
                              Map\URI:
                                  fr: true
                              Map\Host:
                                  'ezp54.server.local': true
                          match: fre
                  Map\Host:
                      'ezp54.server.local': eng
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            joao.inacio-obsolete@ez.no Joao Inacio (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: