From 31960e45e20a71a901c681b749bd44097d7c5a1f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 8 Jul 2014 16:50:54 +0000 Subject: [PATCH] fixed setup-cli --update and setup_cmd_update to install apps marked as "autoinstall" --- setup/inc/class.setup_cmd.inc.php | 20 ++++++++++++++++++-- setup/inc/class.setup_cmd_update.inc.php | 15 +++++++++------ setup/setup-cli.php | 19 ++++++++----------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/setup/inc/class.setup_cmd.inc.php b/setup/inc/class.setup_cmd.inc.php index b5376ef928..05b3e88718 100644 --- a/setup/inc/class.setup_cmd.inc.php +++ b/setup/inc/class.setup_cmd.inc.php @@ -5,7 +5,7 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package setup - * @copyright (c) 2007-9 by Ralf Becker + * @copyright (c) 2007-14 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -268,7 +268,7 @@ abstract class setup_cmd extends admin_cmd $messages[] = self::_echo_message($verbose,lang('eGroupWare configuration file (header.inc.php) version %1 exists%2', $versions['header'],' '.lang('and is up to date'))); } - $header_checks = false; // no further output of the header checks + unset($header_checks); // no further output of the header checks $domains = $GLOBALS['egw_domain']; if ($domain) // domain to check given @@ -351,6 +351,22 @@ abstract class setup_cmd extends admin_cmd return $messages; } + /** + * Check if there are apps which should be autoinstalled + * + * @return array with app-names + */ + static function check_autoinstall() + { + $ret = array_filter(self::$apps_to_install, function($app) + { + global $setup_info; + return $setup_info[$app]['autoinstall']; + }); + //error_log(__METHOD__."() apps_to_install=".array2string(self::$apps_to_install).' returning '.array2string($ret)); + return $ret; + } + /** * Echo the given message, if $verbose * diff --git a/setup/inc/class.setup_cmd_update.inc.php b/setup/inc/class.setup_cmd_update.inc.php index 4be1990c23..c7a95bf5e7 100644 --- a/setup/inc/class.setup_cmd_update.inc.php +++ b/setup/inc/class.setup_cmd_update.inc.php @@ -5,7 +5,7 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package setup - * @copyright (c) 2009 by Ralf Becker + * @copyright (c) 2009-14 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -51,7 +51,7 @@ class setup_cmd_update extends setup_cmd * 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 + * @return string success message * @throws Exception(lang('Wrong credentials to access the header.inc.php file!'),2); * @throws Exception('header.inc.php not found!'); */ @@ -65,10 +65,13 @@ class setup_cmd_update extends setup_cmd $this->check_installed($this->domain,array(14),$this->verbose); 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))) + (!$this->app || !in_array($this->app, self::$apps_to_install) && !in_array($this->app, self::$apps_to_upgrade)) && + !self::check_autoinstall()) { return lang('No update necessary, domain %1(%2) is up to date.',$this->domain,$GLOBALS['egw_domain'][$this->domain]['db_type']); } + if ($check_only) return lang('Update necessary.'); + $setup_info = self::$egw_setup->detection->upgrade_exclude($setup_info); self::$egw_setup->process->init_process(); // we need a new schema-proc instance for each new domain @@ -83,14 +86,14 @@ class setup_cmd_update extends setup_cmd if ($setup_info[$this->app]['tables']) { - $terror = self::$egw_setup->process->current($terror,$DEBUG); - $terror = self::$egw_setup->process->default_records($terror,$DEBUG); + $errors = self::$egw_setup->process->current($terror, $this->verbose); + $terror = self::$egw_setup->process->default_records($errors, $this->verbose); 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); + $terror = self::$egw_setup->process->default_records($terror, $this->verbose); if (self::$egw_setup->app_registered($setup_info[$this->app]['name'])) { self::$egw_setup->update_app($setup_info[$this->app]['name']); diff --git a/setup/setup-cli.php b/setup/setup-cli.php index 6d3be8b5ac..63d2681260 100755 --- a/setup/setup-cli.php +++ b/setup/setup-cli.php @@ -6,7 +6,7 @@ * @link http://www.egroupware.org * @package setup * @author Ralf Becker - * @copyright (c) 2006-13 by Ralf Becker + * @copyright (c) 2006-14 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -186,8 +186,6 @@ function do_config($args) */ function do_hooks($arg) { - global $setup_info; - list($domain,$user,$password) = explode(',',$arg); _fetch_user_password($user,$password); @@ -197,7 +195,7 @@ function do_hooks($arg) $domains = array($domain => $GLOBALS['egw_domain'][$domain]); } - foreach($domains as $domain => $data) + foreach(array_keys($domains) as $domain) { $cmd = new setup_cmd_hooks($domain,$user,$password); echo "$domain: ".$cmd->run()."\n"; @@ -261,7 +259,7 @@ function do_backup($arg,$quite_check=false) { $domains = array($domain => $GLOBALS['egw_domain'][$domain]); } - foreach($domains as $domain => $data) + foreach(array_keys($domains) as $domain) { $options[0] = $domain; @@ -297,8 +295,6 @@ function do_backup($arg,$quite_check=false) */ function do_update($arg) { - global $setup_info; - list($domain,$user,$password,$backup,$app) = explode(',',$arg); _fetch_user_password($user,$password); @@ -314,7 +310,8 @@ function do_update($arg) _check_auth_config($arg,14); 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))) + (!$app || !in_array($app, setup_cmd::$apps_to_install) && !in_array($app, setup_cmd::$apps_to_upgrade)) && + !setup_cmd::check_autoinstall()) { echo lang('No update necessary, domain %1(%2) is up to date.',$domain,$data['db_type'])."\n"; } @@ -409,7 +406,7 @@ function do_header($create,&$arguments) if (!$create) { // read password from enviroment or query it from user, if not given - @list($password,$user) = $options = explode(',',@$arguments[0]); + $options = explode(',',@$arguments[0]); _fetch_user_password($options[1],$options[0]); $arguments[0] = implode(',',$options); } @@ -570,6 +567,7 @@ function list_exit_codes() { $content = file_get_contents($setup_dir.'/'.$file); + $matches = null; if (preg_match_all('/throw new (egw_exception[a-z_]*)\((.*),([0-9]+)\);/m',$content,$matches)) { //echo $file.":\n"; print_r($matches); @@ -577,8 +575,7 @@ function list_exit_codes() { //if (isset($codes[$code])) echo "$file redifines #$code: {$codes[$code]}\n"; - $src = $matches[2][$key]; - $src = preg_replace('/self::\$[a-z_>-]+/i',"''",$src); // gives fatal error otherwise + $src = preg_replace('/self::\$[a-z_>-]+/i', "''", $matches[2][$key]); // gives fatal error otherwise @eval($src='$codes['.$code.'] = '.$src.';'); //echo "- codes[$code] => '{$codes[$code]}'\n"; }