Skip to content

Commit 27becd3

Browse files
committed
Use a separate attribute for versioned fields
1 parent b5a7717 commit 27becd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+164
-134
lines changed

doc/annotations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ use Gedmo\Mapping\Annotation as Gedmo;
527527
class Article {}
528528
```
529529

530-
#### `@Gedmo\Mapping\Annotation\Versioned`
530+
#### `@Gedmo\Mapping\Annotation\KeepRevisions`
531531

532-
The `Versioned` annotation is a property annotation used to identify properties whose changes should be logged.
532+
The `KeepRevisions` annotation is a property annotation used to identify properties whose changes should be logged.
533533
This annotation can be set for properties with a single value (i.e. a scalar type or an object such as
534-
`DateTimeInterface`), but not for collections. Versioned fields can be restored to an earlier version.
534+
`DateTimeInterface`), but not for collections. Fields with revisions can be restored to an earlier version.
535535

536536
Example:
537537

@@ -557,13 +557,13 @@ class Comment
557557

558558
/**
559559
* @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="comments")
560-
* @Gedmo\Versioned
560+
* @Gedmo\KeepRevisions
561561
*/
562562
public ?Article $article = null;
563563

564564
/**
565565
* @ORM\Column(type="string")
566-
* @Gedmo\Versioned
566+
* @Gedmo\KeepRevisions
567567
*/
568568
public ?string $body = null;
569569
}

doc/attributes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,11 @@ use Gedmo\Mapping\Annotation as Gedmo;
470470
class Article {}
471471
```
472472

473-
#### `#[Gedmo\Mapping\Annotation\Versioned]`
473+
#### `#[Gedmo\Mapping\Annotation\KeepRevisions]`
474474

475-
The `Versioned` attribute is a property attribute used to identify properties whose changes should be logged.
475+
The `KeepRevisions` attribute is a property attribute used to identify properties whose changes should be logged.
476476
This attribute can be set for properties with a single value (i.e. a scalar type or an object such as
477-
`DateTimeInterface`), but not for collections. Versioned fields can be restored to an earlier version.
477+
`DateTimeInterface`), but not for collections. Fields with revisions can be restored to an earlier version.
478478

479479
Example:
480480

@@ -496,11 +496,11 @@ class Comment
496496
public ?int $id = null;
497497

498498
#[ORM\ManyToOne(targetEntity: Article::class, inversedBy: 'comments')]
499-
#[Gedmo\Versioned]
499+
#[Gedmo\KeepRevisions]
500500
public ?Article $article = null;
501501

502502
#[ORM\Column(type: Types::STRING)]
503-
#[Gedmo\Versioned]
503+
#[Gedmo\KeepRevisions]
504504
public ?string $body = null;
505505
}
506506
```

doc/revisionable.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Article
114114
public bool $published = false;
115115

116116
#[ORM\Column(type: Types::STRING)]
117-
#[Gedmo\Versioned]
117+
#[Gedmo\KeepRevisions]
118118
public ?string $title = null;
119119
}
120120
```
@@ -134,7 +134,7 @@ class Article
134134
<field name="published" type="boolean"/>
135135

136136
<field name="title" type="string">
137-
<gedmo:versioned/>
137+
<gedmo:keep-revisions/>
138138
</field>
139139

140140
<gedmo:revisionable/>
@@ -174,7 +174,7 @@ class Article
174174

175175
/**
176176
* @ORM\Column(type="string")
177-
* @Gedmo\Versioned
177+
* @Gedmo\KeepRevisions
178178
*/
179179
public ?string $title = null;
180180
}

schemas/orm/doctrine-extensions-mapping-2-2.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<xs:element name="blameable" type="gedmo:blameable"/>
3939
<xs:element name="ip-traceable" type="gedmo:ip-traceable"/>
4040
<xs:element name="versioned" type="gedmo:emptyType"/>
41+
<xs:element name="keep-revisions" type="gedmo:emptyType"/>
4142
<xs:element name="tree-left" type="gedmo:emptyType"/>
4243
<xs:element name="tree-right" type="gedmo:emptyType"/>
4344
<xs:element name="tree-level" type="gedmo:emptyType"/>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Doctrine Behavioral Extensions package.
5+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace Gedmo\Mapping\Annotation;
11+
12+
use Doctrine\Common\Annotations\Annotation;
13+
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
14+
15+
/**
16+
* Versioned annotation for use with the Revisionable extension
17+
*
18+
* @Annotation
19+
*
20+
* @NamedArgumentConstructor
21+
*
22+
* @Target("PROPERTY")
23+
*
24+
* @author Gediminas Morkevicius <[email protected]>
25+
*/
26+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
27+
final class KeepRevisions implements GedmoAnnotation
28+
{
29+
}

src/Mapping/Annotation/Versioned.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
1414

