- updated documentation

- add feature to allow apps to choose to be automatic installed on
  updated: $setup_info[$app]['autoinstall'] = {true|'1.x.xxx'};
- run default_records.inc.php (if exists) also for apps without tables,
  as they might need to initialise some stuff
This commit is contained in:
Ralf Becker 2009-05-28 11:33:30 +00:00
parent 88c9aca3f3
commit 6503d6d0cc
3 changed files with 676 additions and 619 deletions

View File

@ -127,7 +127,7 @@ if(@get_var('submit',Array('POST')))
{
$app_title = $setup_info[$appname]['title'] ? $setup_info[$appname]['title'] : $setup_info[$appname]['name'];
$terror = array();
$terror[] = $setup_info[$appname];
$terror[$appname] = $setup_info[$appname];
if ($setup_info[$appname]['tables'])
{
@ -162,7 +162,7 @@ if(@get_var('submit',Array('POST')))
{
$app_title = $setup_info[$appname]['title'] ? $setup_info[$appname]['title'] : $setup_info[$appname]['name'];
$terror = array();
$terror[] = $setup_info[$appname];
$terror[$appname] = $setup_info[$appname];
if ($setup_info[$appname]['tables'])
{
@ -173,6 +173,8 @@ if(@get_var('submit',Array('POST')))
}
else
{
// check default_records for apps without tables, they might need some initial work too
$terror = $GLOBALS['egw_setup']->process->default_records($terror,$DEBUG);
if ($GLOBALS['egw_setup']->app_registered($setup_info[$appname]['name']))
{
$GLOBALS['egw_setup']->update_app($setup_info[$appname]['name']);
@ -199,7 +201,7 @@ if(@get_var('submit',Array('POST')))
{
$app_title = $setup_info[$appname]['title'] ? $setup_info[$appname]['title'] : $setup_info[$appname]['name'];
$terror = array();
$terror[] = $setup_info[$appname];
$terror[$appname] = $setup_info[$appname];
$GLOBALS['egw_setup']->process->upgrade($terror,$DEBUG);
if ($setup_info[$appname]['tables'])

View File

@ -6,12 +6,21 @@
* @package setup
* @author Dan Kuykendall <seek3r@phpgroupware.org>
* @author Miles Lott <milos@groupwhere.org>
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/**
* Class detecting the current installation status of EGroupware
*/
class setup_detection
{
/**
* Get available application versions and data from filesystem
*
* @return array $setup_info
*/
function get_versions()
{
$d = dir(EGW_SERVER_ROOT);
@ -34,7 +43,13 @@ class setup_detection
return $setup_info;
}
function get_db_versions($setup_info='')
/**
* Get versions of installed applications from database
*
* @param array $setup_info
* @return array $setup_info
*/
function get_db_versions($setup_info=null)
{
$tname = Array();
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no';
@ -97,15 +112,16 @@ class setup_detection
return $setup_info;
}
/* app status values:
U Upgrade required/available
R upgrade in pRogress
C upgrade Completed successfully
D Dependency failure
P Post-install 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)
/**
* Compare versions from filesystem and database and set status:
* U Upgrade required/available
* R upgrade in pRogress
* C upgrade Completed successfully
* D Dependency failure
* P Post-install 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)
*/
function compare_versions($setup_info)
{
@ -208,9 +224,9 @@ class setup_detection
return $setup_info;
}
/*
Called during the mass upgrade routine (Stage 1) to check for apps
that wish to be excluded from this process.
/**
* Called during the mass upgrade routine (Stage 1) to check for apps
* that wish to be excluded from this process.
*/
function upgrade_exclude($setup_info)
{
@ -224,6 +240,11 @@ class setup_detection
return $setup_info;
}
/**
* Check if header exists and is up to date
*
* @return int 1=no header.inc.php, 2=no header admin pw, 3=no instances, 4=need upgrade, 10=ok
*/
function check_header()
{
if(!file_exists('../header.inc.php'))
@ -254,6 +275,12 @@ class setup_detection
return '10';
}
/**
* Check if database exists
*
* @param array $setup_info
* @return int 1=no database, 3=empty, 4=need upgrade, 10=complete
*/
function check_db($setup_info='')
{
$setup_info = $setup_info ? $setup_info : $GLOBALS['setup_info'];

View File

@ -1,41 +1,54 @@
<?php
/**************************************************************************\
* eGroupWare - Setup *
* http://www.egroupware.org *
* -------------------------------------------- *
* This file written by Miles Lott <milos@groupwhere.org> *
* Originally written for phpGroupWare. *
* (C) 2001-2004 Miles Lott *
* Upgrade process rewritten by <RalfBecker@outdoor-training.de> to no *
* longer require tables_baseline files and delta-upgrades *
* -------------------------------------------- *
* 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$ */
/* 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)
/**
* EGroupware setup - update / install an EGroupware instance
*
* @link http://www.egroupware.org
* @author Miles Lott <milos@groupwhere.org>
* @copyright 2001-2004 Miles Lott <milos@groupwhere.org>
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* Upgrade process rewritten by <RalfBecker@outdoor-training.de> to no longer require tables_baseline files and delta-upgrades
* @package setup
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/**
* Update / install an EGroupware instance
*
* 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
{
var $oProc;
var $tables;
var $updateincluded = array();
/**
* Target version of a complete upgrade, set by pass()
*
* @var string
*/
var $api_version_target;
/**
* instance of setup's translation class
*
* @var setup_translation
*/
var $translation;
function setup_process()
/**
* Constructor
*/
function __construct()
{
$this->translation =& CreateObject('setup.setup_translation');
$this->translation = new setup_translation();
}
/**
@ -45,7 +58,7 @@
*/
function init_process()
{
$GLOBALS['egw_setup']->oProc =& CreateObject('phpgwapi.schema_proc');
$GLOBALS['egw_setup']->oProc = new schema_proc();
}
/**
@ -58,7 +71,7 @@
* @param string $system_charset=null charset to use
* @param array $preset_config=array()
*/
function pass($setup_info,$method='new',$DEBUG=False,$force_en=False,$preset_config=array())
function pass(array $setup_info,$method='new',$DEBUG=False,$force_en=False,$preset_config=array())
{
if(!$method)
{
@ -68,10 +81,14 @@
$pass['phpgwapi'] = $setup_info['phpgwapi'];
$pass['admin'] = $setup_info['admin'];
$pass['preferences'] = $setup_info['preferences'];
$pass['etemplate'] = $setup_info['etemplate']; // helps to minimize passes, as many apps depend on it
@reset($setup_info);
$setup_info = $GLOBALS['egw_setup']->detection->get_versions($setup_info);
@reset($setup_info);
// setting api-target-version for general use
$this->api_version_target = $setup_info['phpgwapi']['version'];
$i = 1;
$passed = array();
$passing = array();
@ -90,7 +107,7 @@
//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))
foreach($setup_info as $key => $value)
{
if (isset($value['only_db']) && (
is_array($value['only_db']) && !in_array($GLOBALS['egw_setup']->db->Type,$value['only_db']) ||
@ -98,20 +115,13 @@
{
continue; // app does not support this db-type, dont try installing it
}
if(($value['name'] != 'phpgwapi') && ($value['status'] == 'U'))
if($value['name'] != 'phpgwapi' && $value['status'] == 'U')
{
if(($passed[$value['name']]['status'] != 'F') && ($passed[$value['name']]['status'] != 'C'))
if($passed[$value['name']]['status'] != 'F' && $passed[$value['name']]['status'] != 'C')
{
$pass[$value['name']] = $setup_info[$value['name']];
}
}
/*
Now if we are on the 2nd or more passes, add api in
if (!$pass['phpgwapi'])
{
$pass['phpgwapi'] = $setup_info['phpgwapi'];
}
*/
}
switch($method)
@ -136,8 +146,7 @@
}
$pass = array();
@reset($passing);
while(list($key,$value) = @each($passing))
foreach($passing as $key => $value)
{
if($value['status'] == 'C')
{
@ -208,17 +217,25 @@
$egroupwareDirName = end($parts);
if(!$is_windows) {
if(@is_dir('/tmp')) {
if(@is_dir('/tmp'))
{
$current_config['temp_dir'] = '/tmp';
} else {
}
else
{
$current_config['temp_dir'] = '/path/to/temp/dir';
}
$current_config['files_dir'] = '/var/lib/'.$egroupwareDirName.'/'.$GLOBALS['egw_setup']->ConfigDomain.'/files';
$current_config['backup_dir'] = '/var/lib/'.$egroupwareDirName.'/'.$GLOBALS['egw_setup']->ConfigDomain.'/backup';
} else {
if(@is_dir('c:\\windows\\temp')) {
}
else
{
if(@is_dir('c:\\windows\\temp'))
{
$current_config['temp_dir'] = 'c:\\windows\\temp';
} else {
}
else
{
$current_config['temp_dir'] = 'c:\\path\\to\\temp\\dir';
}
$current_config['files_dir'] = 'c:\\Program files\\'.$egroupwareDirName.'\\'.$GLOBALS['egw_setup']->ConfigDomain.'\\files';
@ -262,7 +279,7 @@
*
* @param $setup_info array of application info from setup.inc.php files, etc.
*/
function droptables($setup_info,$DEBUG=False)
function droptables(array $setup_info,$DEBUG=False)
{
if(!@$GLOBALS['egw_setup']->oProc)
{
@ -310,26 +327,26 @@
* process current table setup in each application/setup dir
*
* @param array $setup_info array of application info from setup.inc.php files, etc.
* @param boolean $DEBUG=false
* @param boolean $DEBUG=false output further diagnostics
* @return array $setup_info
*/
function current($setup_info,$DEBUG=False)
function current(array $setup_info,$DEBUG=False)
{
if(!@$GLOBALS['egw_setup']->oProc)
//echo __METHOD__; _debug_array($setup_info);
if(!isset($GLOBALS['egw_setup']->oProc))
{
$this->init_process();
}
@reset($setup_info);
while(list($key,$null) = @each($setup_info))
foreach($setup_info as $appname => &$appdata)
{
$enabled = False;
$appname = $setup_info[$key]['name'];
$apptitle = $setup_info[$key]['title'];
$apptitle = $appdata['title'];
if($DEBUG) { echo '<br>process->current(): Incoming status: ' . $appname . ',status: '. $setup_info[$key]['status']; }
if($DEBUG) { echo '<br>process->current(): Incoming status: ' . $appname . ',status: '. $appdata['status']; }
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP;
if($setup_info[$key]['tables'] && file_exists($appdir.'tables_current.inc.php'))
if($appdata['tables'] && file_exists($appdir.'tables_current.inc.php'))
{
if($DEBUG) { echo '<br>process->current(): Including: ' . $appdir.'tables_current.inc.php'; }
include ($appdir.'tables_current.inc.php');
@ -347,13 +364,13 @@
$GLOBALS['egw_setup']->register_hooks($appname);
}
// Update the array values for return below
$setup_info[$key]['status'] = 'C';
$appdata['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';
if($DEBUG) { echo '<br>process->current(): Failed for ' . $appname . ',status: '. $appdata['status']; }
$appdata['status'] = 'F';
}
}
else
@ -364,7 +381,7 @@
A manual sql script install is needed, but we do add the hooks
*/
$enabled = 99;
if($setup_info[$key]['tables'][0] != '')
if($appdata['tables'][0] != '')
{
$enabled = False;
}
@ -378,33 +395,34 @@
$GLOBALS['egw_setup']->register_app($appname,$enabled);
$GLOBALS['egw_setup']->register_hooks($appname);
}
$setup_info[$key]['status'] = 'C';
$appdata['status'] = 'C';
}
if($DEBUG) { echo '<br>process->current(): Outgoing status: ' . $appname . ',status: '. $setup_info[$key]['status']; }
if($DEBUG) { echo '<br>process->current(): Outgoing status: ' . $appname . ',status: '. $appdata['status']; }
}
/* Done, return current status */
return ($setup_info);
return $setup_info;
}
/**
* process default_records.inc.php in each application/setup dir
*
* @param $setup_info array of application info from setup.inc.php files, etc.
* @param array $setup_info array of application info from setup.inc.php files, etc.
* @param boolean $DEBUG=false output further diagnostics
* @return array $setup_info
*/
function default_records($setup_info,$DEBUG=False)
function default_records(array $setup_info,$DEBUG=False)
{
//echo __METHOD__; _debug_array($setup_info);
if(!@$GLOBALS['egw_setup']->oProc)
{
$this->init_process();
}
@reset($setup_info);
while(list($key,$null) = @each($setup_info))
foreach($setup_info as $appname => &$appdata)
{
$appname = $setup_info[$key]['name'];
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP;
if($setup_info[$key]['tables'] && file_exists($appdir.'default_records.inc.php'))
if(file_exists($appdir.'default_records.inc.php'))
{
if($DEBUG)
{
@ -415,7 +433,7 @@
include ($appdir.'default_records.inc.php');
$GLOBALS['egw_setup']->oProc->m_odb->transaction_commit();
}
/* $setup_info[$key]['status'] = 'C'; */
/* $appdata['status'] = 'C'; */
}
/* Done, return current status */
@ -426,18 +444,19 @@
* 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.
*
* @param array $setup_info array of application info from setup.inc.php files, etc.
* @param boolean $DEBUG=false output further diagnostics
* @return array $setup_info
*/
function test_data($setup_info,$DEBUG=False)
function test_data(array $setup_info,$DEBUG=False)
{
if(!@$GLOBALS['egw_setup']->oProc)
{
$this->init_process();
}
@reset($setup_info);
while(list($key,$null) = @each($setup_info))
foreach($setup_info as $appname => &$appdata)
{
$appname = $setup_info[$key]['name'];
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP;
if(file_exists($appdir.'test_data.inc.php'))
@ -459,19 +478,18 @@
/**
* process baseline table setup in each application/setup dir
*
* @param $appinfo array of application info from setup.inc.php files, etc.
* @param array $setup_info array of application info from setup.inc.php files, etc.
* @param boolean $DEBUG=false output further diagnostics
* @return array $setup_info
*/
function baseline($setup_info,$DEBUG=False)
function baseline(array $setup_info,$DEBUG=False)
{
if(!@$GLOBALS['egw_setup']->oProc)
{
$this->init_process();
}
@reset($setup_info);
while(list($key,$null) = @each($setup_info))
foreach($setup_info as $appname => &$appdata)
{
$appname = $setup_info[$key]['name'];
$appdir = EGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP;
if(file_exists($appdir.'tables_baseline.inc.php'))
@ -504,22 +522,34 @@
/**
* process available upgrades in each application/setup dir
*
* @param $appinfo array of application info from setup.inc.php files, etc.
* @param array $setup_info array of application info from setup.inc.php files, etc.
* @param boolean $DEBUG=false output further diagnostics
* @return array $setup_info
*/
function upgrade($setup_info,$DEBUG=False)
{
//echo __METHOD__; _debug_array($setup_info);
if(!@$GLOBALS['egw_setup']->oProc)
{
$this->init_process();
}
$GLOBALS['egw_setup']->oProc->m_odb->HaltOnError = 'yes';
foreach($setup_info as $key => $appdata)
foreach($setup_info as $appname => &$appdata)
{
$appname = $appdata['name'];
/* Don't try to upgrade an app that is not installed */
// check if app is NOT installed
if(!$GLOBALS['egw_setup']->app_registered($appname))
{
// check if app wants to be automatically installed on update to version x or allways
if (isset($appdata['autoinstall']) && ($appdata['autoinstall'] === true ||
$appdata['autoinstall'] === $this->api_version_target))
{
$info = $this->current(array($appname => $appdata),$DEBUG);
$info = $this->default_records($info,$DEBUG);
$appdata = $info[$appname];
continue;
}
/* Don't try to upgrade an app that is not installed */
if($DEBUG)
{
echo "<p>process->upgrade(): Application not installed: $appname</p>\n";
@ -583,7 +613,7 @@
{
echo "<br><b>process->upgrade(): No table upgrade available for appname: $appname, version: $currentver</b>\n";
}
$setup_info[$key]['currentver'] = $targetver;
$appdate['currentver'] = $targetver;
$appstatus = 'F';
}
}
@ -597,7 +627,7 @@
}
if ($appstatus == 'C') // update successful completed
{
$setup_info[$key]['currentver'] = $targetver;
$appdata['currentver'] = $targetver;
if($GLOBALS['egw_setup']->app_registered($appname))
{
@ -625,11 +655,11 @@
{
echo "<br>process->upgrade(): Outgoing : appname: $appname, status: $appstatus</div>\n";
}
$setup_info[$key]['status'] = $appstatus;
$appdate['status'] = $appstatus;
}
/* Done, return current status */
return ($setup_info);
return $setup_info;
}
/**
@ -642,7 +672,6 @@
{
return False;
}
return $GLOBALS['egw_setup']->oProc->ExecuteScripts($tables,$DEBUG);
}
@ -677,4 +706,3 @@
return array($arr,$pk,$fk,$ix,$uc);
}
}
?>