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

Preview issue when relying on locations for unpublished content

    Details

      Description

      There appears to be a regression in the eZ Publish 5.2 version of the patch from issue https://jira.ez.no/browse/EZP-22781, that occurs in the conditions described below.

      Steps to reproduce:

      1. Prepare an eZ Publish 5.2 installation, fully patched;
      2. Install eZ Publish 5.2 patch from https://jira.ez.no/browse/EZP-22781;
      3. Preview the first draft of a page that is being served by a new stack full view template with an Image attribute. If the page is published preview doesn't crash. The problem appears to be happening if you have a custom controller that is trying to access the location ID. In the example below, it is the line that is trying loadLocation() that is failing:

      public function webinarEnterpriseAction( $locationId, $viewType, $layout = false, array $params = array() ) {
      	$params += array();
       
      	$repository = $this->getRepository();
      	$location = $repository->getLocationService()->loadLocation( $locationId );
      	$content = $repository->getContentService()->loadContentByContentInfo( $location->contentInfo );
       
      	$params['tz_dates'] = $this->globalWebinarDates( $content );
       
      	// Forward the request to the Default Controller
      	$response = $this->get( 'ez_content' )->viewLocation( $locationId, $viewType, $layout, $params );
       
      	return $response;
      }
      

      In the customer's case, it happens that their site has an Image attribute on that content class. Therefore, to test you just have to create a custom controller and try to access the location ID. It will always crash on a first draft:

       
       
      Full stack trace is below. Is there a follow-up patch that needs to be applied as well?
       
      [1] eZPublishCoreBaseExceptionsNotFoundException: Could not find 'location' with identifier
      at n/a
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/EzcDatabase.php line 79
       
      at eZPublishCorePersistenceLegacyContentLocationGatewayEzcDatabase->getBasicNodeData(null)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php line 56
       
      at eZPublishCorePersistenceLegacyContentLocationGatewayExceptionConversion->getBasicNodeData(null)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Content/Location/Handler.php line 100
       
      at eZPublishCorePersistenceLegacyContentLocationHandler->load(null)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Persistence/Cache/LocationHandler.php line 32
       
      at eZPublishCorePersistenceCacheLocationHandler->load(null)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/LocationService.php line 205
       
      at eZPublishCoreRepositoryLocationService->loadLocation(null)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/SignalSlot/LocationService.php line 102
       
      at eZPublishCoreSignalSlotLocationService->loadLocation(null)
      in /var/www/src/Hootsuite/BaseBundle/Controller/WebinarsController.php line 925
       
      at HootsuiteBaseBundleControllerWebinarsController->webinarEnterpriseAction(null, 'full', true, array('content' => object(Content), 'location' => object(Location), 'isPreview' => true))
      in line
       
      at call_user_func_array(array(object(WebinarsController), 'webinarEnterpriseAction'), array(null, 'full', true, array('content' => object(Content), 'location' => object(Location), 'isPreview' => true)))
      in /var/www/ezpublish/bootstrap.php.cache line 2889
       
      at SymfonyComponentHttpKernelHttpKernel->handleRaw(object(Request), '2')
      in /var/www/ezpublish/bootstrap.php.cache line 2863
       
      at SymfonyComponentHttpKernelHttpKernel->handle(object(Request), '2', true)
      in /var/www/ezpublish/bootstrap.php.cache line 2992
       
      at SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(object(Request), '2')
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/Controller/Content/PreviewController.php line 89
       
      at eZPublishCoreMVCSymfonyControllerContentPreviewController->previewContentAction('3461', '1', 'eng-US', 'eng')
      in line
       
      at call_user_func_array(array(object(PreviewController), 'previewContentAction'), array('3461', '1', 'eng-US', 'eng'))
      in /var/www/ezpublish/bootstrap.php.cache line 2889
       
      at SymfonyComponentHttpKernelHttpKernel->handleRaw(object(Request), '1')
      in /var/www/ezpublish/bootstrap.php.cache line 2863
       
      at SymfonyComponentHttpKernelHttpKernel->handle(object(Request), '1', true)
      in /var/www/ezpublish/bootstrap.php.cache line 2992
       
      at SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(object(Request), '1', true)
      in /var/www/ezpublish/bootstrap.php.cache line 2272
       
      at SymfonyComponentHttpKernelKernel->handle(object(Request), '1', true)
      in /var/www/vendor/ezsystems/ezpublish-kernel/eZ/Bundle/EzPublishCoreBundle/Kernel.php line 62
       
      at eZBundleEzPublishCoreBundleKernel->handle(object(Request))
      in /var/www/web/index.php line 64
      

        Issue Links

          Activity

          Hide
          Bertrand Dunogier added a comment - - edited

          When you say you can preview using viewLocation, what do you mean exactly ?

          The PreviewController will use whatever override rules are defined, and will use either the LocationView or the ContentView controller depending on those rules. When the LocationView controller is used, it can NOT work as expected in any of the stable versions when previewing the first version of a content:

          • either we preview the wrong node id (5.3, 5.4)
          • either we get a fatal error because it is set to null.

          Furthermore, a ContentView controller or template may expect the location to be here, and use it as an argument, to sub-requests or functions. It is done like this in the Article and Blog post templates (and controller for blog post).

          There might be something I've missed, but I'd say I'm pretty close to the bottom of the pit.

          Show
          Bertrand Dunogier added a comment - - edited When you say you can preview using viewLocation, what do you mean exactly ? The PreviewController will use whatever override rules are defined, and will use either the LocationView or the ContentView controller depending on those rules. When the LocationView controller is used, it can NOT work as expected in any of the stable versions when previewing the first version of a content: either we preview the wrong node id (5.3, 5.4) either we get a fatal error because it is set to null. Furthermore, a ContentView controller or template may expect the location to be here, and use it as an argument, to sub-requests or functions. It is done like this in the Article and Blog post templates (and controller for blog post). There might be something I've missed, but I'd say I'm pretty close to the bottom of the pit.
          Hide
          Ricardo Correia (Inactive) added a comment - - edited

          Hi Bertrand,
          I haven't tested using blog posts. I used content classes similar to the article class, and another one with a text line and an image attribute.
          To test viewLocation I injected a call to a custom controller, and the controller will return the content based on the location. This works if I provide the location ID of an already existing content.
          What content ID should I use? The ID of an existing content, or the ID of the content I'm creating (which has a single version still in draft).
          AFAIK content that hasn't been published yet doesn't have a location ID yet, correct?

          Is not this the right direction?
          Am I missing something here?

          BTW, I'm testing using version 5.2 fully patched.

          Show
          Ricardo Correia (Inactive) added a comment - - edited Hi Bertrand, I haven't tested using blog posts. I used content classes similar to the article class, and another one with a text line and an image attribute. To test viewLocation I injected a call to a custom controller, and the controller will return the content based on the location. This works if I provide the location ID of an already existing content. What content ID should I use? The ID of an existing content, or the ID of the content I'm creating (which has a single version still in draft). AFAIK content that hasn't been published yet doesn't have a location ID yet, correct? Is not this the right direction? Am I missing something here? BTW, I'm testing using version 5.2 fully patched.
          Hide
          Peter Keung added a comment -

          "I'm thinking that maybe a context variable, passed to all content templates, and set to 'preview', might make sense. Don't you think so ? We could alter the layout for preview only, so that rendering makes sense from the perspective of an editor previewing content."

          Perhaps that is possible, but the bigger problem is that you currently have to go through the Location ID to get at anything from the Content, such as its fields, in a custom view controller. So skipping the lookup of the fields is too big of a break.

          Also, I think in practice, you will end up wrapping all your uses of the Location in "if" statements checking whether the context is preview. Having the context would be nice to have for some cases, such as putting some placeholder text for an ad for example. BUT from a dev UX standpoint, having to check for the "preview" context when using the Location in some way is not very nice. It would be better if any uses of the Location just silently failed.

          Show
          Peter Keung added a comment - "I'm thinking that maybe a context variable, passed to all content templates, and set to 'preview', might make sense. Don't you think so ? We could alter the layout for preview only, so that rendering makes sense from the perspective of an editor previewing content." Perhaps that is possible, but the bigger problem is that you currently have to go through the Location ID to get at anything from the Content, such as its fields, in a custom view controller. So skipping the lookup of the fields is too big of a break. Also, I think in practice, you will end up wrapping all your uses of the Location in "if" statements checking whether the context is preview. Having the context would be nice to have for some cases, such as putting some placeholder text for an ad for example. BUT from a dev UX standpoint, having to check for the "preview" context when using the Location in some way is not very nice. It would be better if any uses of the Location just silently failed.
          Hide
          Bertrand Dunogier added a comment -

          Perhaps that is possible, but the bigger problem is that you currently have to go through the Location ID to get at anything from the Content, such as its fields, in a custom view controller. So skipping the lookup of the fields is too big of a break.

          That is because you use the LocationView controller (location_view rule). If you use the ContentView controller, your main argument is the ContentId, not the LocationId.

          I've been through every content view rule in ezdemo.yml, and saw only two cases where the actual location was required (it was used in much more than that of course).

          But I'm still working on that.

          Show
          Bertrand Dunogier added a comment - Perhaps that is possible, but the bigger problem is that you currently have to go through the Location ID to get at anything from the Content, such as its fields, in a custom view controller. So skipping the lookup of the fields is too big of a break. That is because you use the LocationView controller (location_view rule). If you use the ContentView controller, your main argument is the ContentId, not the LocationId. I've been through every content view rule in ezdemo.yml, and saw only two cases where the actual location was required (it was used in much more than that of course). But I'm still working on that.
          Hide
          Ricardo Correia (Inactive) added a comment -

          QA approved.
          This fix solves the Could not find 'location' with identifier '' error.
          Another issue has been raised from this one: https://jira.ez.no/browse/EZP-23807

          Show
          Ricardo Correia (Inactive) added a comment - QA approved. This fix solves the Could not find 'location' with identifier '' error. Another issue has been raised from this one: https://jira.ez.no/browse/EZP-23807

            People

            • Assignee:
              Unassigned
              Reporter:
              Nuno Oliveira (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: