2002-03-03 22:47:30 +01:00
< ? php
2002-12-20 00:33:44 +01:00
/************************************************************************** \
2003-12-28 16:19:25 +01:00
* eGroupWare - Setup *
* http :// www . egroupware . org *
2002-12-20 00:33:44 +01:00
* -------------------------------------------- *
2003-12-28 16:19:25 +01:00
* This file written by Miles Lott < milos @ groupwhere . org > *
* Originally written for phpGroupWare . *
* ( C ) 2001 - 2004 Miles Lott *
2004-10-23 17:00:44 +02:00
* Upgrade process rewritten by < RalfBecker @ outdoor - training . de > to no *
* longer require tables_baseline files and delta - upgrades *
2002-12-20 00:33:44 +01:00
* -------------------------------------------- *
* 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$ */
2002-03-03 22:47:30 +01:00
/* app status values :
U Upgrade required / available
R upgrade in pRogress
C upgrade Completed successfully
D Dependency failure
F upgrade Failed
V Version mismatch at end of upgrade ( Not used , proposed only )
M Missing files at start of upgrade ( Not used , proposed only )
*/
class setup_process
{
2002-03-04 06:00:08 +01:00
var $oProc ;
2002-03-03 22:47:30 +01:00
var $tables ;
var $updateincluded = array ();
2002-09-04 03:25:29 +02:00
var $translation ;
2003-12-20 19:34:55 +01:00
function setup_process ()
2002-09-04 03:25:29 +02:00
{
2005-03-24 14:15:12 +01:00
$this -> translation =& CreateObject ( 'setup.setup_translation' );
2002-09-04 03:25:29 +02:00
}
2002-03-03 22:47:30 +01:00
2005-03-24 14:15:12 +01:00
/**
* create schema_proc object
*
* @ param none
*/
2002-03-03 22:47:30 +01:00
function init_process ()
{
2005-03-24 14:15:12 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc =& CreateObject ( 'phpgwapi.schema_proc' );
2002-03-03 22:47:30 +01:00
}
2005-03-24 14:15:12 +01:00
/**
* the mother of all multipass upgrade parental loop functions
*
2005-11-04 19:35:09 +01:00
* @ param array $setup_info array of application info from setup . inc . php files
* @ param string $type = 'new' defaults to new ( install ), could also be 'upgrade'
* @ param boolean $DEBUG = false print debugging info
* @ param boolean $force_en = false install english language files
* @ param string $system_charset = null charset to use
2005-03-24 14:15:12 +01:00
*/
2005-11-27 08:48:22 +01:00
function pass ( $setup_info , $method = 'new' , $DEBUG = False , $force_en = False )
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( ! $method )
2002-03-03 22:47:30 +01:00
{
return False ;
}
// Place api first
2003-12-20 19:34:55 +01:00
$pass [ 'phpgwapi' ] = $setup_info [ 'phpgwapi' ];
$pass [ 'admin' ] = $setup_info [ 'admin' ];
$pass [ 'preferences' ] = $setup_info [ 'preferences' ];
2002-03-03 22:47:30 +01:00
@ reset ( $setup_info );
2005-03-04 16:00:33 +01:00
$setup_info = $GLOBALS [ 'egw_setup' ] -> detection -> get_versions ( $setup_info );
2002-03-03 22:47:30 +01:00
@ reset ( $setup_info );
$i = 1 ;
$passed = array ();
$passing = array ();
$pass_string = implode ( ':' , $pass );
$passing_string = implode ( ':' , $passing );
2004-10-23 17:00:44 +02:00
$do_langs = false ;
2002-03-04 08:18:46 +01:00
while ( $pass_string != $passing_string )
2002-03-03 22:47:30 +01:00
{
$passing = array ();
2002-03-04 08:18:46 +01:00
if ( $DEBUG ) { echo '<br>process->pass(): #' . $i . ' for ' . $method . ' processing' . " \n " ; }
2002-03-03 22:47:30 +01:00
/* Check current versions and dependencies */
2005-03-04 16:00:33 +01:00
$setup_info = $GLOBALS [ 'egw_setup' ] -> detection -> get_db_versions ( $setup_info );
$setup_info = $GLOBALS [ 'egw_setup' ] -> detection -> compare_versions ( $setup_info );
2002-03-03 22:47:30 +01:00
//_debug_array($setup_info);exit;
2005-03-04 16:00:33 +01:00
$setup_info = $GLOBALS [ 'egw_setup' ] -> detection -> check_depends ( $setup_info );
2002-03-03 22:47:30 +01:00
//if($i==2) { _debug_array($passed);exit; }
/* stuff the rest of the apps, but only those with available upgrades */
while ( list ( $key , $value ) = @ each ( $setup_info ))
{
2004-08-13 20:59:00 +02:00
if ( isset ( $value [ 'only_db' ]) && (
2005-03-04 16:00:33 +01:00
is_array ( $value [ 'only_db' ]) && ! in_array ( $GLOBALS [ 'egw_setup' ] -> db -> Type , $value [ 'only_db' ]) ||
! is_array ( $value [ 'only_db' ]) && $GLOBALS [ 'egw_setup' ] -> db -> Type != $value [ 'only_db' ]))
2004-08-13 20:59:00 +02:00
{
continue ; // app does not support this db-type, dont try installing it
}
2002-03-04 08:18:46 +01:00
if (( $value [ 'name' ] != 'phpgwapi' ) && ( $value [ 'status' ] == 'U' ))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if (( $passed [ $value [ 'name' ]][ 'status' ] != 'F' ) && ( $passed [ $value [ 'name' ]][ 'status' ] != 'C' ))
2002-03-03 22:47:30 +01:00
{
$pass [ $value [ 'name' ]] = $setup_info [ $value [ 'name' ]];
}
}
/*
Now if we are on the 2 nd or more passes , add api in
if ( ! $pass [ 'phpgwapi' ])
{
$pass [ 'phpgwapi' ] = $setup_info [ 'phpgwapi' ];
}
*/
}
2003-12-20 19:34:55 +01:00
switch ( $method )
2002-03-03 22:47:30 +01:00
{
case 'new' :
/* Create tables and insert new records for each app in this list */
$passing = $this -> current ( $pass , $DEBUG );
2005-11-27 08:48:22 +01:00
$this -> save_minimal_config ();
2002-03-03 22:47:30 +01:00
$passing = $this -> default_records ( $passing , $DEBUG );
2004-10-23 17:00:44 +02:00
$do_langs = true ; // just do it once at the end of all passes
2002-03-03 22:47:30 +01:00
break ;
case 'upgrade' :
/* Run upgrade scripts on each app in the list */
$passing = $this -> upgrade ( $pass , $DEBUG );
2004-10-23 17:00:44 +02:00
$do_langs = true ; // just do it once at the end of all passes
2002-03-03 22:47:30 +01:00
//_debug_array($pass);exit;
break ;
default :
/* What the heck are you doing? */
return False ;
break ;
}
$pass = array ();
@ reset ( $passing );
while ( list ( $key , $value ) = @ each ( $passing ))
{
if ( $value [ 'status' ] == 'C' )
{
$passed [ $value [ 'name' ]] = $passing [ $value [ 'name' ]];
2002-03-04 08:18:46 +01:00
if ( $DEBUG ) { echo '<br>process->pass(): ' . $passed [ $value [ 'name' ]][ 'name' ] . ' install completed' . " \n " ; }
2002-03-03 22:47:30 +01:00
}
elseif ( $value [ 'status' ] == 'F' )
{
$setup_info [ $value [ 'name' ]] = $passing [ $value [ 'name' ]];
2002-03-04 08:18:46 +01:00
if ( $DEBUG ) { echo '<br>process->pass(): ' . $setup_info [ $value [ 'name' ]][ 'name' ] . ' install failed' . " \n " ; }
2002-03-03 22:47:30 +01:00
}
elseif ( $value [ 'status' ] == 'D' )
{
$pass [ $value [ 'name' ]] = $setup_info [ $value [ 'name' ]];
2002-03-04 08:18:46 +01:00
if ( $DEBUG ) { echo '<br>process->pass(): ' . $pass [ $value [ 'name' ]][ 'name' ] . ' fails dependency check on this pass' . " \n " ; }
2002-03-03 22:47:30 +01:00
}
else
{
$tmp = $passing [ $value [ 'name' ]][ 'name' ];
2002-03-04 08:18:46 +01:00
if ( $DEBUG ) { echo '<br>process->pass(): ' . $tmp . ' skipped on this pass' . " \n " ; }
2002-03-03 22:47:30 +01:00
}
}
$i ++ ;
2002-03-04 08:18:46 +01:00
if ( $i == 20 ) /* Then oops it broke */
2002-03-03 22:47:30 +01:00
{
echo '<br>Setup failure: excess looping in process->pass():' . " \n " ;
echo '<br>Pass:<br>' . " \n " ;
_debug_array ( $pass );
echo '<br>Passed:<br>' . " \n " ;
_debug_array ( $passed );
exit ;
}
$pass_string = implode ( ':' , $pass );
$passing_string = implode ( ':' , $passing );
}
2004-10-23 17:00:44 +02:00
if ( $do_langs ) // just do it once at the end of all passes
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
$langs = false ;
if ( $method == 'new' )
{
$langs [] = ( $own_lang = get_var ( 'ConfigLang' , Array ( 'POST' , 'COOKIE' )));
if ( $own_lang != 'en' ) $langs [] = 'en' ;
}
$this -> translation -> drop_add_all_langs ( $langs );
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
/* now return the list */
return $setup_info = array_merge ( $setup_info , $passed );
2002-03-03 22:47:30 +01:00
}
2005-03-24 14:15:12 +01:00
/**
* saves a minimal default config , so you get a running install without entering and saveing Step #2 config
*
*/
2005-11-27 08:48:22 +01:00
function save_minimal_config ()
2003-10-04 15:24:34 +02:00
{
$GLOBALS [ 'current_config' ][ 'site_title' ] = 'eGroupWare' ;
$GLOBALS [ 'current_config' ][ 'hostname' ] = $_SERVER [ 'HTTP_HOST' ];
// files-dir is not longer allowed in document root, for security reasons !!!
$GLOBALS [ 'current_config' ][ 'files_dir' ] = '/outside/webserver/docroot' ;
if ( @ is_dir ( '/tmp' ))
{
$GLOBALS [ 'current_config' ][ 'temp_dir' ] = '/tmp' ;
}
2005-11-27 08:48:22 +01:00
elseif ( @ is_dir ( 'c:\\windows\\temp' ))
2004-03-21 17:25:22 +01:00
{
2005-11-27 08:48:22 +01:00
$GLOBALS [ 'current_config' ][ 'temp_dir' ] = 'c:\\windows\\temp' ;
2004-03-21 17:25:22 +01:00
}
2003-10-04 15:24:34 +02:00
else
{
$GLOBALS [ 'current_config' ][ 'temp_dir' ] = '/path/to/temp/dir' ;
}
// guessing the phpGW url
$parts = explode ( '/' , $_SERVER [ 'PHP_SELF' ]);
array_pop ( $parts ); // remove config.php
array_pop ( $parts ); // remove setup
$GLOBALS [ 'current_config' ][ 'webserver_url' ] = implode ( '/' , $parts );
2005-03-24 14:15:12 +01:00
$datetime =& CreateObject ( 'phpgwapi.datetime' );
2003-10-04 15:24:34 +02:00
$GLOBALS [ 'current_config' ][ 'tz_offset' ] = $datetime -> getbestguess ();
unset ( $datetime );
2004-03-14 12:35:33 +01:00
// RalfBecker: php.net recommend this for security reasons, it should be our default too
$GLOBALS [ 'current_config' ][ 'usecookies' ] = 'True' ;
2004-10-23 17:00:44 +02:00
2005-11-27 08:48:22 +01:00
if ( $GLOBALS [ 'egw_setup' ] -> system_charset )
2004-10-23 17:00:44 +02:00
{
2005-11-27 08:48:22 +01:00
$GLOBALS [ 'current_config' ][ 'system_charset' ] = $GLOBALS [ 'egw_setup' ] -> system_charset ;
2004-10-23 17:00:44 +02:00
}
2004-03-14 12:35:33 +01:00
2005-11-02 12:45:52 +01:00
foreach ( $GLOBALS [ 'current_config' ] as $name => $value )
2003-10-04 15:24:34 +02:00
{
2005-11-02 12:45:52 +01:00
$GLOBALS [ 'egw_setup' ] -> db -> insert ( $GLOBALS [ 'egw_setup' ] -> config_table , array (
'config_value' => $value ,
), array (
'config_app' => 'phpgwapi' ,
'config_name' => $name ,
), __FILE__ , __LINE__ );
2003-10-04 15:24:34 +02:00
}
}
2005-03-24 14:15:12 +01:00
/**
* drop tables per application , check that they are in the db first
*
* @ param $setup_info array of application info from setup . inc . php files , etc .
*/
2002-03-03 22:47:30 +01:00
function droptables ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
/* The following is built so below we won't try to drop a table that isn't there. */
2005-03-04 16:00:33 +01:00
$tablenames = $GLOBALS [ 'egw_setup' ] -> db -> table_names ();
2004-04-03 15:03:01 +02:00
if ( ! is_array ( $setup_info ) || ! is_array ( $tablenames ))
2002-03-03 22:47:30 +01:00
{
2004-04-03 15:03:01 +02:00
return $setup_info ; // nothing to do
}
$tables = array ();
foreach ( $tablenames as $data )
{
$tables [] = $data [ 'table_name' ];
2002-03-03 22:47:30 +01:00
}
2004-04-03 15:03:01 +02:00
if ( ! is_array ( $setup_info ))
2002-03-03 22:47:30 +01:00
{
2004-04-03 15:03:01 +02:00
return $setup_info ;
}
foreach ( $setup_info as $app_name => $data )
{
if ( is_array ( $data [ 'tables' ]))
2002-03-03 22:47:30 +01:00
{
2004-04-03 15:03:01 +02:00
foreach ( $data [ 'tables' ] as $table )
2002-03-03 22:47:30 +01:00
{
//echo $table;
2002-03-04 08:18:46 +01:00
if ( in_array ( $table , $tables ))
2002-03-03 22:47:30 +01:00
{
2004-04-03 15:03:01 +02:00
if ( $DEBUG ){ echo '<br>process->droptables(): Dropping :' . $app_name . ' table: ' . $table ; }
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> DropTable ( $table );
2002-03-03 22:47:30 +01:00
// Update the array values for return below
2004-04-03 15:03:01 +02:00
$setup_info [ $app_name ][ 'status' ] = 'U' ;
2002-03-03 22:47:30 +01:00
}
}
}
}
/* Done, return current status */
2004-04-03 15:03:01 +02:00
return $setup_info ;
2002-03-03 22:47:30 +01:00
}
2005-03-24 14:15:12 +01:00
/**
* process current table setup in each application / setup dir
*
2005-11-04 19:35:09 +01:00
* @ param array $setup_info array of application info from setup . inc . php files , etc .
* @ param boolean $DEBUG = false
2005-03-24 14:15:12 +01:00
*/
2002-03-03 22:47:30 +01:00
function current ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
@ reset ( $setup_info );
2002-03-04 08:18:46 +01:00
while ( list ( $key , $null ) = @ each ( $setup_info ))
2002-03-03 22:47:30 +01:00
{
$enabled = False ;
$appname = $setup_info [ $key ][ 'name' ];
$apptitle = $setup_info [ $key ][ 'title' ];
if ( $DEBUG ) { echo '<br>process->current(): Incoming status: ' . $appname . ',status: ' . $setup_info [ $key ][ 'status' ]; }
2005-03-24 14:15:12 +01:00
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP ;
2002-03-03 22:47:30 +01:00
2002-03-04 08:18:46 +01:00
if ( $setup_info [ $key ][ 'tables' ] && file_exists ( $appdir . 'tables_current.inc.php' ))
2002-03-03 22:47:30 +01:00
{
if ( $DEBUG ) { echo '<br>process->current(): Including: ' . $appdir . 'tables_current.inc.php' ; }
include ( $appdir . 'tables_current.inc.php' );
$ret = $this -> post_process ( $phpgw_baseline , $DEBUG );
if ( $ret )
{
2005-03-04 16:00:33 +01:00
if ( $GLOBALS [ 'egw_setup' ] -> app_registered ( $appname ))
2002-03-03 22:47:30 +01:00
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> update_app ( $appname );
$GLOBALS [ 'egw_setup' ] -> update_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
else
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> register_app ( $appname );
$GLOBALS [ 'egw_setup' ] -> register_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
// Update the array values for return below
$setup_info [ $key ][ 'status' ] = 'C' ;
}
else
{
/* script processing failed */
if ( $DEBUG ) { echo '<br>process->current(): Failed for ' . $appname . ',status: ' . $setup_info [ $key ][ 'status' ]; }
$setup_info [ $key ][ 'status' ] = 'F' ;
}
}
else
{
if ( $DEBUG ) { echo '<br>process->current(): No current tables for ' . $apptitle . " \n " ; }
/*
Add the app , but disable it if it has tables defined .
A manual sql script install is needed , but we do add the hooks
*/
$enabled = 99 ;
2002-03-04 08:18:46 +01:00
if ( $setup_info [ $key ][ 'tables' ][ 0 ] != '' )
2002-03-03 22:47:30 +01:00
{
$enabled = False ;
}
2005-03-04 16:00:33 +01:00
if ( $GLOBALS [ 'egw_setup' ] -> app_registered ( $appname ))
2002-03-03 22:47:30 +01:00
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> update_app ( $appname );
$GLOBALS [ 'egw_setup' ] -> update_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
else
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> register_app ( $appname , $enabled );
$GLOBALS [ 'egw_setup' ] -> register_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
$setup_info [ $key ][ 'status' ] = 'C' ;
}
if ( $DEBUG ) { echo '<br>process->current(): Outgoing status: ' . $appname . ',status: ' . $setup_info [ $key ][ 'status' ]; }
}
/* Done, return current status */
return ( $setup_info );
}
2005-03-24 14:15:12 +01:00
/**
* process default_records . inc . php in each application / setup dir
*
* @ param $setup_info array of application info from setup . inc . php files , etc .
*/
2002-03-03 22:47:30 +01:00
function default_records ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
@ reset ( $setup_info );
2002-03-04 08:18:46 +01:00
while ( list ( $key , $null ) = @ each ( $setup_info ))
2002-03-03 22:47:30 +01:00
{
$appname = $setup_info [ $key ][ 'name' ];
2005-03-24 14:15:12 +01:00
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP ;
2002-03-03 22:47:30 +01:00
2002-03-04 08:18:46 +01:00
if ( $setup_info [ $key ][ 'tables' ] && file_exists ( $appdir . 'default_records.inc.php' ))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
echo '<br>process->default_records(): Including default records for ' . $appname . " \n " ;
}
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_odb -> transaction_begin ();
$oProc = & $GLOBALS [ 'egw_setup' ] -> oProc ; // to be compatible with old apps
2002-03-03 22:47:30 +01:00
include ( $appdir . 'default_records.inc.php' );
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_odb -> transaction_commit ();
2002-03-03 22:47:30 +01:00
}
/* $setup_info[$key]['status'] = 'C'; */
}
/* Done, return current status */
return ( $setup_info );
}
2005-03-24 14:15:12 +01:00
/**
* process test_data . inc . php in each application / setup dir for developer tests
*
* This data should work with the baseline tables
* @ param $setup_info array of application info from setup . inc . php files , etc .
*/
2002-03-03 22:47:30 +01:00
function test_data ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
@ reset ( $setup_info );
2002-03-04 08:18:46 +01:00
while ( list ( $key , $null ) = @ each ( $setup_info ))
2002-03-03 22:47:30 +01:00
{
$appname = $setup_info [ $key ][ 'name' ];
2005-03-24 14:15:12 +01:00
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP ;
2002-03-03 22:47:30 +01:00
2002-03-04 08:18:46 +01:00
if ( file_exists ( $appdir . 'test_data.inc.php' ))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
echo '<br>process->test_data(): Including baseline test data for ' . $appname . " \n " ;
}
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_odb -> transaction_begin ();
2002-03-03 22:47:30 +01:00
include ( $appdir . 'test_data.inc.php' );
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_odb -> transaction_commit ();
2002-03-03 22:47:30 +01:00
}
}
/* Done, return current status */
return ( $setup_info );
}
2005-03-24 14:15:12 +01:00
/**
* process baseline table setup in each application / setup dir
*
* @ param $appinfo array of application info from setup . inc . php files , etc .
*/
2002-03-03 22:47:30 +01:00
function baseline ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
@ reset ( $setup_info );
2002-03-04 08:18:46 +01:00
while ( list ( $key , $null ) = @ each ( $setup_info ))
2002-03-03 22:47:30 +01:00
{
$appname = $setup_info [ $key ][ 'name' ];
2005-03-24 14:15:12 +01:00
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP ;
2002-03-03 22:47:30 +01:00
2002-03-04 08:18:46 +01:00
if ( file_exists ( $appdir . 'tables_baseline.inc.php' ))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
echo '<br>process->baseline(): Including baseline tables for ' . $appname . " \n " ;
}
include ( $appdir . 'tables_baseline.inc.php' );
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> GenerateScripts ( $phpgw_baseline , $DEBUG );
2002-03-03 22:47:30 +01:00
$this -> post_process ( $phpgw_baseline , $DEBUG );
/* Update the array values for return below */
/* $setup_info[$key]['status'] = 'R'; */
}
else
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
echo '<br>process->baseline(): No baseline tables for ' . $appname . " \n " ;
}
//$setup_info[$key]['status'] = 'C';
}
}
/* Done, return current status */
return ( $setup_info );
}
2005-03-24 14:15:12 +01:00
/**
* process available upgrades in each application / setup dir
*
* @ param $appinfo array of application info from setup . inc . php files , etc .
*/
2002-03-03 22:47:30 +01:00
function upgrade ( $setup_info , $DEBUG = False )
{
2005-03-04 16:00:33 +01:00
if ( !@ $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_odb -> HaltOnError = 'yes' ;
2002-03-03 22:47:30 +01:00
2004-10-23 17:00:44 +02:00
foreach ( $setup_info as $key => $appdata )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
$appname = $appdata [ 'name' ];
2002-03-03 22:47:30 +01:00
/* Don't try to upgrade an app that is not installed */
2005-03-04 16:00:33 +01:00
if ( ! $GLOBALS [ 'egw_setup' ] -> app_registered ( $appname ))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <p>process->upgrade(): Application not installed: $appname </p> \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
unset ( $setup_info [ $appname ]);
2002-03-03 22:47:30 +01:00
continue ;
}
/* if upgrade required, or if we are running again after an upgrade or dependency failure */
2004-10-23 17:00:44 +02:00
if ( $DEBUG )
{
echo '<div style="text-align: left; border: thin dashed black; margin-top: 5px;">' . " process->upgrade(): Incoming : appname: $appname , version: $appdata[currentver] , status: $appdata[status] \n " ;
}
if ( $appdata [ 'status' ] == 'U' || $appdata [ 'status' ] == 'D' || $appdata [ 'status' ] == 'V' || $appdata [ 'status' ] == '' ) // TODO this is not getting set for api upgrade, sometimes ???
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
$currentver = $appdata [ 'currentver' ];
$targetver = $appdata [ 'version' ]; // The version we need to match when done
2005-03-24 14:15:12 +01:00
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP ;
2002-03-03 22:47:30 +01:00
2002-03-04 08:18:46 +01:00
if ( file_exists ( $appdir . 'tables_update.inc.php' ) && !@ $this -> updateincluded [ $appname ])
2002-03-03 22:47:30 +01:00
{
include ( $appdir . 'tables_update.inc.php' );
$this -> updateincluded [ $appname ] = True ;
2004-10-23 17:00:44 +02:00
while ( $currentver && $currentver != $targetver &&
function_exists ( $function = $appname . '_upgrade' . str_replace ( '.' , '_' , $currentver )))
2002-03-03 22:47:30 +01:00
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br>process->upgrade(): $appname ( $currentver --> $targetver ): running $function () \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
if ( ! ( $currentver = $function ()))
2002-03-03 22:47:30 +01:00
{
if ( $DEBUG )
{
2004-10-23 17:00:44 +02:00
echo " <b>failed!!!</b> \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
$appstatus = 'F' ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
else
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " --> $currentver\n " ;
2002-03-03 22:47:30 +01:00
}
}
2004-10-23 17:00:44 +02:00
}
if ( $currentver == $targetver ) // upgrades succesful
{
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br>process->upgrade(): Upgrade of $appname to $targetver is completed. \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
$appstatus = 'C' ;
}
elseif ( $currentver )
{
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br><b>process->upgrade(): No table upgrade available for appname: $appname , version: $currentver </b> \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
$setup_info [ $key ][ 'currentver' ] = $targetver ;
$appstatus = 'F' ;
2002-03-03 22:47:30 +01:00
}
}
else
{
2004-10-23 17:00:44 +02:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br>process->upgrade(): No table upgrade required/availible for $appname\n " ;
}
$appstatus = 'C' ;
}
if ( $appstatus == 'C' ) // update successful completed
{
$setup_info [ $key ][ 'currentver' ] = $targetver ;
2002-03-03 22:47:30 +01:00
2005-03-04 16:00:33 +01:00
if ( $GLOBALS [ 'egw_setup' ] -> app_registered ( $appname ))
2004-10-23 17:00:44 +02:00
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> update_app ( $appname );
$GLOBALS [ 'egw_setup' ] -> update_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
else
{
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> register_app ( $appname );
$GLOBALS [ 'egw_setup' ] -> register_hooks ( $appname );
2002-03-03 22:47:30 +01:00
}
}
2004-10-23 17:00:44 +02:00
2002-03-03 22:47:30 +01:00
}
else
{
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br>process->upgrade(): No upgrade required for $appname\n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
$appstatus = 'C' ;
2002-03-03 22:47:30 +01:00
}
/* Done with this app, update status */
2002-03-04 08:18:46 +01:00
if ( $DEBUG )
2002-03-03 22:47:30 +01:00
{
2004-10-23 17:00:44 +02:00
echo " <br>process->upgrade(): Outgoing : appname: $appname , status: $appstatus </div> \n " ;
2002-03-03 22:47:30 +01:00
}
2004-10-23 17:00:44 +02:00
$setup_info [ $key ][ 'status' ] = $appstatus ;
2002-03-03 22:47:30 +01:00
}
/* Done, return current status */
return ( $setup_info );
}
2005-03-24 14:15:12 +01:00
/**
* commit above processing to the db
*
*/
2002-03-03 22:47:30 +01:00
function post_process ( $tables , $DEBUG = False )
{
2002-03-04 08:18:46 +01:00
if ( ! $tables )
2002-03-03 22:47:30 +01:00
{
return False ;
}
2005-11-04 19:35:09 +01:00
return $GLOBALS [ 'egw_setup' ] -> oProc -> ExecuteScripts ( $tables , $DEBUG );
2002-03-03 22:47:30 +01:00
}
2005-03-24 14:15:12 +01:00
/**
* send this a table name , returns printable column spec and keys for the table from schema_proc
*
* @ param $tablename table whose array you want to see
*/
2002-03-03 22:47:30 +01:00
function sql_to_array ( $tablename = '' )
{
2002-03-04 08:18:46 +01:00
if ( ! $tablename )
2002-03-03 22:47:30 +01:00
{
return False ;
}
2005-03-04 16:00:33 +01:00
if ( ! $GLOBALS [ 'egw_setup' ] -> oProc )
2002-03-03 22:47:30 +01:00
{
$this -> init_process ();
}
2005-03-04 16:00:33 +01:00
$GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> _GetColumns ( $GLOBALS [ 'egw_setup' ] -> oProc , $tablename , $sColumns , $sColumnName );
2002-03-03 22:47:30 +01:00
2005-03-04 16:00:33 +01:00
while ( list ( $key , $tbldata ) = each ( $GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> sCol ))
2002-03-03 22:47:30 +01:00
{
$arr .= $tbldata ;
}
2005-03-04 16:00:33 +01:00
$pk = $GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> pk ;
$fk = $GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> fk ;
$ix = $GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> ix ;
$uc = $GLOBALS [ 'egw_setup' ] -> oProc -> m_oTranslator -> uc ;
2002-03-03 22:47:30 +01:00
return array ( $arr , $pk , $fk , $ix , $uc );
}
}
2003-03-27 19:39:49 +01:00
?>