Sfoglia il codice sorgente

fix media object iri problem

master
Daniel 2 anni fa
parent
commit
b117770830
4 ha cambiato i file con 42 aggiunte e 9 eliminazioni
  1. +5
    -5
      config/services.yaml
  2. +2
    -2
      migrations/Version20240213115154.php
  3. +29
    -0
      src/Entity/MediaObject.php
  4. +6
    -2
      src/Serializer/MediaObjectNormalizer.php

+ 5
- 5
config/services.yaml Vedi File

@@ -29,8 +29,8 @@ services:
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }
arguments: ['@symfonycasts.micro_mapper', '@api_platform.iri_converter']

App\Serializer\MediaObjectNormalizer:
arguments:
$storage: '@vich_uploader.storage.file_system'
tags:
- { name: 'api_platform.jsonld.normalizer.item', priority: 1000 }
# App\Serializer\MediaObjectNormalizer:
# arguments:
# $storage: '@vich_uploader.storage.file_system'
# tags:
# - { name: 'api_platform.jsonld.normalizer.item', priority: 1000 }

migrations/Version20240207141851.php → migrations/Version20240213115154.php Vedi File

@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240207141851 extends AbstractMigration
final class Version20240213115154 extends AbstractMigration
{
public function getDescription(): string
{
@@ -21,7 +21,7 @@ final class Version20240207141851 extends AbstractMigration
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE contact (id INT AUTO_INCREMENT NOT NULL, partner_id INT NOT NULL, image_id INT DEFAULT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, birthday DATE DEFAULT NULL, position VARCHAR(255) DEFAULT NULL, phone VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_4C62E6389393F8FE (partner_id), INDEX IDX_4C62E6383DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE media_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE media_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE partner (id INT AUTO_INCREMENT NOT NULL, logo_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, street_no VARCHAR(255) DEFAULT NULL, zip VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_312B3E16F98F144A (logo_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE posting (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BD275D737E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');

+ 29
- 0
src/Entity/MediaObject.php Vedi File

@@ -68,8 +68,37 @@ class MediaObject
#[ORM\Column(nullable: true)]
public ?string $filePath = null;

#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;

public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}

public function getId(): ?int
{
return $this->id;
}

public function getContentUrl(): ?string
{
return $this->contentUrl;
}

public function getFile(): ?File
{
return $this->file;
}

public function getFilePath(): ?string
{
return $this->filePath;
}

public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}

}

+ 6
- 2
src/Serializer/MediaObjectNormalizer.php Vedi File

@@ -15,6 +15,7 @@ use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Vich\UploaderBundle\Storage\StorageInterface;

//final class MediaObjectNormalizer
#[AsDecorator('api_platform.jsonld.normalizer.item')]
final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwareInterface
{
@@ -31,7 +32,10 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar
{
$context[self::ALREADY_CALLED] = true;

$object->contentUrl = $this->storage->resolveUri($object, 'file');
if ($object instanceof MediaObject) {
// Nur für MediaObject die URI generieren
$object->contentUrl = $this->storage->resolveUri($object, 'file');
}

return $this->normalizer->normalize($object, $format, $context);
}
@@ -42,7 +46,7 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar
return false;
}

return $data instanceof MediaObject;
return $this->normalizer->supportsNormalization($data, $format, $context);
}

public function setSerializer(SerializerInterface $serializer): void


Caricamento…
Annulla
Salva