Skip to content

Commit 1e9973a

Browse files
authored
Merge release 2.10.4 into 2.11.x (#9280)
2 parents 9176173 + cccb2e2 commit 1e9973a

11 files changed

+76
-47
lines changed

docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Advanced field value conversion using custom mapping types
44
.. sectionauthor:: Jan Sorgalla <[email protected]>
55

66
When creating entities, you sometimes have the need to transform field values
7-
before they are saved to the database. In Doctrine you can use Custom Mapping
7+
before they are saved to the database. In Doctrine you can use Custom Mapping
88
Types to solve this (see: :ref:`reference-basic-mapping-custom-mapping-types`).
99

1010
There are several ways to achieve this: converting the value inside the Type
@@ -15,7 +15,7 @@ type `Point <https://dev.mysql.com/doc/refman/8.0/en/gis-class-point.html>`_.
1515

1616
The ``Point`` type is part of the `Spatial extension <https://dev.mysql.com/doc/refman/8.0/en/spatial-extensions.html>`_
1717
of MySQL and enables you to store a single location in a coordinate space by
18-
using x and y coordinates. You can use the Point type to store a
18+
using x and y coordinates. You can use the Point type to store a
1919
longitude/latitude pair to represent a geographic location.
2020

2121
The entity
@@ -29,9 +29,9 @@ The entity class:
2929
.. code-block:: php
3030
3131
<?php
32-
32+
3333
namespace Geo\Entity;
34-
34+
3535
/**
3636
* @Entity
3737
*/
@@ -84,15 +84,15 @@ The entity class:
8484
}
8585
}
8686
87-
We use the custom type ``point`` in the ``@Column`` docblock annotation of the
87+
We use the custom type ``point`` in the ``@Column`` docblock annotation of the
8888
``$point`` field. We will create this custom mapping type in the next chapter.
8989

9090
The point class:
9191

9292
.. code-block:: php
9393
9494
<?php
95-
95+
9696
namespace Geo\ValueObject;
9797
9898
class Point
@@ -196,7 +196,7 @@ The format of the string representation format is called
196196
`Well-known text (WKT) <https://en.wikipedia.org/wiki/Well-known_text>`_.
197197
The advantage of this format is, that it is both human readable and parsable by MySQL.
198198

199-
Internally, MySQL stores geometry values in a binary format that is not
199+
Internally, MySQL stores geometry values in a binary format that is not
200200
identical to the WKT format. So, we need to let MySQL transform the WKT
201201
representation into its internal format.
202202

@@ -210,13 +210,13 @@ which convert WKT strings to and from the internal format of MySQL.
210210

211211
.. note::
212212

213-
When using DQL queries, the ``convertToPHPValueSQL`` and
213+
When using DQL queries, the ``convertToPHPValueSQL`` and
214214
``convertToDatabaseValueSQL`` methods only apply to identification variables
215-
and path expressions in SELECT clauses. Expressions in WHERE clauses are
215+
and path expressions in SELECT clauses. Expressions in WHERE clauses are
216216
**not** wrapped!
217217

218218
If you want to use Point values in WHERE clauses, you have to implement a
219-
:doc:`user defined function <dql-user-defined-functions>` for
219+
:doc:`user defined function <dql-user-defined-functions>` for
220220
``PointFromText``.
221221

222222
Example usage
@@ -252,5 +252,5 @@ Example usage
252252
$query = $em->createQuery("SELECT l FROM Geo\Entity\Location l WHERE l.address = '1600 Amphitheatre Parkway, Mountain View, CA'");
253253
$location = $query->getSingleResult();
254254
255-
/* @var Geo\ValueObject\Point */
255+
/** @var Geo\ValueObject\Point */
256256
$point = $location->getPoint();

