use SL::Common;
-require Exporter;
-our @ISA = qw(Exporter);
-
-our @EXPORT = qw(parse_dbupdate_controls sort_dbupdate_controls);
-
use strict;
+sub new {
+ my ($package, $form, $dbdriver) = @_;
+ my $self = { form => $form, dbdriver => $dbdriver };
+ return bless($self, $package);
+}
+
sub parse_dbupdate_controls {
$main::lxdebug->enter_sub();
- my ($form, $dbdriver) = @_;
+ my ($self) = @_;
+ my $form = $self->{form};
my $locale = $main::locale;
local *IN;
my %all_controls;
- my $path = "sql/${dbdriver}-upgrade2";
+ my $path = "sql/" . $self->{dbdriver} . "-upgrade2";
foreach my $file_name (<$path/*.sql>, <$path/*.pl>) {
next unless (open(IN, $file_name));
map({ _dbupdate2_calculate_depth(\%all_controls, $_->{"tag"}) }
values(%all_controls));
+ $self->{all_controls} = \%all_controls;
+
$main::lxdebug->leave_sub();
return \%all_controls;
}
sub sort_dbupdate_controls {
+ my $self = shift;
+
return sort({ $a->{"depth"} != $b->{"depth"} ? $a->{"depth"} <=> $b->{"depth"}
: $a->{"priority"} != $b->{"priority"} ? $a->{"priority"} <=> $b->{"priority"}
- : $a->{"tag"} cmp $b->{"tag"} } values(%{$_[0]}));
+ : $a->{"tag"} cmp $b->{"tag"} } values(%{ $self->{all_controls} }));
}
1;
$rc = 0;
- my $controls =
- parse_dbupdate_controls($form, $myconfig{"dbdriver"});
+ my $dbupdater = SL::DBUpgrade2->new($form, $myconfig{"dbdriver"});
+ my $controls = $dbupdater->parse_dbupdate_controls;
map({ $form->{$_} = $myconfig{$_} }
qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat));
$SIG{QUIT} = 'IGNORE';
$self->dbupdate($form);
- $self->dbupdate2($form, $controls);
+ $self->dbupdate2($form, $dbupdater);
close(FH);
my ($self, $form) = @_;
my %members = $main::auth->read_all_users();
- my $controls = parse_dbupdate_controls($form, $form->{dbdriver});
+ my $controls = SL::DBUpgrade2->new($form, $form->{dbdriver})->parse_dbupdate_controls;
my ($query, $sth, %dbs_needing_updates);
sub dbupdate2 {
$main::lxdebug->enter_sub();
- my ($self, $form, $controls) = @_;
+ my ($self, $form, $dbupdater) = @_;
$form->{sid} = $form->{dbdefault};
my ($query, $sth, $tag);
my $rc = -2;
- @upgradescripts = sort_dbupdate_controls($controls);
+ @upgradescripts = $dbupdater->sort_dbupdate_controls;
my $db_charset = $main::dbcharset;
$db_charset ||= Common::DEFAULT_CHARSET;
$sth = $dbh->prepare($query);
$sth->execute() || $form->dberror($query);
while (($tag) = $sth->fetchrow_array()) {
- $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
+ $dbupdater->{all_controls}->{$tag}->{"applied"} = 1 if (defined($dbupdater->{all_controls}->{$tag}));
}
$sth->finish();