Skip to content

Commit 669118b

Browse files
committed
Merge pull request #355 from snelg/issue-354
Issue #354 fix - Fallback for unbuffered queries in VariablesPanel
2 parents a3c63f5 + e363eae commit 669118b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: src/Panel/VariablesPanel.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public function shutdown(Event $event)
7272

7373
$walker = function (&$item) use (&$walker) {
7474
if ($item instanceof Query || $item instanceof ResultSet) {
75-
$item = $item->toArray();
75+
try {
76+
$item = $item->toArray();
77+
} catch (\Cake\Database\Exception $e) {
78+
//Likely issue is unbuffered query; fall back to __debugInfo
79+
$item = array_map($walker, $item->__debugInfo());
80+
}
7681
} elseif ($item instanceof Closure ||
7782
$item instanceof PDO ||
7883
$item instanceof SimpleXmlElement

Diff for: tests/TestCase/Panel/VariablesPanelTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ public function testShutdown()
5858
$requests = TableRegistry::get('Requests');
5959
$query = $requests->find('all');
6060
$result = $requests->find()->all();
61+
$unbufferedQuery = $requests->find('all')->bufferResults(false);
62+
$unbufferedQuery->toArray(); //toArray call would normally happen somewhere in View, usually implicitly
6163

6264
$controller = new \StdClass();
6365
$controller->viewVars = [
6466
'query' => $query,
67+
'unbufferedQuery' => $unbufferedQuery,
6568
'result set' => $result,
6669
'string' => 'yes',
6770
'array' => ['some' => 'key']
@@ -76,6 +79,7 @@ public function testShutdown()
7679
'Original value should not be mutated'
7780
);
7881
$this->assertInternalType('array', $output['content']['query']);
82+
$this->assertInternalType('array', $output['content']['unbufferedQuery']);
7983
$this->assertInternalType('array', $output['content']['result set']);
8084
$this->assertEquals($controller->viewVars['string'], $output['content']['string']);
8185
$this->assertEquals($controller->viewVars['array'], $output['content']['array']);

0 commit comments

Comments
 (0)