docs/en/cookbook/dql-custom-walkers.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ API would look for this use-case:
8888
$pageNum = 1;
8989
$query = $em->createQuery($dql);
9090
$query->setFirstResult( ($pageNum-1) * 20)->setMaxResults(20);
91-
91+
9292
$totalResults = Paginate::count($query);
9393
$results = $query->getResult();
9494
@@ -101,12 +101,12 @@ The ``Paginate::count(Query $query)`` looks like:
101101
{
102102
static public function count(Query $query)
103103
{
104-
/* @var $countQuery Query */
104+
/** @var Query $countQuery */
105105
$countQuery = clone $query;
106-
106+
107107
$countQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('DoctrineExtensions\Paginate\CountSqlWalker'));
108108
$countQuery->setFirstResult(null)->setMaxResults(null);
109-
109+
110110
return $countQuery->getSingleScalarResult();
111111
}
112112
}
@@ -137,13 +137,13 @@ implementation is:
137137
break;
138138
}
139139
}
140-
140+
141141
$pathExpression = new PathExpression(
142142
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName,
143143
$parent['metadata']->getSingleIdentifierFieldName()
144144
);
145145
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
146-
146+
147147
$AST->selectClause->selectExpressions = array(
148148
new SelectExpression(
149149
new AggregateExpression('count', $pathExpression, true), null
@@ -196,15 +196,15 @@ modify the generation of the SELECT clause, adding the
196196
public function walkSelectClause($selectClause)
197197
{
198198
$sql = parent::walkSelectClause($selectClause);
199-
199+
200200
if ($this->getQuery()->getHint('mysqlWalker.sqlNoCache') === true) {
201201
if ($selectClause->isDistinct) {
202202
$sql = str_replace('SELECT DISTINCT', 'SELECT DISTINCT SQL_NO_CACHE', $sql);
203203
} else {
204204
$sql = str_replace('SELECT', 'SELECT SQL_NO_CACHE', $sql);
205205
}
206206
}
207-
207+
208208
return $sql;
209209
}
210210
}

docs/en/cookbook/dql-user-defined-functions.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ configuration:
4545
$config->addCustomStringFunction($name, $class);
4646
$config->addCustomNumericFunction($name, $class);
4747
$config->addCustomDatetimeFunction($name, $class);
48-
48+
4949
$em = EntityManager::create($dbParams, $config);
5050
5151
The ``$name`` is the name the function will be referred to in the
@@ -96,7 +96,7 @@ discuss it step by step:
9696
// (1)
9797
public $firstDateExpression = null;
9898
public $secondDateExpression = null;
99-
99+
100100
public function parse(\Doctrine\ORM\Query\Parser $parser)
101101
{
102102
$parser->match(Lexer::T_IDENTIFIER); // (2)
@@ -106,7 +106,7 @@ discuss it step by step:
106106
$this->secondDateExpression = $parser->ArithmeticPrimary(); // (6)
107107
$parser->match(Lexer::T_CLOSE_PARENTHESIS); // (3)
108108
}
109-
109+
110110
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
111111
{
112112
return 'DATEDIFF(' .
@@ -180,28 +180,28 @@ I'll skip the blah and show the code for this function:
180180
public $firstDateExpression = null;
181181
public $intervalExpression = null;
182182
public $unit = null;
183-
183+
184184
public function parse(\Doctrine\ORM\Query\Parser $parser)
185185
{
186186
$parser->match(Lexer::T_IDENTIFIER);
187187
$parser->match(Lexer::T_OPEN_PARENTHESIS);
188-
188+
189189
$this->firstDateExpression = $parser->ArithmeticPrimary();
190-
190+
191191
$parser->match(Lexer::T_COMMA);
192192
$parser->match(Lexer::T_IDENTIFIER);
193-
193+
194194
$this->intervalExpression = $parser->ArithmeticPrimary();
195-
195+
196196
$parser->match(Lexer::T_IDENTIFIER);
197-
198-
/* @var $lexer Lexer */
197+
198+
/** @var Lexer $lexer */
199199
$lexer = $parser->getLexer();
200200
$this->unit = $lexer->token['value'];
201-
201+
202202
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
203203
}
204-
204+
205205
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
206206
{
207207
return 'DATE_ADD(' .

docs/en/reference/second-level-cache.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ By providing a cache logger you should be able to get information about all cach
231231
.. code-block:: php
232232
233233
<?php
234-
/* @var $config \Doctrine\ORM\Configuration */
234+
/** @var \Doctrine\ORM\Configuration $config */
235235
$logger = new \Doctrine\ORM\Cache\Logging\StatisticsCacheLogger();
236236
237237
// Cache logger
@@ -533,7 +533,7 @@ The query cache stores the results of the query but as identifiers, entity value
533533
.. code-block:: php
534534
535535
<?php
536-
/* @var $em \Doctrine\ORM\EntityManager */
536+
/** @var \Doctrine\ORM\EntityManager $em */
537537
538538
// Execute database query, store query cache and entity cache
539539
$result1 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name')
@@ -560,7 +560,7 @@ The Cache Mode controls how a particular query interacts with the second-level c
560560
.. code-block:: php
561561
562562
<?php
563-
/* @var $em \Doctrine\ORM\EntityManager */
563+
/** @var \Doctrine\ORM\EntityManager $em */
564564
// Will refresh the query cache and all entities the cache as it reads from the database.
565565
$result1 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name')
566566
->setCacheMode(\Doctrine\ORM\Cache::MODE_GET)
@@ -649,7 +649,7 @@ However, you can use the cache API to check / invalidate cache entries.
649649
.. code-block:: php
650650
651651
<?php
652-
/* @var $cache \Doctrine\ORM\Cache */
652+
/** @var \Doctrine\ORM\Cache $cache */
653653
$cache = $em->getCache();
654654
655655
$cache->containsEntity('Entity\State', 1) // Check if the cache exists
@@ -694,11 +694,11 @@ For performance reasons the cache API does not extract from composite primary ke
694694
}
695695
696696
// Supported
697-
/* @var $article Article */
697+
/** @var Article $article */
698698
$article = $em->find('Article', 1);
699699
700700
// Supported
701-
/* @var $article Article */
701+
/** @var Article $article */
702702
$article = $em->find('Article', $article);
703703
704704
// Supported

lib/Doctrine/ORM/Id/SequenceGenerator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ORM\Id;
66

7+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
78
use Doctrine\ORM\EntityManager;
89
use Serializable;
910

@@ -54,11 +55,14 @@ public function generate(EntityManager $em, $entity)
5455
{
5556
if ($this->_maxValue === null || $this->_nextValue === $this->_maxValue) {
5657
// Allocate new values
57-
$conn = $em->getConnection();
58-
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
58+
$connection = $em->getConnection();
59+
$sql = $connection->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
5960

60-
// Using `query` to force usage of the master server in MasterSlaveConnection
61-
$this->_nextValue = (int) $conn->executeQuery($sql)->fetchOne();
61+
if ($connection instanceof PrimaryReadReplicaConnection) {
62+
$connection->ensureConnectedToPrimary();
63+
}
64+
65+
$this->_nextValue = (int) $connection->executeQuery($sql)->fetchOne();
6266
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
6367
}
6468

lib/Doctrine/ORM/Id/UuidGenerator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ORM\Id;
66

7+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
78
use Doctrine\DBAL\Platforms\AbstractPlatform;
89
use Doctrine\Deprecations\Deprecation;
910
use Doctrine\ORM\EntityManager;
@@ -39,9 +40,13 @@ public function __construct()
3940
*/
4041
public function generate(EntityManager $em, $entity)
4142
{
42-
$conn = $em->getConnection();
43-
$sql = 'SELECT ' . $conn->getDatabasePlatform()->getGuidExpression();
43+
$connection = $em->getConnection();
44+
$sql = 'SELECT ' . $connection->getDatabasePlatform()->getGuidExpression();
4445

45-
return $conn->executeQuery($sql)->fetchOne();
46+
if ($connection instanceof PrimaryReadReplicaConnection) {
47+
$connection->ensureConnectedToPrimary();
48+
}
49+
50+
return $connection->executeQuery($sql)->fetchOne();
4651
}
4752
}

lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Query\Exec;
66

77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
89
use Doctrine\DBAL\Types\Type;
910
use Doctrine\ORM\Query\AST;
1011
use Doctrine\ORM\Query\AST\DeleteStatement;
@@ -49,6 +50,10 @@ public function __construct(AST\Node $AST, $sqlWalker)
4950
$platform = $conn->getDatabasePlatform();
5051
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
5152

53+
if ($conn instanceof PrimaryReadReplicaConnection) {
54+
$conn->ensureConnectedToPrimary();
55+
}
56+
5257
$primaryClass = $em->getClassMetadata($AST->deleteClause->abstractSchemaName);
5358
$primaryDqlAlias = $AST->deleteClause->aliasIdentificationVariable;
5459
$rootClass = $em->getClassMetadata($primaryClass->rootEntityName);

lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Query\Exec;
66

77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
89
use Doctrine\DBAL\Types\Type;
910
use Doctrine\ORM\Query\AST;
1011
use Doctrine\ORM\Query\AST\UpdateStatement;
@@ -55,6 +56,10 @@ public function __construct(AST\Node $AST, $sqlWalker)
5556
$platform = $conn->getDatabasePlatform();
5657
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
5758

59+
if ($conn instanceof PrimaryReadReplicaConnection) {
60+
$conn->ensureConnectedToPrimary();
61+
}
62+
5863
$updateClause = $AST->updateClause;
5964
$primaryClass = $sqlWalker->getEntityManager()->getClassMetadata($updateClause->abstractSchemaName);
6065
$rootClass = $em->getClassMetadata($primaryClass->rootEntityName);

lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Query\Exec;
66

77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
89
use Doctrine\ORM\Query\AST;
910
use Doctrine\ORM\Query\SqlWalker;
1011

@@ -37,6 +38,10 @@ public function __construct(AST\Node $AST, $sqlWalker)
3738
*/
3839
public function execute(Connection $conn, array $params, array $types)
3940
{
41+
if ($conn instanceof PrimaryReadReplicaConnection) {
42+
$conn->ensureConnectedToPrimary();
43+
}
44+
4045
return $conn->executeStatement($this->_sqlStatements, $params, $types);
4146
}
4247
}

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\Common\Collections\Collection;
1010
use Doctrine\Common\EventManager;
1111
use Doctrine\Common\Proxy\Proxy;
12+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
1213
use Doctrine\DBAL\LockMode;
1314
use Doctrine\Deprecations\Deprecation;
1415
use Doctrine\ORM\Cache\Persister\CachedPersister;
@@ -338,6 +339,12 @@ public function __construct(EntityManagerInterface $em)
338339
*/
339340
public function commit($entity = null)
340341
{
342+
$connection = $this->em->getConnection();
343+
344+
if ($connection instanceof PrimaryReadReplicaConnection) {
345+
$connection->ensureConnectedToPrimary();
346+
}
347+
341348
// Raise preFlush
342349
if ($this->evm->hasListeners(Events::preFlush)) {
343350
$this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));

0 commit comments

Comments
 (0)