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

Overriding the built-In ViewController exhausts php memory limit

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: High High
    • Resolution: Obsolete
    • Affects Version/s: Pollux, 5.4.2
    • Fix Version/s: QA tracked issues
    • Component/s: Platform stack
    • Labels:

      Description

      If you create an override for the ViewController, following the documentation on https://doc.ez.no/display/EZP/How+to+use+a+custom+controller+to+display+a+content+or+location#Howtouseacustomcontrollertodisplayacontentorlocation-Overridingthebuilt-inViewController. You'll get the following exception in apache error log

      [Fri Jun 12 10:26:50 2015] [error] [client 10.0.5.1] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 130968 bytes) in vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php on line 24
      

        Activity

        Hide
        Pedro Resende (Inactive) added a comment -

        Test Bundle

        Show
        Pedro Resende (Inactive) added a comment - Test Bundle
        Hide
        Bertrand Dunogier added a comment - - edited

        You redefine `ez_content` to your own controller, and call `ez_content` from it. It calls itself, infinite loop.

        This doc chapter does document that you can override ez_content, but it doesn't say that you can _ and should _ re-use it within itself. I'd like to close that as invalid.

        Show
        Bertrand Dunogier added a comment - - edited You redefine `ez_content` to your own controller, and call `ez_content` from it. It calls itself, infinite loop. This doc chapter does document that you can override ez_content, but it doesn't say that you can _ and should _ re-use it within itself. I'd like to close that as invalid.
        Hide
        Pedro Resende (Inactive) added a comment - - edited

        Bertrand Dunogier: Given the documentation in https://doc.ez.no/display/EZP/How+to+use+a+custom+controller+to+display+a+content+or+location#Howtouseacustomcontrollertodisplayacontentorlocation-Overridingthebuilt-inViewController, how would you override viewLocation ? If you take a look at my override you'll notice that I'm trying to use a e-tag.
        If it isn't possible to override viewLocation with the description in the documentation, then I believe this is a documentation issue

        Show
        Pedro Resende (Inactive) added a comment - - edited Bertrand Dunogier : Given the documentation in https://doc.ez.no/display/EZP/How+to+use+a+custom+controller+to+display+a+content+or+location#Howtouseacustomcontrollertodisplayacontentorlocation-Overridingthebuilt-inViewController , how would you override viewLocation ? If you take a look at my override you'll notice that I'm trying to use a e-tag. If it isn't possible to override viewLocation with the description in the documentation, then I believe this is a documentation issue
        Hide
        Bertrand Dunogier added a comment - - edited

        That doc explains how to replace ez_content with your own controller, yes. That's by the way something we are going to change very soon, as it is not valid anymore in Platform 1.0.

        But it doesn't say anywhere that you can/should call $container->get('ez_content')->viewLocation().

        Maybe it could be documented better, but it does say Doing so will completely override the built-in ViewController! Use this at your own risk!. You've misused it, period. The way you did it doesn't work, but nowhere does it say it should.

        What you could do is make your controller override the built-in ViewController, and call the parent method:

        namespace Cleverti\OverrideViewControllerBundle\Controller;
         
        use eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController as BaseViewController;
         
        class ViewController extends ViewController 
        {
            public function viewLocation($locationId, $viewType, $layout = false, array $params = array())
            {
                $response = parent::viewLocation($locationId, $viewType, $layout = false, array $params = array())
                $response->setETag(md5($response->getContent()));
                $response->setPrivate();
         
                return $response;
            }
        }
        

        In any case, you can't just override a controller used all over the system like that. If you override it, then ALL of its methods must be reimplemented. As the warning says, it is an advanced method.

        Furthermore, as said before, this will be removed from the doc, as the whole things was refactored. I don't think it's worth spending time testing this.

        Show
        Bertrand Dunogier added a comment - - edited That doc explains how to replace ez_content with your own controller, yes. That's by the way something we are going to change very soon, as it is not valid anymore in Platform 1.0. But it doesn't say anywhere that you can/should call $container->get('ez_content')->viewLocation() . Maybe it could be documented better, but it does say Doing so will completely override the built-in ViewController! Use this at your own risk! . You've misused it, period. The way you did it doesn't work, but nowhere does it say it should. What you could do is make your controller override the built-in ViewController , and call the parent method: namespace Cleverti\OverrideViewControllerBundle\Controller;   use eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController as BaseViewController;   class ViewController extends ViewController { public function viewLocation($locationId, $viewType, $layout = false, array $params = array()) { $response = parent::viewLocation($locationId, $viewType, $layout = false, array $params = array()) $response->setETag(md5($response->getContent())); $response->setPrivate(); return $response; } } In any case, you can't just override a controller used all over the system like that. If you override it, then ALL of its methods must be reimplemented. As the warning says, it is an advanced method. Furthermore, as said before, this will be removed from the doc, as the whole things was refactored. I don't think it's worth spending time testing this.
        Hide
        Rui Silva (Inactive) added a comment -

        No QA needed.
        Closing this as is.

        Show
        Rui Silva (Inactive) added a comment - No QA needed. Closing this as is.

          People

          • Assignee:
            Unassigned
            Reporter:
            Pedro Resende (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: