Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
"ext-simplexml": "*",
"api-platform/core": "^4.2",
"cocur/slugify": "^4.1",
"doctrine/annotations": "^1.7.0",
"doctrine/dbal": "^3.4",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.9",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^3.2",
"doctrine/doctrine-migrations-bundle": "^3.7",
"doctrine/orm": "^3.6",
"imagine/imagine": "^1.3",
"lcobucci/clock": "^2.0|^3.0",
"lexik/jwt-authentication-bundle": "^3.1",
Expand All @@ -40,7 +39,7 @@
"phpdocumentor/reflection-docblock": "^5.3",
"ramsey/collection": "^1.2",
"ramsey/uuid": "^4.5",
"ramsey/uuid-doctrine": "^1.6",
"ramsey/uuid-doctrine": "^2.1",
"symfony/asset": "^7.2",
"symfony/console": "^7.2",
"symfony/doctrine-bridge": "^7.2",
Expand All @@ -56,6 +55,7 @@
"symfony/twig-bundle": "^7.4",
"symfony/type-info": "^7.4",
"symfony/validator": "^7.4",
"symfony/var-exporter": "^8",
"twig/cssinliner-extra": "^3.0.3",
"twig/extra-bundle": "^3.0.3",
"twig/inky-extra": "^3.0.3",
Expand All @@ -65,8 +65,7 @@
"behat/behat": "^3.13",
"behat/mink": "*",
"behatch/contexts": "dev-master",
"doctrine/common": "^3.1",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"doctrine/doctrine-fixtures-bundle": "^4.3",
"friends-of-behat/mink-browserkit-driver": "^1.6",
"friends-of-behat/mink-extension": "^2.7",
"friends-of-behat/symfony-extension": "^2.4",
Expand All @@ -87,7 +86,6 @@
"roave/security-advisories": "dev-master",
"symfony/browser-kit": "^7.4",
"symfony/css-selector": "^7.4",
"symfony/debug": "^4",
"symfony/dotenv": "^7.4",
"symfony/http-client": "^7.4",
"symfony/maker-bundle": "^1.0",
Expand Down Expand Up @@ -140,7 +138,6 @@
"symfony/serializer": "<=6.1.2",
"symfony/var-exporter": "<6.1",
"symfony/web-link": "<=6.0",
"doctrine/collections": "<1.7",
"doctrine/orm": "<2.13"
"doctrine/collections": "<1.7"
}
}
4 changes: 2 additions & 2 deletions features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ public function iHaveARefreshToken(string $expiresAt = '+10 seconds'): void
$refreshToken = new RefreshToken();
$refreshToken
->setUser($this->iriConverter->getResourceFromIri($this->restContext->resources['login_user']))
->setCreatedAt(new \DateTime())
->setExpiresAt(new \DateTime($expiresAt));
->setCreatedAt(new \DateTimeImmutable())
->setExpiresAt(new \DateTimeImmutable($expiresAt));
$this->manager->persist($refreshToken);
$this->manager->flush();
$this->restContext->resources['refresh_token'] = $refreshToken->getId();
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Extension/ORM/PublishableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function updateQueryBuilderForUnauthorizedUsers(QueryBuilder $queryBuild
$queryBuilder
->andWhere("$alias.$configuration->fieldName IS NOT NULL")
->andWhere("$alias.$configuration->fieldName <= :currentTime")
->setParameter('currentTime', new \DateTimeImmutable());
->setParameter('currentTime', new \DateTime());
}

private function getConfiguration(string $resourceClass): ?Publishable
Expand Down
16 changes: 12 additions & 4 deletions src/Doctrine/Extension/ORM/TablePrefixExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;

/**
Expand Down Expand Up @@ -61,10 +61,18 @@ private function setPrimaryTable(ClassMetadata $classMetadata): void
private function setJoinTableName(ClassMetadata $classMetadata): void
{
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
if (ClassMetadataInfo::MANY_TO_MANY === $mapping['type'] && $mapping['isOwningSide'] && !\array_key_exists('inherited', $mapping)) {
$mappedTableName = $mapping['joinTable']['name'];
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
if (!$mapping instanceof ManyToManyOwningSideMapping) {
continue;
}

if (null !== $mapping->inherited) {
continue;
}

$mapping->joinTable->name = $this->prefix . $mapping->joinTable->name;

// May not be needed, because $mapping is already the same object stored internally.
$classMetadata->associationMappings[$fieldName] = $mapping;
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/EventListener/Doctrine/PropagateUpdatesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs;
Expand All @@ -25,6 +24,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Doctrine\Persistence\Proxy;
use Silverback\ApiComponentsBundle\DataProvider\PageDataProvider;
use Silverback\ApiComponentsBundle\Entity\Component\Collection;
use Silverback\ApiComponentsBundle\Entity\Core\PageDataInterface;
Expand Down Expand Up @@ -121,7 +121,11 @@ private function gatherResourceAndAssociated(object $entity, string $type, Objec
$changeSet = $uow->getEntityChangeSet($entity);
$this->collectUpdatedResource($entity, $type);

$associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings();
$class = $entity instanceof Proxy
? get_parent_class($entity)
: $entity::class;

$associationMappings = $em->getClassMetadata($class)->getAssociationMappings();

if ($entity instanceof PageDataInterface) {
$this->pageDataPropertiesChanged = array_keys($changeSet);
Expand Down
12 changes: 8 additions & 4 deletions src/EventListener/Doctrine/PublishableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Silverback\ApiComponentsBundle\EventListener\Doctrine;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Silverback\ApiComponentsBundle\AttributeReader\PublishableAttributeReader;

Expand All @@ -30,7 +30,7 @@ public function __construct(PublishableAttributeReader $publishableStatusChecker

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
/** @var ClassMetadataInfo $metadata */
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
if (!$this->publishableStatusChecker->isConfigured($metadata->getName())) {
return;
Expand All @@ -55,14 +55,18 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
}

if (!$metadata->hasAssociation($configuration->associationName)) {
$referencedColumnName = $namingStrategy->referenceColumnName();
$metadata->mapOneToOne(
[
'fieldName' => $configuration->associationName,
'targetEntity' => $metadata->getName(),
'joinColumns' => [
[
'name' => $namingStrategy->joinKeyColumnName($metadata->getName()),
'referencedColumnName' => $namingStrategy->referenceColumnName(),
'name' => $namingStrategy->joinKeyColumnName(
$configuration->associationName,
$referencedColumnName
),
'referencedColumnName' => $referencedColumnName,
'onDelete' => 'SET NULL',
'nullable' => true,
],
Expand Down
5 changes: 2 additions & 3 deletions src/EventListener/Doctrine/TimestampedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Silverback\ApiComponentsBundle\EventListener\Doctrine;

use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Silverback\ApiComponentsBundle\AttributeReader\TimestampedAttributeReader;

Expand All @@ -29,14 +29,13 @@ public function __construct(TimestampedAttributeReader $annotationReader)

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
/** @var ClassMetadataInfo $metadata */
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
if (!$this->annotationReader->isConfigured($metadata->getName())) {
return;
}

$configuration = $this->annotationReader->getConfiguration($metadata->getName());

if (!$metadata->hasField($configuration->createdAtField)) {
$metadata->mapField(
[
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/Doctrine/UploadableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Silverback\ApiComponentsBundle\EventListener\Doctrine;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Silverback\ApiComponentsBundle\AttributeReader\UploadableAttributeReader;

Expand All @@ -30,7 +30,7 @@ public function __construct(UploadableAttributeReader $uploadableAnnotationReade

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
/** @var ClassMetadataInfo $metadata */
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
$className = $metadata->getName();
if (!$this->uploadableAnnotationReader->isConfigured($className)) {
Expand Down
1 change: 0 additions & 1 deletion src/Filter/OrSearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function __construct(
protected function getType(string $doctrineType): string
{
return match ($doctrineType) {
Types::ARRAY => 'array',
Types::JSON => 'json',
Types::BIGINT, Types::INTEGER, Types::SMALLINT => 'int',
Types::BOOLEAN => 'bool',
Expand Down
29 changes: 14 additions & 15 deletions src/Mercure/MercureResourcePublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ private function storeObjectToPublish(object $object, string $property): void

$id = $this->iriConverter->getIriFromResource($object);
$iri = $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_URL);
$objectData = ['id' => $id, 'iri' => $iri, 'mercureOptions' => $this->normalizeMercureOptions($options)];
$objectData = ['id' => $id, 'iri' => $iri, 'mercureOptions' => $this->normalizeMercureOptions($options, $object)];

if ('deletedObjects' === $property) {
$this->createdObjects->detach($object);
$this->updatedObjects->detach($object);
$this->createdObjects->offsetUnset($object);
$this->updatedObjects->offsetUnset($object);
$this->deletedObjects[$object] = $objectData;

return;
Expand Down Expand Up @@ -173,14 +173,14 @@ private function getObjectMercureOptions(object $object): ?array

foreach ($options as $key => $value) {
if (!isset(self::ALLOWED_KEYS[$key])) {
throw new InvalidArgumentException(\sprintf('The option "%s" set in the "mercure" attribute of the "%s" resource does not exist. Existing options: "%s"', $key, $resourceClass, implode('", "', self::ALLOWED_KEYS)));
throw new InvalidArgumentException(\sprintf('The option "%s" set in the "mercure" attribute of the "%s" resource does not exist. Existing options: "%s"', $key, $resourceClass, implode('", "', array_keys(self::ALLOWED_KEYS))));
}
}

return $options;
}

private function normalizeMercureOptions(array $options): array
private function normalizeMercureOptions(array $options, object $object): array
{
$options['enable_async_update'] ??= true;

Expand All @@ -192,11 +192,6 @@ private function normalizeMercureOptions(array $options): array
continue;
}

if (!str_starts_with($topic, '@=')) {
$topics[] = $topic;
continue;
}

if (null === $this->expressionLanguage) {
throw new \LogicException('The "@=" expression syntax cannot be used without the Expression Language component. Try running "composer require symfony/expression-language".');
}
Expand Down Expand Up @@ -229,7 +224,7 @@ public function propagate(): void
}
}

private function getObjectData(object $object, string $iri)
private function getObjectData(object $object, string $iri, array $options): string
{
$resourceClass = $this->getObjectClass($object);

Expand All @@ -250,7 +245,9 @@ private function getObjectData(object $object, string $iri)
private function publishUpdate(object $object, array $objectData, string $type): void
{
$options = $objectData['mercureOptions'];
$iri = $options['topics'] ?? $objectData['iri'];

$topicIri = $options['topics'] ?? $objectData['iri'];
$resourceIri = $objectData['iri'];

$getDeletedObjectData = static function () use ($objectData) {
return json_encode(['@id' => $objectData['id']], \JSON_THROW_ON_ERROR);
Expand All @@ -260,15 +257,17 @@ private function publishUpdate(object $object, array $objectData, string $type):
$data = $getDeletedObjectData();
} else {
try {
$data = $this->getObjectData($object, $iri);
$data = $this->getObjectData($object, $resourceIri, $options);
} catch (InvalidArgumentException|LegacyInvalidArgumentException) {
// the object may have been deleted at the database level with delete cascades...
$type = 'delete';
$data = $getDeletedObjectData();
}
}

$updates = array_merge([$this->buildUpdate($iri, $data, $options)], $this->getGraphQlSubscriptionUpdates($object, $options, $type));
$updates = array_merge(
[$this->buildUpdate($topicIri, $data, $options)],
$this->getGraphQlSubscriptionUpdates($object, $options, $type)
);

foreach ($updates as $update) {
if ($options['enable_async_update'] && $this->messageBus) {
Expand Down
6 changes: 3 additions & 3 deletions src/RefreshToken/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class RefreshToken
{
protected ?\DateTimeInterface $createdAt = null;
protected ?\DateTimeInterface $expiresAt = null;
protected ?\DateTimeImmutable $expiresAt = null;
protected ?UserInterface $user = null;
protected ?int $version = null;

Expand All @@ -38,15 +38,15 @@ public function setCreatedAt(\DateTimeInterface $createdAt)
return $this;
}

public function getExpiresAt(): ?\DateTimeInterface
public function getExpiresAt(): ?\DateTimeImmutable
{
return $this->expiresAt;
}

/**
* @return static
*/
public function setExpiresAt(\DateTimeInterface $expiresAt)
public function setExpiresAt(\DateTimeImmutable $expiresAt)
{
$this->expiresAt = $expiresAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass repository-class="Silverback\ApiComponentsBundle\Repository\Core\RefreshTokenRepository" name="Silverback\ApiComponentsBundle\Entity\Core\AbstractRefreshToken" table="refresh_token">
<field name="createdAt" column="created_at" type="datetime"/>
<field name="expiresAt" column="expired_at" type="datetime"/>
<field name="createdAt" column="created_at" type="datetime_immutable"/>
<field name="expiresAt" column="expired_at" type="datetime_immutable"/>
<field name="version" type="integer" version="true"/>
</mapped-superclass>
</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<many-to-many field="layouts" target-entity="Silverback\ApiComponentsBundle\Entity\Core\Layout" mapped-by="componentGroups" fetch="LAZY"/>
<many-to-many field="pages" target-entity="Silverback\ApiComponentsBundle\Entity\Core\Page" mapped-by="componentGroups" fetch="LAZY"/>
<many-to-many field="components" target-entity="Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent" mapped-by="componentGroups" fetch="LAZY"/>
<field name="allowedComponents" column="allowed_components" type="array" nullable="true"/>
<field name="allowedComponents" column="allowed_components" type="json" nullable="true"/>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</indexes>
<field name="username" length="255" column="username"/>
<field name="emailAddress" length="255" column="email_address"/>
<field name="roles" column="roles" type="array"/>
<field name="roles" column="roles" type="json"/>
<field name="enabled" column="enabled" type="boolean"/>
<field name="password" column="password" length="255"/>
<field name="newPasswordConfirmationToken" column="new_password_confirmation_token" nullable="true"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/Normalizer/ComponentPositionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Silverback\ApiComponentsBundle\Serializer\Normalizer;

use ApiPlatform\Metadata\IriConverterInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Silverback\ApiComponentsBundle\DataProvider\PageDataProvider;
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
Expand Down Expand Up @@ -135,7 +135,7 @@ private function normalizePublishableComponent(AbstractComponent $component)
if (!$em) {
throw new InvalidArgumentException(\sprintf('Could not find entity manager for class %s', $type));
}
/** @var ClassMetadataInfo $classMetadata */
/** @var ClassMetadata $classMetadata */
$classMetadata = $em->getClassMetadata($type);
$draft = $classMetadata->getFieldValue($component, $configuration->reverseAssociationName);

Expand Down
Loading
Loading