Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
62cb965e
Commit
62cb965e
authored
Sep 17, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-335' into 2.3
parents
c00cfd49
c5658ba7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+13
-3
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+23
-3
No files found.
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
View file @
62cb965e
...
...
@@ -138,12 +138,22 @@ class MasterSlaveConnection extends Connection
/**
* {@inheritDoc}
*/
public
function
connect
(
$connectionName
=
'slave'
)
public
function
connect
(
$connectionName
=
null
)
{
$requestedConnectionChange
=
(
$connectionName
!==
null
);
$connectionName
=
$connectionName
?:
'slave'
;
if
(
$connectionName
!==
'slave'
&&
$connectionName
!==
'master'
)
{
throw
new
\InvalidArgumentException
(
"Invalid option to connect(), only master or slave allowed."
);
}
// If we have a connection open, and this is not an explicit connection
// change request, then abort right here, because we are already done.
// This prevents writes to the slave in case of "keepSlave" option enabled.
if
(
$this
->
_conn
&&
!
$requestedConnectionChange
)
{
return
false
;
}
$forceMasterAsSlave
=
false
;
if
(
$this
->
getTransactionNestingLevel
()
>
0
)
{
...
...
@@ -161,7 +171,7 @@ class MasterSlaveConnection extends Connection
}
if
(
$connectionName
===
'master'
)
{
/
** Set slave connection to master to avoid invalid reads */
/
/ Set slave connection to master to avoid invalid reads
if
(
$this
->
connections
[
'slave'
]
&&
!
$this
->
keepSlave
)
{
unset
(
$this
->
connections
[
'slave'
]);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
View file @
62cb965e
...
...
@@ -32,11 +32,12 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
}
}
public
function
createMasterSlaveConnection
()
public
function
createMasterSlaveConnection
(
$keepSlave
=
false
)
{
$params
=
$this
->
_conn
->
getParams
();
$params
[
'master'
]
=
$params
;
$params
[
'slaves'
]
=
array
(
$params
,
$params
);
$params
[
'keepSlave'
]
=
$keepSlave
;
$params
[
'wrapperClass'
]
=
'Doctrine\DBAL\Connections\MasterSlaveConnection'
;
return
DriverManager
::
getConnection
(
$params
);
...
...
@@ -79,4 +80,23 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$this
->
assertEquals
(
2
,
$data
[
0
][
'num'
]);
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
}
/**
* @group DBAL-335
*/
public
function
testKeepSlaveBeginTransactionStaysOnMaster
()
{
$conn
=
$this
->
createMasterSlaveConnection
(
$keepSlave
=
true
);
$conn
->
connect
(
'slave'
);
$conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
30
));
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
$conn
->
connect
();
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
$conn
->
connect
(
'slave'
);
$this
->
assertFalse
(
$conn
->
isConnectedToMaster
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment