mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 07:06:45 +02:00
New plugin: Specify query timeout
This commit is contained in:
@@ -21,12 +21,12 @@ class AdminerMenuLinks extends Adminer\Plugin {
|
||||
'' => $this->lang('Both'),
|
||||
'auto' => $this->lang('Auto (select on select page, structure otherwise)'),
|
||||
);
|
||||
$menu = Adminer\get_setting("menu", "adminer_config") ?: $this->menu;
|
||||
$menu = Adminer\get_setting("menu", "adminer_config", $this->menu);
|
||||
return array($this->lang('Menu table links') => Adminer\html_radios('config[menu]', $options, $menu, "<br>"));
|
||||
}
|
||||
|
||||
function tablesPrint(array $tables) {
|
||||
$menu = Adminer\get_setting("menu", "adminer_config") ?: $this->menu;
|
||||
$menu = Adminer\get_setting("menu", "adminer_config", $this->menu);
|
||||
$titles = array(
|
||||
'select' => $this->lang('Select data'),
|
||||
'table' => $this->lang('Show structure'),
|
||||
|
48
plugins/timeout.php
Normal file
48
plugins/timeout.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/** Specify timeout for running every query
|
||||
* @link https://www.adminer.org/plugins/#use
|
||||
* @author Jakub Vrana, https://www.vrana.cz/
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||
*/
|
||||
class AdminerTimeout extends Adminer\Plugin {
|
||||
private $seconds;
|
||||
|
||||
/**
|
||||
* @param int $seconds
|
||||
*/
|
||||
function __construct($seconds = 5) {
|
||||
$this->seconds = $seconds;
|
||||
}
|
||||
|
||||
function afterConnect() {
|
||||
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
|
||||
if ($seconds != '') {
|
||||
$ms = $seconds * 1000;
|
||||
$conn = Adminer\connection();
|
||||
switch (Adminer\JUSH) {
|
||||
case 'sql': $conn->query("SET max_execution_time = $ms"); break;
|
||||
case 'pgsql': $conn->query("SET statement_timeout = $ms"); break;
|
||||
case 'mssql': $conn->query("SET LOCK_TIMEOUT $ms"); break;
|
||||
default:
|
||||
if (method_exists(connection(), 'timeout')) {
|
||||
$conn->timeout($ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function config() {
|
||||
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
|
||||
return array($this->lang('Queries timeout') => '<input type="number" name="config[timeout]" min="0" value="' . Adminer\h($seconds) . '" class="size"> ' . $this->lang('seconds'));
|
||||
}
|
||||
|
||||
protected $translations = array(
|
||||
'cs' => array(
|
||||
'' => 'Nastaví timeout pro spouštění každého dotazu',
|
||||
'Queries timeout' => 'Timeout dotazů',
|
||||
'seconds' => 'sekund',
|
||||
),
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user