mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
allow to switch whole database readonly, via setting "db_readonly" => true in header.inc.php
This commit is contained in:
parent
78c5f31ff5
commit
23ac04df8d
@ -5,7 +5,7 @@
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package admin
|
||||
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2007-17 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @version $Id$
|
||||
*/
|
||||
@ -147,7 +147,7 @@ class admin_cmd_change_account_id extends admin_cmd
|
||||
|
||||
$db = clone($GLOBALS['egw']->db);
|
||||
$db->set_app($app);
|
||||
if ($check_only) $db->log_updates = true;
|
||||
if ($check_only) $db->log_updates = $db->readonly = true;
|
||||
|
||||
foreach($data as $table => $columns)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
* @package api
|
||||
* @subpackage db
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2003-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2003-17 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
@ -101,13 +101,18 @@ class Db
|
||||
*/
|
||||
var $Password = '';
|
||||
|
||||
/**
|
||||
* @var boolean $readonly only allow readonly access to database
|
||||
*/
|
||||
var $readonly = false;
|
||||
|
||||
/**
|
||||
* @var int $Debug enable debuging - 0 no, 1 yes
|
||||
*/
|
||||
var $Debug = 0;
|
||||
|
||||
/**
|
||||
* Log update querys to error_log, do not run them
|
||||
* Log update querys to error_log
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
@ -248,7 +253,7 @@ class Db
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type'
|
||||
* @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type', 'db_readonly'
|
||||
*/
|
||||
function __construct(array $db_data=null)
|
||||
{
|
||||
@ -261,6 +266,7 @@ class Db
|
||||
'User' => 'db_user',
|
||||
'Password' => 'db_pass',
|
||||
'Type' => 'db_type',
|
||||
'readonly' => 'db_readonly',
|
||||
) as $var => $key)
|
||||
{
|
||||
$this->$var = $db_data[$key];
|
||||
@ -609,8 +615,7 @@ class Db
|
||||
if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli
|
||||
|
||||
$vars = get_object_vars($this);
|
||||
unset($vars['Link_ID']);
|
||||
unset($vars['privat_Link_ID']);
|
||||
unset($vars['Link_ID'], $vars['Query_ID'], $vars['privat_Link_ID']);
|
||||
return array_keys($vars);
|
||||
}
|
||||
|
||||
@ -749,10 +754,10 @@ class Db
|
||||
{
|
||||
$num_rows = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
if ($this->log_updates && stripos($Query_String, 'SELECT') !== 0)
|
||||
if (($this->readonly || $this->log_updates) && !preg_match('/\(?(SELECT|SET|SHOW)/i', $Query_String))
|
||||
{
|
||||
error_log($Query_String);
|
||||
return 0;
|
||||
if ($this->log_updates) error_log($Query_String.': '.function_backtrace());
|
||||
if ($this->readonly) return 0;
|
||||
}
|
||||
if ($num_rows > 0)
|
||||
{
|
||||
|
@ -140,16 +140,13 @@ class setup_cmd_database extends setup_cmd
|
||||
*/
|
||||
private function connect($user=null,$pass=null,$name=null)
|
||||
{
|
||||
if (is_null($user)) $user = $this->db_user;
|
||||
if (is_null($pass)) $pass = $this->db_pass;
|
||||
if (is_null($name)) $name = $this->db_name;
|
||||
|
||||
$this->test_db = new Api\Db();
|
||||
// propagate all db_* vars
|
||||
$this->test_db = new Api\Db(get_object_vars($this));
|
||||
|
||||
$error_rep = error_reporting();
|
||||
error_reporting($error_rep & ~E_WARNING); // switch warnings of, in case they are on
|
||||
error_reporting($error_rep & ~E_WARNING); // switch warnings off, in case they are on
|
||||
try {
|
||||
$this->test_db->connect($name,$this->db_host,$this->db_port,$user,$pass,$this->db_type);
|
||||
$this->test_db->connect($name, null, null, $user, $pass);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// just give a nicer error, after switching error_reporting on again
|
||||
|
Loading…
Reference in New Issue
Block a user