1) enabled DB support additionaly for:

- Oracle via oci8 or odbc extension
- MsSql via odbc extension
2) added checks for the neccesary extension incl. loading them if they are not loaded by default: db extensions and session extension. This is now consitent wiht check_install.
3) sessions class tries now to load the php session extension and silently fallbacks to db-sessions
This commit is contained in:
Ralf Becker 2005-02-25 07:45:37 +00:00
parent 9f525747b4
commit 9a6b90e78f
4 changed files with 98 additions and 29 deletions

View File

@ -21,6 +21,15 @@
* @license LGPL * @license LGPL
*/ */
// some constanst for pre php4.3
if (!defined('PHP_SHLIB_SUFFIX'))
{
define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
}
if (!defined('PHP_SHLIB_PREFIX'))
{
define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
}
if(empty($GLOBALS['phpgw_info']['server']['db_type'])) if(empty($GLOBALS['phpgw_info']['server']['db_type']))
{ {
$GLOBALS['phpgw_info']['server']['db_type'] = 'mysql'; $GLOBALS['phpgw_info']['server']['db_type'] = 'mysql';
@ -185,25 +194,46 @@
{ {
$$name = $this->$name; $$name = $this->$name;
} }
$type = $this->Type; $php_extension = $type = $this->Type;
switch($this->Type) // convert to ADO db-type-names switch($this->Type) // convert to ADO db-type-names
{ {
case 'pgsql': case 'pgsql':
$type = 'postgres'; $type = 'postgres'; // name in ADOdb
// create our own pgsql connection-string, to allow unix domain soccets if !$Host // create our own pgsql connection-string, to allow unix domain soccets if !$Host
$Host = "dbname=$this->Database".($this->Host ? " host=$this->Host".($this->Port ? " port=$this->Port" : '') : ''). $Host = "dbname=$this->Database".($this->Host ? " host=$this->Host".($this->Port ? " port=$this->Port" : '') : '').
" user=$this->User".($this->Password ? " password='".addslashes($this->Password)."'" : ''); " user=$this->User".($this->Password ? " password='".addslashes($this->Password)."'" : '');
$User = $Password = $Database = ''; // to indicate $Host is a connection-string $User = $Password = $Database = ''; // to indicate $Host is a connection-string
break; break;
case 'odbc_mssql':
$php_extension = 'odbc';
$this->Type = 'mssql';
// fall through
case 'mssql': case 'mssql':
if ($this->Port) $Host .= ','.$this->Port; if ($this->Port) $Host .= ','.$this->Port;
break; break;
case 'odbc_oracle':
$php_extension = 'odbc';
$this->Type = 'oracle';
break;
case 'oracle':
$php_extension = $type = 'oci8';
break;
case 'sapdb':
$this->Type = 'maxdb';
// fall through
case 'maxdb':
$type ='sapdb'; // name in ADOdb
$php_extension = 'odbc';
break;
default: default:
if ($this->Port) $Host .= ':'.$this->Port; if ($this->Port) $Host .= ':'.$this->Port;
break; break;
} }
if (!is_object($GLOBALS['phpgw']->ADOdb) || // we have no connection so far if (!is_object($GLOBALS['phpgw']->ADOdb) || // we have no connection so far
(is_object($GLOBALS['phpgw']->db) && // we connect to a different db, then the global one (is_object($GLOBALS['phpgw']->db) && // we connect to a different db, then the global one
($this->Type != $GLOBALS['phpgw']->db->Type || ($this->Type != $GLOBALS['phpgw']->db->Type ||
@ -212,6 +242,12 @@
$this->Host != $GLOBALS['phpgw']->db->Host || $this->Host != $GLOBALS['phpgw']->db->Host ||
$this->Port != $GLOBALS['phpgw']->db->Port))) $this->Port != $GLOBALS['phpgw']->db->Port)))
{ {
if (!extension_loaded($php_extension) && (!function_exists('dl') ||
!dl(PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX)))
{
$this->halt("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!");
return 0; // in case error-reporting = 'no'
}
if (!is_object($GLOBALS['phpgw']->ADOdb)) // use the global object to store the connection if (!is_object($GLOBALS['phpgw']->ADOdb)) // use the global object to store the connection
{ {
$this->Link_ID = &$GLOBALS['phpgw']->ADOdb; $this->Link_ID = &$GLOBALS['phpgw']->ADOdb;
@ -223,7 +259,7 @@
$this->Link_ID = ADONewConnection($type); $this->Link_ID = ADONewConnection($type);
if (!$this->Link_ID) if (!$this->Link_ID)
{ {
$this->halt("No ADOdb support for '$type' !!!"); $this->halt("No ADOdb support for '$type' ($this->Type) !!!");
return 0; // in case error-reporting = 'no' return 0; // in case error-reporting = 'no'
} }
$connect = $GLOBALS['phpgw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect'; $connect = $GLOBALS['phpgw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect';

View File

@ -1324,8 +1324,21 @@
{ {
$GLOBALS['phpgw_info']['server']['sessions_type'] = 'php4'; // the more performant default $GLOBALS['phpgw_info']['server']['sessions_type'] = 'php4'; // the more performant default
} }
if ($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4' && !extension_loaded('session') && !@dl('session')) // for php4 sessions, check if the extension is loaded, try loading it and fallback to db sessions if not
if ($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4' && !extension_loaded('session'))
{
// some constanst for pre php4.3
if (!defined('PHP_SHLIB_SUFFIX'))
{
define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
}
if (!defined('PHP_SHLIB_PREFIX'))
{
define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
}
if (!function_exists('dl') || !@dl(PHP_SHLIB_PREFIX.'session'.'.'.PHP_SHLIB_SUFFIX))
{ {
$GLOBALS['phpgw_info']['server']['sessions_type'] = 'db'; // fallback if we have no php4 sessions support $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db'; // fallback if we have no php4 sessions support
} }
}
include_once(PHPGW_API_INC.'/class.sessions_'.$GLOBALS['phpgw_info']['server']['sessions_type'].'.inc.php'); include_once(PHPGW_API_INC.'/class.sessions_'.$GLOBALS['phpgw_info']['server']['sessions_type'].'.inc.php');

View File

@ -111,7 +111,11 @@
), ),
'odbc' => array( 'odbc' => array(
'func' => 'extension_check', 'func' => 'extension_check',
'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','odbc','MaxDB') . '</div>', 'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','odbc','MaxDB, MsSQL or Oracle') . '</div>',
),
'oci8' => array(
'func' => 'extension_check',
'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','oci','Oracle') . '</div>',
), ),
'mbstring' => array( 'mbstring' => array(
'func' => 'extension_check', 'func' => 'extension_check',

View File

@ -21,6 +21,24 @@
); );
include('./inc/functions.inc.php'); include('./inc/functions.inc.php');
// some constanst for pre php4.3
if (!defined('PHP_SHLIB_SUFFIX'))
{
define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
}
if (!defined('PHP_SHLIB_PREFIX'))
{
define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
}
/**
* checks if a named extension is loaded or loadable
*/
function check_load_extension($extension)
{
return extension_loaded($extension) ||
function_exists('dl') && @dl(PHP_SHLIB_PREFIX.$extension.'.'.PHP_SHLIB_SUFFIX);
}
$GLOBALS['phpgw_info']['server']['versions']['current_header'] = $setup_info['phpgwapi']['versions']['current_header']; $GLOBALS['phpgw_info']['server']['versions']['current_header'] = $setup_info['phpgwapi']['versions']['current_header'];
$GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] = $setup_info['phpgwapi']['version']; $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] = $setup_info['phpgwapi']['version'];
unset($setup_info); unset($setup_info);
@ -48,15 +66,19 @@
'pgsql' => 'PostgreSQL', 'pgsql' => 'PostgreSQL',
'mysql' => 'MySQL', 'mysql' => 'MySQL',
'mssql' => 'MS SQL Server', 'mssql' => 'MS SQL Server',
'odbc_mssql' => 'MS SQL Server via ODBC',
'oracle' => 'Oracle', 'oracle' => 'Oracle',
'sapdb' => 'SAP/Max DB', 'odbc_oracle' => 'Oracle via ODBC',
'sapdb' => 'SAP/Max DB via ODBC',
); );
$default_db_ports = array( $default_db_ports = array(
'pgsql' => 5432, 'pgsql' => 5432,
'mysql' => 3306, 'mysql' => 3306,
'mssql' => 1433, 'mssql' => 1433,
'odbc_mssql' => '',
'oracle' => 1521, 'oracle' => 1521,
'odbc_oracle' => '',
'sapdb' => '', 'sapdb' => '',
); );
@ -252,7 +274,7 @@
$detected .= '<tr class="th"><td colspan="2">' . lang('Analysis') . '</td></tr><tr><td colspan="2">'. "\n"; $detected .= '<tr class="th"><td colspan="2">' . lang('Analysis') . '</td></tr><tr><td colspan="2">'. "\n";
$supported_db = array(); $supported_db = array();
if(extension_loaded('mysql') || function_exists('mysql_connect')) if(check_load_extension('mysql') || function_exists('mysql_connect'))
{ {
$detected .= lang('You appear to have MySQL support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have MySQL support enabled') . '<br>' . "\n";
$supported_db[] = 'mysql'; $supported_db[] = 'mysql';
@ -261,7 +283,7 @@
{ {
$detected .= lang('No MySQL support found. Disabling') . '<br>' . "\n"; $detected .= lang('No MySQL support found. Disabling') . '<br>' . "\n";
} }
if(extension_loaded('pgsql') || function_exists('pg_connect')) if(check_load_extension('pgsql') || function_exists('pg_connect'))
{ {
$detected .= lang('You appear to have PostgreSQL support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have PostgreSQL support enabled') . '<br>' . "\n";
$supported_db[] = 'pgsql'; $supported_db[] = 'pgsql';
@ -270,7 +292,7 @@
{ {
$detected .= lang('No PostgreSQL support found. Disabling') . '<br>' . "\n"; $detected .= lang('No PostgreSQL support found. Disabling') . '<br>' . "\n";
} }
if(extension_loaded('mssql') || function_exists('mssql_connect')) if(check_load_extension('mssql') || function_exists('mssql_connect'))
{ {
$detected .= lang('You appear to have Microsoft SQL Server support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have Microsoft SQL Server support enabled') . '<br>' . "\n";
$supported_db[] = 'mssql'; $supported_db[] = 'mssql';
@ -279,35 +301,29 @@
{ {
$detected .= lang('No Microsoft SQL Server support found. Disabling') . '<br>' . "\n"; $detected .= lang('No Microsoft SQL Server support found. Disabling') . '<br>' . "\n";
} }
if(extension_loaded('odbc')) if(check_load_extension('odbc'))
{ {
$detected .= lang('You appear to have ODBC support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have ODBC support enabled') . '<br>' . "\n";
// databases supported by the ODBC driver // databases supported by the ODBC driver
$supported_db[] = 'sapdb'; $supported_db[] = 'sapdb';
$supported_db[] = 'odbc_mssql';
$supported_db[] = 'odbc_oracle';
} }
else else
{ {
$detected .= lang('No ODBC support found. Disabling') . '<br>' . "\n"; $detected .= lang('No ODBC support found. Disabling') . '<br>' . "\n";
} }
/*
if(extension_loaded('oci8')) if(check_load_extension('oci8'))
{ {
$detected .= lang('You appear to have Oracle V8 (OCI) support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have Oracle V8 (OCI) support enabled') . '<br>' . "\n";
$supported_db[] = 'oracle'; $supported_db[] = 'oracle';
} }
else else
{
if(extension_loaded('oracle'))
{
$detected .= lang('You appear to have Oracle support enabled') . '<br>' . "\n";
$supported_db[] = 'oracle';
}
else
{ {
$detected .= lang('No Oracle-DB support found. Disabling') . '<br>' . "\n"; $detected .= lang('No Oracle-DB support found. Disabling') . '<br>' . "\n";
} }
}
*/
if(!count($supported_db)) if(!count($supported_db))
{ {
$detected .= '<b><p align="center" class="msg">' $detected .= '<b><p align="center" class="msg">'
@ -327,12 +343,12 @@
echo $detected; echo $detected;
exit; exit;
} }
else if (check_load_extension('session'))
{ {
$detected .= lang('You appear to be using PHP4. Enabling PHP4 sessions support') . '<br>' . "\n"; $detected .= lang('You appear to have PHP4 session support. Enabling PHP4 sessions.') . '<br>' . "\n";
$supported_sessions_type[] = 'php4'; // makeing php4 sessions the default $supported_sessions_type[] = 'php4'; // makeing php4 sessions the default
$supported_sessions_type[] = 'db';
} }
$supported_sessions_type[] = 'db';
@reset($default_db_ports); @reset($default_db_ports);
$js_default_db_ports = 'var default_db_ports = new Array();'."\n"; $js_default_db_ports = 'var default_db_ports = new Array();'."\n";
@ -343,7 +359,7 @@
$setup_tpl->set_var('js_default_db_ports',$js_default_db_ports); $setup_tpl->set_var('js_default_db_ports',$js_default_db_ports);
/* /*
if(extension_loaded('xml') || function_exists('xml_parser_create')) if(check_load_extension('xml') || function_exists('xml_parser_create'))
{ {
$detected .= lang('You appear to have XML support enabled') . '<br>' . "\n"; $detected .= lang('You appear to have XML support enabled') . '<br>' . "\n";
$xml_enabled = 'True'; $xml_enabled = 'True';
@ -503,7 +519,7 @@
/* These are a few of the advanced settings */ /* These are a few of the advanced settings */
$GLOBALS['phpgw_info']['server']['db_persistent'] = True; $GLOBALS['phpgw_info']['server']['db_persistent'] = True;
$GLOBALS['phpgw_info']['server']['mcrypt_enabled'] = extension_loaded('mcrypt'); $GLOBALS['phpgw_info']['server']['mcrypt_enabled'] = check_load_extension('mcrypt');
$GLOBALS['phpgw_info']['server']['versions']['mcrypt'] = ''; $GLOBALS['phpgw_info']['server']['versions']['mcrypt'] = '';
srand((double)microtime()*1000000); srand((double)microtime()*1000000);