Skip to content

Commit efd429d

Browse files
authored
Merge pull request #10769 from greg0ire/cleanup-bc-layers
Remove Notify change tracking policy
2 parents 492635a + 716139c commit efd429d

20 files changed

+8
-907
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: The `NOTIFY` change tracking policy is removed
4+
5+
You should use `DEFERRED_EXPLICIT` instead.
6+
37
## BC BREAK: `Mapping\Driver\XmlDriver::__construct()` third argument is now a no-op
48

59
The third argument to

docs/en/cookbook/implementing-the-notify-changetracking-policy.rst

Lines changed: 0 additions & 75 deletions
This file was deleted.

docs/en/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ Cookbook
110110

111111
* **Implementation**:
112112
:doc:`Array Access <cookbook/implementing-arrayaccess-for-domain-objects>` |
113-
:doc:`Notify ChangeTracking Example <cookbook/implementing-the-notify-changetracking-policy>` |
114113
:doc:`Working with DateTime <cookbook/working-with-datetime>` |
115114
:doc:`Validation <cookbook/validation-of-entities>` |
116115
:doc:`Entities in the Session <cookbook/entities-in-session>` |

docs/en/reference/attributes-reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ Example:
311311
Entity,
312312
ChangeTrackingPolicy("DEFERRED_IMPLICIT"),
313313
ChangeTrackingPolicy("DEFERRED_EXPLICIT"),
314-
ChangeTrackingPolicy("NOTIFY")
315314
]
316315
class User {}
317316

docs/en/reference/change-tracking-policies.rst

Lines changed: 1 addition & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Change tracking is the process of determining what has changed in
55
managed entities since the last time they were synchronized with
66
the database.
77

8-
Doctrine provides 3 different change tracking policies, each having
8+
Doctrine provides 2 different change tracking policies, each having
99
its particular advantages and disadvantages. The change tracking
1010
policy can be defined on a per-class basis (or more precisely,
1111
per-hierarchy).
@@ -56,122 +56,3 @@ This policy can be configured as follows:
5656
{
5757
// ...
5858
}
59-
60-
Notify
61-
~~~~~~
62-
63-
.. note::
64-
65-
The notify change tracking policy is deprecated and will be removed in ORM 3.0.
66-
(`Details <https://github.com/doctrine/orm/issues/8383>`_)
67-
68-
This policy is based on the assumption that the entities notify
69-
interested listeners of changes to their properties. For that
70-
purpose, a class that wants to use this policy needs to implement
71-
the ``NotifyPropertyChanged`` interface from the Doctrine
72-
namespace. As a guideline, such an implementation can look as
73-
follows:
74-
75-
.. code-block:: php
76-
77-
<?php
78-
use Doctrine\Persistence\NotifyPropertyChanged,
79-
Doctrine\Persistence\PropertyChangedListener;
80-
81-
#[Entity]
82-
#[ChangeTrackingPolicy('NOTIFY')]
83-
class MyEntity implements NotifyPropertyChanged
84-
{
85-
// ...
86-
87-
private array $_listeners = array();
88-
89-
public function addPropertyChangedListener(PropertyChangedListener $listener): void
90-
{
91-
$this->_listeners[] = $listener;
92-
}
93-
}
94-
95-
Then, in each property setter of this class or derived classes, you
96-
need to notify all the ``PropertyChangedListener`` instances. As an
97-
example we add a convenience method on ``MyEntity`` that shows this
98-
behaviour:
99-
100-
.. code-block:: php
101-
102-
<?php
103-
// ...
104-
105-
class MyEntity implements NotifyPropertyChanged
106-
{
107-
// ...
108-
109-
protected function _onPropertyChanged($propName, $oldValue, $newValue): void
110-
{
111-
if ($this->_listeners) {
112-
foreach ($this->_listeners as $listener) {
113-
$listener->propertyChanged($this, $propName, $oldValue, $newValue);
114-
}
115-
}
116-
}
117-
118-
public function setData($data): void
119-
{
120-
if ($data != $this->data) {
121-
$this->_onPropertyChanged('data', $this->data, $data);
122-
$this->data = $data;
123-
}
124-
}
125-
}
126-
127-
You have to invoke ``_onPropertyChanged`` inside every method that
128-
changes the persistent state of ``MyEntity``.
129-
130-
The check whether the new value is different from the old one is
131-
not mandatory but recommended. That way you also have full control
132-
over when you consider a property changed.
133-
134-
If your entity contains an embeddable, you will need to notify
135-
separately for each property in the embeddable when it changes
136-
for example:
137-
138-
.. code-block:: php
139-
140-
<?php
141-
// ...
142-
143-
class MyEntity implements NotifyPropertyChanged
144-
{
145-
public function setEmbeddable(MyValueObject $embeddable): void
146-
{
147-
if (!$embeddable->equals($this->embeddable)) {
148-
// notice the entityField.embeddableField notation for referencing the property
149-
$this->_onPropertyChanged('embeddable.prop1', $this->embeddable->getProp1(), $embeddable->getProp1());
150-
$this->_onPropertyChanged('embeddable.prop2', $this->embeddable->getProp2(), $embeddable->getProp2());
151-
$this->embeddable = $embeddable;
152-
}
153-
}
154-
}
155-
156-
This would update all the fields of the embeddable, you may wish to
157-
implement a diff method on your embedded object which returns only
158-
the changed fields.
159-
160-
The negative point of this policy is obvious: You need implement an
161-
interface and write some plumbing code. But also note that we tried
162-
hard to keep this notification functionality abstract. Strictly
163-
speaking, it has nothing to do with the persistence layer and the
164-
Doctrine ORM or DBAL. You may find that property notification
165-
events come in handy in many other scenarios as well. As mentioned
166-
earlier, the ``Doctrine\Common`` namespace is not that evil and
167-
consists solely of very small classes and interfaces that have
168-
almost no external dependencies (none to the DBAL and none to the
169-
ORM) and that you can easily take with you should you want to swap
170-
out the persistence layer. This change tracking policy does not
171-
introduce a dependency on the Doctrine DBAL/ORM or the persistence
172-
layer.
173-
174-
The positive point and main advantage of this policy is its
175-
effectiveness. It has the best performance characteristics of the 3
176-
policies with larger units of work and a flush() operation is very
177-
cheap when nothing has changed.

