diff options
author | jeff <jeff> | 2007-07-12 13:36:27 +0000 |
---|---|---|
committer | jeff <jeff> | 2007-07-12 13:36:27 +0000 |
commit | cd907554f4c08175c379e204e28e26483acf957a (patch) | |
tree | f07a03443fcb8e1673ba24af0ef729e440f3ed4c /FS/bin | |
parent | 161172b3162b1495e3d8d0f7425a8b699ffab9fe (diff) |
refactor freeside-init-config to module code, compare results of old/new code, have freeside-upgrade complain and revert to old code/config on failure (#1477)
Diffstat (limited to 'FS/bin')
-rwxr-xr-x | FS/bin/freeside-init-config | 63 | ||||
-rwxr-xr-x | FS/bin/freeside-setup | 26 | ||||
-rwxr-xr-x | FS/bin/freeside-upgrade | 21 |
3 files changed, 46 insertions, 64 deletions
diff --git a/FS/bin/freeside-init-config b/FS/bin/freeside-init-config index 8bc7ad1d2..fe4729c40 100755 --- a/FS/bin/freeside-init-config +++ b/FS/bin/freeside-init-config @@ -3,10 +3,10 @@ use strict; use vars qw($opt_u $opt_f $opt_v); use Getopt::Std; -use IO::File; use FS::UID qw(adminsuidsetup checkeuid dbh); use FS::CurrentUser; use FS::Record qw(qsearch); +use FS::Conf; die "Not running uid freeside!" unless checkeuid(); @@ -15,51 +15,19 @@ getopts("u:vf"); my $dir = shift or die &usage; $FS::CurrentUser::upgrade_hack = 1; +$FS::UID::AutoCommit = 0; +$FS::UID::callback_hack = 1; adminsuidsetup $opt_u; #$user; $|=1; -my $conf = new FS::Conf; if (!scalar(qsearch('conf', {})) || $opt_f) { - - foreach my $item ( $conf->config_items() ) { - insert_config_item($item,$dir); + my $error = FS::Conf::init_config($dir); + if ($error) { + warn "CONFIGURATION INITIALIZATION FAILED\n"; + dbh->rollback or die dbh->errstr; + die $error if $error; } - - # ugly pseudo false laziness with Conf.pm - foreach my $item ( map { my $basename = basename($_); - $basename =~ /^(.*)$/; - $basename = $1; - new FS::ConfItem { - 'key' => $basename, - 'type' => '', - } - } glob($dir. '/invoice_template_*'), - glob($dir. '/invoice_html_*'), - glob($dir. '/invoice_htmlnotes_*'), - glob($dir. '/invoice_latex_*'), - glob($dir. '/invoice_latexnotes_*') - ) { - - insert_config_item($item,$dir); - - } - - foreach my $item ( map { my $basename = basename($_); - $basename =~ /^(.*)$/; - $basename = $1; - new FS::ConfItem { - 'key' => $basename, - 'type' => 'binary', - } - } glob($dir. '/logo_*.png'), - glob($dir. '/logo_*.eps') - ) { - - insert_config_item($item,$dir); - - } - } warn "Freeside database initialized - committing transaction\n" if $opt_v; @@ -69,21 +37,6 @@ dbh->disconnect or die dbh->errstr; warn "Configuration initialization committed successfully\n" if $opt_v; -sub insert_config_item { - local $/; - my ($item,$dir) = @_; - my $key = $item->key; - if (-e "$dir/$key") { - warn "Inserting $key\n" if $opt_v; - my $value = readline(new IO::File "$dir/$key"); - if ($item->type eq 'binary'){ - $conf->set_binary($key, $value); - }else{ - $conf->set($key, $value); - } - } -} - sub usage { die "Usage:\n freeside-init-config [ -v ] [ -f ] directory\n" # [ -u user ] for devel/multi-db installs diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index ed737b395..188a1867a 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -9,9 +9,10 @@ use Getopt::Std; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::CurrentUser; use FS::Schema qw( dbdef_dist reload_dbdef ); -use FS::Record; +use FS::Record qw( qsearch ); #use FS::raddb; use FS::Setup qw(create_initial_data); +use FS::Conf; die "Not running uid freeside!" unless checkeuid(); @@ -117,11 +118,24 @@ $dbh->disconnect or die $dbh->errstr; warn "Database schema committed successfully\n" if $opt_v; -my $init_config = "freeside-init-config"; -$init_config .= " -v" if $opt_v; -$init_config .= " -u $opt_u" if $opt_u; -$init_config .= " $config_dir"; -system "$init_config" ; +warn "Initializing freeside configuration\n" if $opt_v; +$FS::UID::callback_hack = 1; +$dbh = adminsuidsetup $opt_u; +$FS::UID::callback_hack = 0; +if (!scalar(qsearch('conf', {}))) { + my $error = FS::Conf::init_config($config_dir); + if ($error) { + dbh->rollback or die dbh->errstr; + die $error; + } +} + +warn "Freeside configuration initialized - commiting transaction\n" if $opt_v; + +$dbh->commit or die $dbh->errstr; +$dbh->disconnect or die $dbh->errstr; + +warn "Freeside configuration committed successfully\n" if $opt_v; $dbh = adminsuidsetup $opt_u; create_initial_data('domain' => $opt_d); diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index 04e5da988..eb818ea4e 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -9,6 +9,8 @@ use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets); use FS::CurrentUser; use FS::Schema qw( dbdef dbdef_dist reload_dbdef ); use FS::Misc::prune qw(prune_applications); +use FS::Conf; +use FS::Record qw(qsearch); die "Not running uid freeside!" unless checkeuid(); @@ -56,11 +58,24 @@ dbdef_create($dbh, $dbdef_file); $dbh->disconnect or die $dbh->errstr; +delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload +$FS::UID::AutoCommit = 1; +$FS::UID::callback_hack = 1; +$dbh = adminsuidsetup($user); +$FS::UID::callback_hack = 0; unless ( $DRY_RUN ) { - my $init_config = "freeside-init-config -u $user "; - $init_config .= "%%%FREESIDE_CONF%%%/conf.". datasrc; - system "$init_config" ; + my $dir = "%%%FREESIDE_CONF%%%/conf.". datasrc; + if (!scalar(qsearch('conf', {}))) { + my $error = FS::Conf::init_config($dir); + if ($error) { + warn "CONFIGURATION UPGRADE FAILED\n"; + $dbh->rollback or die $dbh->errstr; + die $error; + } + } } +$dbh->commit or die $dbh->errstr; +$dbh->disconnect or die $dbh->errstr; ### |