File tree 2 files changed +42
-2
lines changed
2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 20
20
use Phinx \Db \Adapter \AdapterInterface ;
21
21
use Phinx \Db \Adapter \AdapterWrapper ;
22
22
23
+ use function Cake \Core \deprecationWarning ;
24
+
23
25
/**
24
26
* Decorates an AdapterInterface in order to proxy some method to the actual
25
27
* connection object.
@@ -76,11 +78,29 @@ public function getCakeConnection()
76
78
/**
77
79
* Returns a new Query object
78
80
*
81
+ * @param string|null $type The query type to get. Defaults to null emitting a deprecation
79
82
* @return \Cake\Database\Query
80
83
*/
81
- public function getQueryBuilder (): Query
84
+ public function getQueryBuilder (? string $ type = null ): Query
82
85
{
83
- return $ this ->getCakeConnection ()->newQuery ();
86
+ switch ($ type ) {
87
+ case 'delete ' :
88
+ return $ this ->getCakeConnection ()->deleteQuery ();
89
+ case 'insert ' :
90
+ return $ this ->getCakeConnection ()->insertQuery ();
91
+ case 'select ' :
92
+ return $ this ->getCakeConnection ()->selectQuery ();
93
+ case 'update ' :
94
+ return $ this ->getCakeConnection ()->updateQuery ();
95
+ case null :
96
+ default :
97
+ deprecationWarning (
98
+ 'Using getQueryBuilder() with no parameters is deprecated. ' .
99
+ "Please provide a query type parameter e.g `getQueryBuilder('select')` "
100
+ );
101
+
102
+ return $ this ->getCakeConnection ()->newQuery ();
103
+ }
84
104
}
85
105
86
106
/**
Original file line number Diff line number Diff line change 14
14
namespace Migrations \Test \TestCase ;
15
15
16
16
use Cake \Core \Plugin ;
17
+ use Cake \Database \Query \InsertQuery ;
18
+ use Cake \Database \Query \SelectQuery ;
19
+ use Cake \Database \Query \UpdateQuery ;
17
20
use Cake \Datasource \ConnectionManager ;
18
21
use Cake \TestSuite \TestCase ;
19
22
use Migrations \CakeAdapter ;
@@ -1001,4 +1004,21 @@ public function migrationsProvider()
1001
1004
],
1002
1005
];
1003
1006
}
1007
+
1008
+ public function testQueryBuilder (): void
1009
+ {
1010
+ $ adapter = $ this ->migrations
1011
+ ->getManager ()
1012
+ ->getEnvironment ('default ' )
1013
+ ->getAdapter ();
1014
+
1015
+ $ this ->assertInstanceOf (CakeAdapter::class, $ adapter );
1016
+ $ this ->assertInstanceOf (DeleteQuery::class, $ adapter ->getQueryBuilder ('delete ' ));
1017
+ $ this ->assertInstanceOf (InsertQuery::class, $ adapter ->getQueryBuilder ('insert ' ));
1018
+ $ this ->assertInstanceOf (SelectQuery::class, $ adapter ->getQueryBuilder ('select ' ));
1019
+ $ this ->assertInstanceOf (UpdateQuery::class, $ adapter ->getQueryBuilder ('update ' ));
1020
+ $ this ->deprecated (function () use ($ adapter ) {
1021
+ $ this ->assertInstanceOf (SelectQuery::class, $ adapter ->getQueryBuilder ());
1022
+ });
1023
+ }
1004
1024
}
You can’t perform that action at this time.
0 commit comments