setup-cli / post_install command to install/update a single (non-default) app

This commit is contained in:
Ralf Becker 2011-06-18 10:44:56 +00:00
parent 65a8e4e8d3
commit 17ce63390c
5 changed files with 92 additions and 28 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/php
<?php
/**
* eGroupWare - RPM post install: automatic install or update EGroupware
* EGroupware - RPM post install: automatic install or update EGroupware
*
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
@ -59,6 +59,7 @@ $config = array(
'postfix' => '', // see setup-cli.php --help config
'cyrus' => '',
'sieve' => '',
'install-update-app' => '', // install or update a single (non-default) app
);
// read language from LANG enviroment variable
@ -109,7 +110,7 @@ function set_distro_defaults($distro=null)
$config['start_webserver'] = '/usr/sbin/service apache2';
}
else
{
{
$config['start_db'] = '/etc/init.d/mysql';
$config['start_webserver'] = '/etc/init.d/apache2';
}
@ -350,7 +351,7 @@ else
register_shutdown_function('patch_header',$config['header'],$config['config_user'],$old_password);
// update egroupware
$setup_update = $setup_cli.' --update '.escapeshellarg('all,'.$config['config_user'].','.$config['config_passwd']);
$setup_update = $setup_cli.' --update '.escapeshellarg('all,'.$config['config_user'].','.$config['config_passwd'].',,'.$config['install-update-app']);
$ret = run_cmd($setup_update,$output,array(4,15));
switch($ret)

View File

@ -208,9 +208,24 @@ abstract class setup_cmd extends admin_cmd
}
}
/**
* Applications which are currently not installed (set after call to check_installed, for the last/only domain only)
*
* @var array
*/
static public $apps_to_install=array();
/**
* Applications which are currently need update (set after call to check_installed, for the last/only domain only)
*
* @var array
*/
static public $apps_to_upgrade=array();
/**
* Check if eGW is installed, which versions and if an update is needed
*
* Sets self::$apps_to_update and self::$apps_to_install for the last/only domain only!
*
* @param string $domain='' domain to check, default '' = all
* @param int/array $stop=0 stop checks before given exit-code(s), default 0 = all checks
* @param boolean $verbose=false echo messages as they happen, instead returning them
@ -306,30 +321,29 @@ abstract class setup_cmd extends admin_cmd
case 4: throw new egw_exception_wrong_userinput(lang('eGroupWare API needs a database (schema) update from version %1 to %2!',$setup_info['phpgwapi']['currentver'],$versions['phpgwapi']).' '.lang('Use --update to do so.'),14);
case 10: // also check apps of updates
$apps_to_upgrade = array();
$apps_to_install = array();
self::$apps_to_upgrade = self::$apps_to_install = array();
foreach($setup_info as $app => $data)
{
if ($data['currentver'] && $data['version'] && $data['version'] != 'deleted' && $data['version'] != $data['currentver'])
{
$apps_to_upgrade[] = $app;
self::$apps_to_upgrade[] = $app;
}
if (!isset($data['enabled']))
{
$apps_to_install[] = $app;
self::$apps_to_install[] = $app;
}
}
if ($apps_to_install)
if (self::$apps_to_install)
{
self::_echo_message($verbose);
$messages[] = self::_echo_message($verbose,lang('The following applications are NOT installed:').' '.implode(', ',$apps_to_install));
$messages[] = self::_echo_message($verbose,lang('The following applications are NOT installed:').' '.implode(', ',self::$apps_to_install));
}
if ($apps_to_upgrade)
if (self::$apps_to_upgrade)
{
$db_stage = 4;
if ($stop && in_array(10+$db_stage,$stop)) return $messages;
throw new egw_exception_wrong_userinput(lang('The following applications need to be upgraded:').' '.implode(', ',$apps_to_upgrade).'! '.lang('Use --update to do so.'),14);
throw new egw_exception_wrong_userinput(lang('The following applications need to be upgraded:').' '.implode(', ',self::$apps_to_upgrade).'! '.lang('Use --update to do so.'),14);
}
break;
}

View File

@ -28,8 +28,9 @@ class setup_cmd_update extends setup_cmd
* @param string $config_passwd=null pw of above user
* @param string $backup=null filename of backup to use instead of new install, default new install
* @param boolean $verbose=false if true, echos out some status information during the run
* @param string $app=null single application to update or install
*/
function __construct($domain,$config_user=null,$config_passwd=null,$backup=null,$verbose=false)
function __construct($domain,$config_user=null,$config_passwd=null,$backup=null,$verbose=false,$app=null)
{
if (!is_array($domain))
{
@ -39,6 +40,7 @@ class setup_cmd_update extends setup_cmd
'config_passwd' => $config_passwd,
'backup' => $backup,
'verbose' => $verbose,
'app' => $app,
);
}
//echo __CLASS__.'::__construct()'; _debug_array($domain);
@ -46,7 +48,7 @@ class setup_cmd_update extends setup_cmd
}
/**
* run the command: update
* run the command: update or install/update a single app ($this->app)
*
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
* @return string serialized $GLOBALS defined in the header.inc.php
@ -62,17 +64,57 @@ class setup_cmd_update extends setup_cmd
$this->check_installed($this->domain,array(14),$this->verbose);
if ($GLOBALS['egw_info']['setup']['stage']['db'] != 4)
if ($GLOBALS['egw_info']['setup']['stage']['db'] != 4 &&
(!$this->app || !in_array($this->app, self::$apps_to_install) && !in_array($this->app, self::$apps_to_upgrade)))
{
return lang('No update necessary, domain %1(%2) is up to date.',$this->domain,$GLOBALS['egw_domain'][$this->domain]['db_type']);
}
$setup_info = self::$egw_setup->detection->upgrade_exclude($setup_info);
self::_echo_message($this->verbose,lang('Start updating the database ...'));
ob_start();
self::$egw_setup->process->init_process(); // we need a new schema-proc instance for each new domain
self::$egw_setup->process->pass($setup_info,'upgrade',false);
// request to install a single app
if ($this->app && in_array($this->app, self::$apps_to_install))
{
$app_title = $setup_info[$this->app]['title'] ? $setup_info[$this->app]['title'] : $setup_info[$this->app]['name'];
self::_echo_message($this->verbose,lang('Start installing application %1 ...',$app_title));
ob_start();
$terror = array($this->app => $setup_info[$this->app]);
if ($setup_info[$this->app]['tables'])
{
$terror = self::$egw_setup->process->current($terror,$DEBUG);
$terror = self::$egw_setup->process->default_records($terror,$DEBUG);
echo $app_title . ' ' . lang('tables installed, unless there are errors printed above') . '.';
}
else
{
// check default_records for apps without tables, they might need some initial work too
$terror = self::$egw_setup->process->default_records($terror,$DEBUG);
if (self::$egw_setup->app_registered($setup_info[$this->app]['name']))
{
self::$egw_setup->update_app($setup_info[$this->app]['name']);
}
else
{
self::$egw_setup->register_app($setup_info[$this->app]['name']);
}
echo $app_title . ' ' . lang('registered') . '.';
if ($setup_info[$this->app]['hooks'])
{
self::$egw_setup->register_hooks($setup_info[$this->app]['name']);
echo "\n".$app_title . ' ' . lang('hooks registered') . '.';
}
}
self::$egw_setup->process->translation->drop_add_all_langs(false,$this->app);
}
else
{
self::_echo_message($this->verbose,lang('Start updating the database ...'));
ob_start();
self::$egw_setup->process->pass($setup_info,'upgrade',false);
}
$messages = ob_get_contents();
ob_end_clean();
if ($messages && $this->verbose) echo strip_tags($messages)."\n";

View File

@ -116,18 +116,24 @@ class setup_translation
return translation::add_langs($appname,$DEBUG,$force_langs);
}
static function drop_add_all_langs($langs=False)
/**
* installs translations for the selected langs into the database
*
* @param array|boolean $langs langs to install (as data NOT keys (!))
* @param string|boolean $only_app=false app-name to install only one app or default false for all
*/
static function drop_add_all_langs($langs=false,$only_app=false)
{
if (!$langs && !count($langs = translation::get_langs()))
{
$langs[] = 'en';
}
return translation::install_langs($langs,'dumpold');
return translation::install_langs($langs,'dumpold',$only_app);
}
/**
* Languages we support (alphabetically sorted)
*
*
* @param boolean $array_values=true true: values are an array, false values are just the descriptiong
* @return array
*/
@ -150,7 +156,7 @@ class setup_translation
}
}
fclose($f);
if ($array_values)
{
$d = dir(EGW_SERVER_ROOT.'/setup/lang');

View File

@ -247,15 +247,15 @@ function do_backup($arg,$quite_check=false)
}
/**
* Update one or all domains
* Update one or all domains, optional install a given app
*
* @param string $arg domain(all),[config user(admin)],password,[backup-file, 'no' for no backup or empty for default name]
* @param string $arg domain(all),[config user(admin)],password,[backup-file, 'no' for no backup or empty for default name],[app to install or uppdate]
*/
function do_update($arg)
{
global $setup_info;
list($domain,$user,$password,$backup) = explode(',',$arg);
list($domain,$user,$password,$backup,$app) = explode(',',$arg);
_fetch_user_password($user,$password);
$domains = $GLOBALS['egw_domain'];
@ -269,7 +269,8 @@ function do_update($arg)
_check_auth_config($arg,14);
if ($GLOBALS['egw_info']['setup']['stage']['db'] != 4)
if ($GLOBALS['egw_info']['setup']['stage']['db'] != 4 &&
(!$app || !in_array($app, setup_cmd::$apps_to_install) && !in_array($app, setup_cmd::$apps_to_upgrade)))
{
echo lang('No update necessary, domain %1(%2) is up to date.',$domain,$data['db_type'])."\n";
}
@ -277,7 +278,7 @@ function do_update($arg)
{
do_backup($arg,true);
$cmd = new setup_cmd_update($domain,$user,$password,$backup,true);
$cmd = new setup_cmd_update($domain,$user,$password,$backup,true,$app);
echo $cmd->run()."\n";
}
}
@ -501,7 +502,7 @@ function do_usage($what='')
echo '--admin '.lang('creates an admin user: domain(default),[config user(admin)],password,username,password,[first name],[last name],[email]')."\n";
echo '--language '.lang('install or update translations: domain(all),[config user(admin)],password,[[+]lang1[,lang2,...]] + adds, no langs update existing ones')."\n";
echo '--backup '.lang('domain(all),[config user(admin)],password,[file-name(default: backup-dir/db_backup-YYYYMMDDHHii)]')."\n";
echo '--update '.lang('run a database schema update (if necessary): domain(all),[config user(admin)],password').'[,no = no backup]'."\n";
echo '--update '.lang('run a database schema update (if necessary): domain(all),[config user(admin)],password').'[,[no = no backup][,app to install]]'."\n";
echo lang('You can use the header user and password for every domain too. If the password is not set via the commandline, it is read from the enviroment variable EGW_CLI_PASSWORD or queried from the user.')."\n";
}
if (!$what || $what == 'header')