new: [API] SQL dump now includes two modes

- sql_dump:1 - append the SQL dump to the response
- sql_dump:2 - only return the SQL dump in the response
pull/5404/head
iglocska 2019-11-11 08:19:00 +01:00
parent 21088005d4
commit 463b98c275
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 15 additions and 7 deletions

View File

@ -124,7 +124,7 @@ class AppController extends Controller
}
if (!empty($this->params['named']['sql'])) {
$this->sql_dump = 1;
$this->sql_dump = intval($this->params['named']['sql']);
}
$this->_setupDatabaseConnection();

View File

@ -446,17 +446,25 @@ class RestResponseComponent extends Component
}
if (Configure::read('debug') > 1 && !empty($this->Controller->sql_dump)) {
$this->Log = ClassRegistry::init('Log');
$response['sql_dump'] = json_encode($this->Log->getDataSource()->getLog(false, false));
if ($this->Content->sql_dump === 2) {
$response = array('sql_dump' => $this->Log->getDataSource()->getLog(false, false));
} else {
$response['sql_dump'] = $this->Log->getDataSource()->getLog(false, false);
}
}
$response = json_encode($response, JSON_PRETTY_PRINT);
} else {
if (Configure::read('debug') > 1 && !empty($this->Controller->sql_dump)) {
$this->Log = ClassRegistry::init('Log');
$response = substr_replace(
$response,
sprintf(', "sql_dump": %s}', json_encode($this->Log->getDataSource()->getLog(false, false))),
-2
);
if ($this->Controller->sql_dump === 2) {
$response = json_encode(array('sql_dump' => $this->Log->getDataSource()->getLog(false, false)));
} else {
$response = substr_replace(
$response,
sprintf(', "sql_dump": %s}', json_encode($this->Log->getDataSource()->getLog(false, false))),
-2
);
}
}
}
}