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

Wrong implementation of method buildView() in class ContentViewBuilder

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: High High
    • None
    • 1.8.1
    • None
    • ubuntu 16.04 MariaDB 10 php 5.6

    Description

      class eZ\Publish\Core\MVC\Symfony\View\Builder\ContentViewBuilder
      method: buildView
      wrong:

      ...
      if (isset($location)) {
                  if ($location->contentId !== $content->id) {
                      throw new InvalidArgumentException('Location', 'Provided location does not belong to selected content');
                  }
              } elseif (isset($this->locationLoader)) {
                  try {
                      $location = $this->locationLoader->loadLocation($content->contentInfo);
                  } catch (NotFoundException $e) {
                      // nothing else to do
                  }
              }
      ...
      

      my implementation:
      ...
      use eZ\Publish\Core\Base\Exceptions\NotFoundException as NotFoundException2;

      ...
      
      if (isset($location)) {
                  if ($location->contentId !== $content->id) {
                      throw new InvalidArgumentException('Location', 'Provided location does not belong to selected content');
                  }
              } else {
                  try {
                      //$this->locationLoader  - is useless there
                      //$location = $this->locationLoader->loadLocation($content->contentInfo);
                      $contentInfo = $content->contentInfo;
                      if ($contentInfo->mainLocationId > 0) {
      
                          $location = $this->getRepository()->sudo(
                              function (Repository $repository) use ($contentInfo) {
                                  return $repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
                              }
                          );
                      }
                      unset($contentInfo);
      
                  }
                  catch (NotFoundException2 $nfe)
                  {
                      // nothing else to do
                  }
                  catch(Exception $e)
                  {
                      throw $e;
                  }
              }
      ...
      

      Why my implementation, because i mute only Not Found Exceptions, yours all, to be sure open method and see implementation
      '$this->locationLoader->loadLocation()'
      it change any Exceptin to not found so builder gets only Not Found Exc but it is wrong, it is huge programmer mistake.
      And exceptions different than NotFoundExc are NOT logged so you don't know why you have some problem.

      And class attr $repository exist in builder class so why programmer inject next param to constructor?!

      Attachments

        Activity

          People

            Unassigned Unassigned
            radek.dev radek.dev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: