Skip to content

Commit

Permalink
fix tree-items
Browse files Browse the repository at this point in the history
  • Loading branch information
labudzinski committed Nov 28, 2023
1 parent af4da9d commit 4fb0bb2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/Controller/ElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
use CIHub\Bundle\SimpleRESTAdapterBundle\Helper\AssetHelper;
use CIHub\Bundle\SimpleRESTAdapterBundle\Messenger\UpdateIndexElementMessage;
use CIHub\Bundle\SimpleRESTAdapterBundle\Provider\AssetProvider;
use CIHub\Bundle\SimpleRESTAdapterBundle\Provider\Traits\HasBaseAssetProvider;
use CIHub\Bundle\SimpleRESTAdapterBundle\Reader\ConfigReader;
use CIHub\Bundle\SimpleRESTAdapterBundle\Traits\RestHelperTrait;
use Exception;
use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Attributes as OA;
use Pimcore\Model\Asset;
Expand All @@ -27,25 +25,22 @@
use Pimcore\Model\Element\AbstractElement;
use Pimcore\Model\Element\Service;
use Pimcore\Model\Element\Tag;
use Pimcore\Model\Version;
use Pimcore\Model\Version\Listing;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route;
use function array_key_exists;

#[Route(path: ['/datahub/rest/{config}/element', '/pimcore-datahub-webservices/simplerest/{config}'], name: 'datahub_rest_endpoints_element_')]
#[Security(name: 'Bearer')]
#[OA\Tag(name: 'Element')]
final class ElementController extends BaseEndpointController
{
use RestHelperTrait;
use HasBaseAssetProvider;

/**
* @throws Exception
* @throws \Exception
*/
#[Route('', name: 'get', methods: ['GET'])]
#[OA\Get(
Expand Down Expand Up @@ -425,7 +420,7 @@ public function getElementVersion(): Response
}

/**
* @throws Exception
* @throws \Exception
*/
#[Route('/versions', name: 'versions', methods: ['GET'])]
#[OA\Get(
Expand Down Expand Up @@ -593,16 +588,16 @@ public function getVersions(): Response
}

$version['scheduled'] = null;
if (array_key_exists($version['id'], $schedules)) {
if (\array_key_exists($version['id'], $schedules)) {
$version['scheduled'] = $schedules[$version['id']];
}

$version = $this->getAssetMetaData($element, $version, $configReader);
}

return $this->json([
'total_count' => count($versions),
'items' => $versions
'total_count' => \count($versions),
'items' => $versions,
]);
} else {
throw $this->createAccessDeniedException('Permission denied, '.$type.' id ['.$element->getId().']');
Expand Down Expand Up @@ -800,20 +795,17 @@ public function unlock(AssetHelper $assetHelper, MessageBusInterface $messageBus

/**
* @param mixed $element
* @param $result
* @param ConfigReader $configReader
* @return array
*
* @throws Exception
* @throws \Exception
*/
private function getAssetMetaData(AbstractElement $element, $result, ConfigReader $configReader): array
{
if ($element instanceof Asset && !$element instanceof Asset\Folder) {
$result = array_merge($result, [
'mimeType' => $element->getMimeType(),
'fileSize' => $element->getFileSize(),
'binaryData' => $this->getBinaryDataValues($element, $configReader),
'metaData' => $this->getMetaDataValues($element),
'binaryData' => $this->getAssetProvider()->getBinaryDataValues($element, $configReader),
'metaData' => $this->getAssetProvider()->getMetaDataValues($element),
]);
}
if ($element instanceof Image) {
Expand Down

0 comments on commit 4fb0bb2

Please sign in to comment.