mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 12:51:52 +02:00
fixed "There's NO ADOdb object!" error in DB backup/restore via
setup-cli.php
This commit is contained in:
parent
667eb5eb82
commit
16c5ce05ac
@ -1,58 +1,87 @@
|
|||||||
<?php
|
<?php
|
||||||
/**************************************************************************\
|
/**
|
||||||
* eGroupWare - Setup - db-backups *
|
* eGroupWare API: Database backups
|
||||||
* http://www.egroupware.org *
|
|
||||||
* -------------------------------------------- *
|
|
||||||
* Written and copyright by Ralf Becker <RalfBecker@outdoor-training.de> *
|
|
||||||
* -------------------------------------------- *
|
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
|
||||||
* under the terms of the GNU General Public License as published by the *
|
|
||||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
||||||
* option) any later version. *
|
|
||||||
\**************************************************************************/
|
|
||||||
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
define('BACKSLASH_TOKEN','##!!**bAcKsLaSh**!!##'); // used in cvs_split
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DB independent backup and restore of eGW's DB
|
|
||||||
*
|
*
|
||||||
* @package phpgwapi
|
* @link http://www.egroupware.org
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package api
|
||||||
* @subpackage db
|
* @subpackage db
|
||||||
* @author RalfBecker-AT-outdoor-training.de
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||||
* @license GPL
|
* @copyright (c) 2003-8 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class db_backup
|
/**
|
||||||
{
|
* DB independent backup and restore of eGW's DB
|
||||||
var $schema_proc; /** schema_proc class */
|
*/
|
||||||
var $schemas = array(); /** array tablename => schema */
|
class db_backup
|
||||||
var $exclude_tables = array( /** exclude from backup */
|
{
|
||||||
|
/**
|
||||||
|
* replaces backslashes, used in cvs_split
|
||||||
|
*/
|
||||||
|
const BACKSLASH_TOKEN = '##!!**bAcKsLaSh**!!##';
|
||||||
|
/**
|
||||||
|
* Reference to schema_proc
|
||||||
|
*
|
||||||
|
* @var schema_proc
|
||||||
|
*/
|
||||||
|
var $schema_proc;
|
||||||
|
/**
|
||||||
|
* Reference to ADOdb (connection) object
|
||||||
|
*
|
||||||
|
* @var ADOConnection
|
||||||
|
*/
|
||||||
|
var $adodb;
|
||||||
|
/**
|
||||||
|
* DB schemas, as array tablename => schema
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $schemas = array();
|
||||||
|
/**
|
||||||
|
* Tables to exclude from the backup: sessions, diverse caches which get automatic rebuild
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $exclude_tables = array(
|
||||||
'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables
|
'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables
|
||||||
'phpgw_anglemail', // email's cache
|
'phpgw_anglemail', // email's cache
|
||||||
'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache
|
'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache
|
||||||
);
|
);
|
||||||
var $system_tables = false; /** regular expression to identify system-tables => ignored for schema+backup */
|
/**
|
||||||
var $egw_tables = false; /** regurar expression to identify eGW tables => if set only they are used */
|
* regular expression to identify system-tables => ignored for schema+backup
|
||||||
|
*
|
||||||
|
* @var string|boolean
|
||||||
|
*/
|
||||||
|
var $system_tables = false;
|
||||||
|
/**
|
||||||
|
* regurar expression to identify eGW tables => if set only they are used
|
||||||
|
*
|
||||||
|
* @var string|boolean
|
||||||
|
*/
|
||||||
|
var $egw_tables = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function db_backup()
|
function __construct()
|
||||||
{
|
{
|
||||||
if (is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it
|
if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db))
|
||||||
|
{
|
||||||
|
$GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded
|
||||||
|
}
|
||||||
|
if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it
|
||||||
{
|
{
|
||||||
$this->schema_proc = $GLOBALS['egw_setup']->oProc;
|
$this->schema_proc = $GLOBALS['egw_setup']->oProc;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->schema_proc = CreateObject('phpgwapi.schema_proc');
|
$this->schema_proc = new schema_proc();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db = $this->schema_proc->m_odb;
|
$this->db = $this->schema_proc->m_odb;
|
||||||
$this->adodb = &$GLOBALS['egw']->ADOdb;
|
$this->adodb = $this->db->Link_ID;
|
||||||
if (is_object($GLOBALS['egw_setup'])) // called from setup
|
if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup'])) // called from setup
|
||||||
{
|
{
|
||||||
if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
|
if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
|
||||||
{
|
{
|
||||||
@ -276,9 +305,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Split one line of a csv file into an array and does all unescaping
|
* Split one line of a csv file into an array and does all unescaping
|
||||||
* @internal
|
|
||||||
*/
|
*/
|
||||||
function csv_split($line,$keys=False)
|
private function csv_split($line,$keys=False)
|
||||||
{
|
{
|
||||||
$fields = explode(',',trim($line));
|
$fields = explode(',',trim($line));
|
||||||
|
|
||||||
@ -300,7 +328,7 @@
|
|||||||
$str_pending = $field;
|
$str_pending = $field;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$arr[$key] = str_replace(BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1)));
|
$arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1)));
|
||||||
}
|
}
|
||||||
elseif ($keys && strlen($field) > 24)
|
elseif ($keys && strlen($field) > 24)
|
||||||
{
|
{
|
||||||
@ -316,9 +344,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* escape data for csv
|
||||||
*/
|
*/
|
||||||
function escape_data(&$data,$col,$defs)
|
private function escape_data(&$data,$col,$defs)
|
||||||
{
|
{
|
||||||
if (is_null($data))
|
if (is_null($data))
|
||||||
{
|
{
|
||||||
@ -399,7 +427,7 @@
|
|||||||
/**
|
/**
|
||||||
* Backup all schemas in the form of a setup/tables_current.inc.php file
|
* Backup all schemas in the form of a setup/tables_current.inc.php file
|
||||||
*
|
*
|
||||||
* @param f resource/boolean
|
* @param resource|boolean $f
|
||||||
*/
|
*/
|
||||||
function schema_backup($f=False)
|
function schema_backup($f=False)
|
||||||
{
|
{
|
||||||
@ -436,7 +464,7 @@
|
|||||||
{
|
{
|
||||||
if (!is_object($this->browser))
|
if (!is_object($this->browser))
|
||||||
{
|
{
|
||||||
$this->browser = CreateObject('phpgwapi.browser');
|
$this->browser = new browser();
|
||||||
}
|
}
|
||||||
$this->browser->content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
|
$this->browser->content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
|
||||||
echo "<?php\n\t/* eGroupWare schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
|
echo "<?php\n\t/* eGroupWare schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
|
||||||
@ -444,9 +472,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal copied from etemplate/inc/class.db_tools.inc.php
|
* Dump an array as php source
|
||||||
|
*
|
||||||
|
* copied from etemplate/inc/class.db_tools.inc.php
|
||||||
*/
|
*/
|
||||||
function write_array($arr,$depth,$parent='')
|
private function write_array($arr,$depth,$parent='')
|
||||||
{
|
{
|
||||||
if (in_array($parent,array('pk','fk','ix','uc')))
|
if (in_array($parent,array('pk','fk','ix','uc')))
|
||||||
{
|
{
|
||||||
@ -495,7 +525,7 @@
|
|||||||
|
|
||||||
return $def;
|
return $def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
$line = '"de","ranking","use \\"yes\\", or \\"no, prefession\\"","benützen Sie \\"yes\\" oder \\"no, Beruf\\""';
|
$line = '"de","ranking","use \\"yes\\", or \\"no, prefession\\"","benützen Sie \\"yes\\" oder \\"no, Beruf\\""';
|
||||||
|
|
||||||
|
@ -100,18 +100,20 @@ class schema_proc
|
|||||||
if(is_object($db))
|
if(is_object($db))
|
||||||
{
|
{
|
||||||
$this->m_odb = $db;
|
$this->m_odb = $db;
|
||||||
$this->adodb = &$this->m_odb->Link_ID;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->m_odb = is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
|
$this->m_odb = isset($GLOBALS['egw']->db) && is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
|
||||||
$this->adodb = &$GLOBALS['egw']->ADOdb;
|
}
|
||||||
|
if (!($this->m_odb instanceof egw_db))
|
||||||
|
{
|
||||||
|
throw new egw_exception_assertion_failed('no egw_db object!');
|
||||||
}
|
}
|
||||||
$this->m_odb->connect();
|
$this->m_odb->connect();
|
||||||
$this->capabilities =& $this->m_odb->capabilities;
|
$this->capabilities =& $this->m_odb->capabilities;
|
||||||
|
|
||||||
$this->sType = $dbms ? $dmbs : $this->m_odb->Type;
|
$this->sType = $dbms ? $dmbs : $this->m_odb->Type;
|
||||||
|
$this->adodb = &$this->m_odb->Link_ID;
|
||||||
$this->dict = NewDataDictionary($this->adodb);
|
$this->dict = NewDataDictionary($this->adodb);
|
||||||
|
|
||||||
// enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1
|
// enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user