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

Public API: moveSubtree() not working for parentId 1

    XMLWordPrintable

Details

    Description

      We accidentally created the forms folder at parent Location 2 and want to move it to parent Location 1 via Public API

      $this->repo->sudo(
          function (Repository $repo) {
              $locSvc = $repo->getLocationService();
              $form = $locSvc->loadLocation(58);
              $parent = $locSvc->loadLocation(1);
              $repo->getLocationService()->moveSubtree($form, $parent);
          }
      ); 

      But then get an error

      Type error: Return value of eZ\Publish\Core\Repository\Values\Content\Conte  
        nt::getContentType() must be an instance of eZ\Publish\API\Repository\Value  
        s\ContentType\ContentType, null returned 

      This is because the special location 1 has no content (id 0) although it has a content-type 1 (folder).

      The check in vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/LocationService.php Line 675 is the cause, because it tries to fetch the content-type from the content instead of the location.

      if (!$newParentLocation->getContent()->getContentType()->isContainer) 

      Solution: Fetch the contentType via the contentTypeId attached to the location and then do the check.

      //Note from support:
      the same situation occurs for:

      • copySubtree
      • swapLocation
      • updating mainLocationId

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            9dcdb0dd-5caa-459b-93b0-1ce97332c3fa@accounts.ibexa.co Hannes Giesenow
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: