Closed the-juju closed 5 months ago
Hello @the-juju, I'd love to be able to reproduce it. Could you give us a reduced Doctrine entity code which reproduces the issue ?
Also, we are going to release a new 1.2.0 in a near future (ie. a few days) I'd love to know if that's still an issue.
Hello @pounard sure i'll add them in attachment to this message ! Also, we're using API Platform on version 3.2
ProjectComponent.php (parent)
<?php
namespace App\Entity;
use App\Config\ProjectConfig;
use App\Repository\ProjectComponentRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: ProjectComponentRepository::class)]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap([
'title' => ProjectComponentTitle::class,
'text' => ProjectComponentText::class,
'image' => ProjectComponentImage::class,
'video' => ProjectComponentVideo::class,
'audio' => ProjectComponentAudio::class,
])]
#[ORM\Index(columns: ['type'], name: 'idx_publication_type')]
class ProjectComponent
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: UuidType::NAME, nullable: true)]
private ?Uuid $uuid = null;
#[ORM\ManyToOne(inversedBy: 'components')]
#[ORM\JoinColumn(nullable: false)]
private ?Project $project = null;
#[ORM\Column]
private ?int $position = null;
#[Groups([
ProjectConfig::UPDATE,
ProjectConfig::READ,
ProjectConfig::PUBLIC_READ,
])]
private ?string $type = null;
public function __construct()
{
$this->uuid = Uuid::v7();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?Uuid
{
return $this->uuid;
}
public function setUuid(Uuid $uuid): static
{
$this->uuid = $uuid;
return $this;
}
public function getProject(): ?Project
{
return $this->project;
}
public function setProject(?Project $project): static
{
$this->project = $project;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): static
{
$this->position = $position;
return $this;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
}
ProjectComponentImage.php
<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Config\ProjectConfig;
use App\Contracts\ProjectComponentInterface;
use App\Contracts\ProjectMediaComponentInterface;
use App\Enum\ComponentType;
use App\Repository\BlockImageRepository;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Override;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: BlockImageRepository::class)]
#[ORM\Table(name: 'component_image')]
#[ApiResource]
class ProjectComponentImage extends ProjectComponent implements ProjectComponentInterface, ProjectMediaComponentInterface
{
#[ORM\Column(length: 255, nullable: true)]
#[Groups([
ProjectConfig::UPDATE,
ProjectConfig::READ,
ProjectConfig::PUBLIC_READ,
])]
private ?string $url = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups([
ProjectConfig::UPDATE,
ProjectConfig::READ,
ProjectConfig::PUBLIC_READ,
])]
private ?string $thumbnail_url = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups([
ProjectConfig::UPDATE,
ProjectConfig::READ,
ProjectConfig::PUBLIC_READ,
])]
private ?string $mime_type = null;
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): static
{
$this->url = $url;
return $this;
}
public function getThumbnailUrl(): ?string
{
return $this->thumbnail_url;
}
public function setThumbnailUrl(?string $thumbnail_url): static
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
public function getMimeType(): ?string
{
return $this->mime_type;
}
public function setMimeType(?string $mime_type): static
{
$this->mime_type = $mime_type;
return $this;
}
#[Override]
public function fill(array $data): ProjectComponentInterface
{
$this->setUrl($data['url']);
$this->setThumbnailUrl($data['thumbnail_url']);
$this->setMimeType($data['mime_type']);
return $this;
}
/**
* @throws Exception
*/
#[Override]
public function getType(): string
{
return ComponentType::getValue(ComponentType::IMAGE);
}
#[Override]
public function getMainUrl(): ?string
{
return $this->url;
}
#[Override]
public function getSecondaryUrl(): ?string
{
return $this->thumbnail_url;
}
}
OK so @SimonMellerin's intuition was right, it's due to inheritance. I'll try to reproduce today, if I can fix it easily it will be in the next 1.2.0 release.
To be honest, we didn't test every inheritance use cases yet, I guess it's the right time to start.
@the-juju in the meantime, if you really need it, you can still bypass entity anonymization and use YAML configuration for directly anonymizing the database columns.
No emergency on my side. I've just read an article about your bundle, and i wanted to give it a try. I'll try to dig deeper in the config to see if I can even "skip" anonymization for that tables (not needed as I wanted to anonymize users related tables)
Keep up the good work @pounard @SimonMellerin 🤜💥🤛
So far, i'm not finding any related issue or documentation. I will try to have a look directly in the code.
That's one documentation witness, as we didn't have fully implemented all kinds of doctrine inheritance support, we didn't have documented yet either. We're going to fix that!
Should be fixed in there https://github.com/makinacorpus/DbToolsBundle/pull/164 - ready for next release!
Wonderful! Looking forward to try the next release
@the-juju Feel free to test the new release: https://github.com/makinacorpus/DbToolsBundle/releases/tag/1.2.0
I confirm that everything went well with 1.2.0 Good job @pounard and thanks !
PHP's version : 8.3 Symfony's version : 6.4 Bundle's version : 1.1.0
Hello there, I'm facing an issue while trying to anonymize my local database. I have an inheritance between classes. My child classes do not have $id attribute and when I'm trying to run the following command :
php bin/console db-tools:anonymize --local-database
I'm getting the error mentionned in title :
So far, i'm not finding any related issue or documentation. I will try to have a look directly in the code. Do you have any idea on the cause? Or is it just insupported?
Thanks, Julien