1515
/**
16-
* Versioned annotation for use with the Loggable and Revisionable extensions
16+
* Versioned annotation for use with the Loggable extension
1717
*
1818
* @Annotation
1919
*

src/Revisionable/Mapping/Driver/Attribute.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata;
1414
use Doctrine\Persistence\Mapping\ClassMetadata;
1515
use Gedmo\Exception\InvalidMappingException;
16+
use Gedmo\Mapping\Annotation\KeepRevisions;
1617
use Gedmo\Mapping\Annotation\Revisionable;
17-
use Gedmo\Mapping\Annotation\Versioned;
1818
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
1919

2020
/**
@@ -60,7 +60,7 @@ public function readExtendedMetadata($meta, array &$config)
6060
foreach ($class->getProperties() as $property) {
6161
$field = $property->getName();
6262

63-
if ($this->reader->getPropertyAnnotation($property, Versioned::class)) {
63+
if ($this->reader->getPropertyAnnotation($property, KeepRevisions::class)) {
6464
if ($meta->isCollectionValuedAssociation($field)) {
6565
throw new InvalidMappingException(sprintf('Cannot version field %s::$%s, collection valued associations are not supported.', $meta->getName(), $field));
6666
}
@@ -103,7 +103,7 @@ public function readExtendedMetadata($meta, array &$config)
103103
if (!$meta->isMappedSuperclass && $config) {
104104
// The revisionable flag must be set, except for embedded models, and the versioned config should be a non-empty array
105105
if (isset($config['versionedFields']) && !isset($config['revisionable']) && !$this->isEmbed($meta)) {
106-
throw new InvalidMappingException(sprintf('Class "%s" has "%s" annotated fields but is missing the "%s" class annotation.', $meta->getName(), Versioned::class, Revisionable::class));
106+
throw new InvalidMappingException(sprintf('Class "%s" has "%s" annotated fields but is missing the "%s" class annotation.', $meta->getName(), KeepRevisions::class, Revisionable::class));
107107
}
108108
}
109109

@@ -121,7 +121,7 @@ public function readExtendedMetadata($meta, array &$config)
121121
private function inspectEmbeddedForVersioned(string $field, array $config, ORMClassMetadata $meta): array
122122
{
123123
foreach ((new \ReflectionClass($meta->embeddedClasses[$field]['class']))->getProperties() as $property) {
124-
if ($this->reader->getPropertyAnnotation($property, Versioned::class)) {
124+
if ($this->reader->getPropertyAnnotation($property, KeepRevisions::class)) {
125125
$embeddedField = $field.'.'.$property->getName();
126126

127127
if (isset($meta->embeddedClasses[$embeddedField])) {

src/Revisionable/Mapping/Driver/Xml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function readExtendedMetadata($meta, array &$config)
6868
if (!$meta->isMappedSuperclass && $config) {
6969
// The revisionable flag must be set, except for embedded models, and the versioned config should be a non-empty array
7070
if (isset($config['versionedFields']) && (!$this->isEmbed($meta) && !isset($config['revisionable']))) {
71-
throw new InvalidMappingException(sprintf("Class '%s' has fields with the 'gedmo:versioned' element but the class does not have the 'gedmo:revisionable' element.", $meta->getName()));
71+
throw new InvalidMappingException(sprintf("Class '%s' has fields with the 'gedmo:keep-revisions' element but the class does not have the 'gedmo:revisionable' element.", $meta->getName()));
7272
}
7373
}
7474

@@ -127,7 +127,7 @@ private function inspectElementForVersioned(\SimpleXMLElement $element, array $c
127127
foreach ($element as $mappingDoctrine) {
128128
$mapping = $mappingDoctrine->children(self::GEDMO_NAMESPACE_URI);
129129

130-
if (!isset($mapping->versioned)) {
130+
if (!isset($mapping->{'keep-revisions'})) {
131131
continue;
132132
}
133133

src/Revisionable/Mapping/Driver/Yaml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function readExtendedMetadata($meta, array &$config)
6767
if (!$meta->isMappedSuperclass && $config) {
6868
// The revisionable flag must be set, except for embedded models, and the versioned config should be a non-empty array
6969
if (isset($config['versionedFields']) && !isset($config['revisionable'])) {
70-
throw new InvalidMappingException(sprintf("Class '%s' has fields marked as versioned but the class does not have the 'revisionable' configuration.", $meta->getName()));
70+
throw new InvalidMappingException(sprintf("Class '%s' has fields marked with the 'keepRevisions' property but the class does not have the 'revisionable' configuration.", $meta->getName()));
7171
}
7272
}
7373

@@ -140,7 +140,7 @@ private function inspectConfigurationForVersioned(array $mapping, array $config,
140140
continue;
141141
}
142142

143-
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
143+
if (in_array('keepRevisions', $fieldMapping['gedmo'], true)) {
144144
if ($meta->isCollectionValuedAssociation($field)) {
145145
throw new InvalidMappingException(sprintf('Cannot version field %s::$%s, collection valued associations are not supported.', $meta->getName(), $field));
146146
}

tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.EmbeddedRevisionable.dcm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
33
<embeddable name="Gedmo\Tests\Mapping\Fixture\Xml\EmbeddedRevisionable">
44
<field name="subtitle" type="string" length="191">
5-
<gedmo:versioned/>
5+
<gedmo:keep-revisions/>
66
</field>
77
</embeddable>
88
</doctrine-mapping>

0 commit comments

Comments
 (0)