docs/en/reference/php-mapping.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ The API of the ClassMetadataBuilder has the following methods with a fluent inte
9292
- ``setDiscriminatorColumn($name, $type = 'string', $length = 255, $columnDefinition = null, $enumType = null, $options = [])``
9393
- ``addDiscriminatorMapClass($name, $class)``
9494
- ``setChangeTrackingPolicyDeferredExplicit()``
95-
- ``setChangeTrackingPolicyNotify()``
9695
- ``addLifecycleEvent($methodName, $event)``
9796
- ``addManyToOne($name, $targetEntity, $inversedBy = null)``
9897
- ``addInverseOneToOne($name, $targetEntity, $mappedBy)``
@@ -203,7 +202,6 @@ Change Tracking Getters
203202

204203
- ``isChangeTrackingDeferredExplicit()``
205204
- ``isChangeTrackingDeferredImplicit()``
206-
- ``isChangeTrackingNotify()``
207205

208206
Field & Association Getters
209207
~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/en/sidebar.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
cookbook/dql-custom-walkers
7171
cookbook/dql-user-defined-functions
7272
cookbook/implementing-arrayaccess-for-domain-objects
73-
cookbook/implementing-the-notify-changetracking-policy
7473
cookbook/resolve-target-entity-listener
7574
cookbook/sql-table-prefixes
7675
cookbook/strategy-cookbook-introduction

docs/en/toc.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Cookbook
7272
cookbook/dql-custom-walkers
7373
cookbook/dql-user-defined-functions
7474
cookbook/implementing-arrayaccess-for-domain-objects
75-
cookbook/implementing-the-notify-changetracking-policy
7675
cookbook/resolve-target-entity-listener
7776
cookbook/sql-table-prefixes
7877
cookbook/strategy-cookbook-introduction

doctrine-mapping.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
<xs:restriction base="xs:token">
199199
<xs:enumeration value="DEFERRED_IMPLICIT"/>
200200
<xs:enumeration value="DEFERRED_EXPLICIT"/>
201-
<xs:enumeration value="NOTIFY"/>
202201
</xs:restriction>
203202
</xs:simpleType>
204203

lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,6 @@ public function setChangeTrackingPolicyDeferredExplicit(): static
220220
return $this;
221221
}
222222

223-
/**
224-
* Sets notify change tracking policy.
225-
*
226-
* @return $this
227-
*/
228-
public function setChangeTrackingPolicyNotify(): static
229-
{
230-
$this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY);
231-
232-
return $this;
233-
}
234-
235223
/**
236224
* Adds lifecycle event.
237225
*

0 commit comments

Comments
 (0)