upgrade files as objects
This commit is contained in:
parent
8326c63c1e
commit
4a61946399
7 changed files with 62 additions and 36 deletions
|
|
@ -1,5 +1,5 @@
|
|||
package WebGUI::Upgrade;
|
||||
|
||||
use 5.010;
|
||||
use Moose;
|
||||
use WebGUI::Paths;
|
||||
use WebGUI::Pluggable;
|
||||
|
|
@ -163,21 +163,44 @@ sub runUpgradeFile {
|
|||
my ($configFile, $version, $filename) = @_;
|
||||
my $has_run = $self->_files_run->{ Cwd::realpath($filename) } ++;
|
||||
|
||||
my ($extension) = $filename =~ /\.([^.]+)$/;
|
||||
return
|
||||
unless $extension;
|
||||
|
||||
my $package = 'WebGUI::Upgrade::File::' . $extension;
|
||||
if ( try { WebGUI::Pluggable::load($package) } && $package->DOES('WebGUI::Upgrade::File') ) {
|
||||
if ($has_run && $package->once) {
|
||||
try {
|
||||
my $upgrade_class = $self->classForFile($filename);
|
||||
my $upgrade_file = $upgrade_class->new(
|
||||
version => $version,
|
||||
file => $filename,
|
||||
upgrade => $self,
|
||||
configFile => $configFile,
|
||||
);
|
||||
if ($has_run && $upgrade_file->once) {
|
||||
return;
|
||||
}
|
||||
return $package->run($self, $configFile, $version, $filename);
|
||||
$upgrade_file->run;
|
||||
}
|
||||
warn "Don't know how to use $extension upgrade file\n";
|
||||
catch {
|
||||
when (/^No upgrade package/) {
|
||||
warn $_;
|
||||
}
|
||||
default {
|
||||
die $_;
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
sub classForFile {
|
||||
my $class = shift;
|
||||
my $file = shift;
|
||||
my ($extension) = $file =~ /\.([^.]+)$/;
|
||||
if ($extension) {
|
||||
my $package = 'WebGUI::Upgrade::File::' . $extension;
|
||||
WebGUI::Pluggable::load($package);
|
||||
return $package
|
||||
if $package->DOES('WebGUI::Upgrade::File');
|
||||
}
|
||||
no warnings 'uninitialized';
|
||||
die "No upgrade package for extension: $extension";
|
||||
}
|
||||
|
||||
sub markVersionUpgrade {
|
||||
my $self = shift;
|
||||
my $configFile = shift;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,14 @@ use Moose::Role;
|
|||
|
||||
requires 'run';
|
||||
|
||||
has file => ( is => 'ro' );
|
||||
has configFile => ( is => 'ro' );
|
||||
has version => ( is => 'ro' );
|
||||
has upgrade => (
|
||||
is => 'ro',
|
||||
handles => [ 'quiet' ],
|
||||
);
|
||||
|
||||
sub once { 0 }
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ use namespace::autoclean -also => qr/^_/;
|
|||
with 'WebGUI::Upgrade::File';
|
||||
|
||||
sub run {
|
||||
my $class = shift;
|
||||
my ($upgrade, $configFile, $version, $file) = @_;
|
||||
my $self = shift;
|
||||
|
||||
local $ENV{WEBGUI_CONFIG} = $configFile;
|
||||
local $ENV{WEBGUI_UPGRADE_VERSION} = $version;
|
||||
local $ENV{WEBGUI_UPGRADE_QUIET} = $upgrade->quiet;
|
||||
return _runScript($file);
|
||||
local $ENV{WEBGUI_CONFIG} = $self->configFile;
|
||||
local $ENV{WEBGUI_UPGRADE_VERSION} = $self->version;
|
||||
local $ENV{WEBGUI_UPGRADE_QUIET} = $self->quiet;
|
||||
return _runScript($self->file);
|
||||
}
|
||||
|
||||
sub _runScript {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ with 'WebGUI::Upgrade::File';
|
|||
sub once { 1 }
|
||||
|
||||
sub run {
|
||||
my $class = shift;
|
||||
my ($upgrade, $configFile, $version, $file) = @_;
|
||||
if ( ! $upgrade->quiet ) {
|
||||
system { $^X } $^X, '-MPod::Perldoc', '-ePod::Perldoc->run', $file;
|
||||
my $self = shift;
|
||||
if ( ! $self->quiet ) {
|
||||
system { $^X } $^X, '-MPod::Perldoc', '-ePod::Perldoc->run', $self->file;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -3,14 +3,13 @@ use Moose;
|
|||
with 'WebGUI::Upgrade::File';
|
||||
|
||||
sub run {
|
||||
my $class = shift;
|
||||
my ($upgrade, $configFile, $version, $file) = @_;
|
||||
my $self = shift;
|
||||
|
||||
my @command_line = (
|
||||
$upgrade->mysql,
|
||||
$upgrade->mysqlCommandLine($configFile),
|
||||
$self->upgrade->mysql,
|
||||
$self->upgrade->mysqlCommandLine($self->configFile),
|
||||
'--batch',
|
||||
'--execute=source ' . $file,
|
||||
'--execute=source ' . $self->file,
|
||||
);
|
||||
|
||||
system { $command_line[0] } @command_line
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ with 'WebGUI::Upgrade::File';
|
|||
sub once { 1 }
|
||||
|
||||
sub run {
|
||||
my $class = shift;
|
||||
my ($upgrade, $configFile, $version, $file) = @_;
|
||||
if ( ! $upgrade->quiet ) {
|
||||
open my $fh, '<', $file;
|
||||
my $self = shift;
|
||||
if ( ! $self->quiet ) {
|
||||
open my $fh, '<', $self->file;
|
||||
while ( my $line = <$fh> ) {
|
||||
print $line;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,18 @@ use Try::Tiny;
|
|||
use namespace::clean;
|
||||
|
||||
sub run {
|
||||
my $class = shift;
|
||||
my ($upgrade, $configFile, $version, $file) = @_;
|
||||
my $self = shift;
|
||||
|
||||
my $session = WebGUI::Session->open($configFile);
|
||||
my $session = WebGUI::Session->open($self->configFile);
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
(undef, undef, my $shortname) = File::Spec->splitpath($file);
|
||||
(undef, undef, my $shortname) = File::Spec->splitpath($self->file);
|
||||
$shortname =~ s/\.[^.]*$//;
|
||||
$versionTag->set({name => "Upgrade to $version - $shortname"});
|
||||
$versionTag->set({name => "Upgrade to @{[$self->version]} - $shortname"});
|
||||
|
||||
my $package = $class->import_package($session, $file);
|
||||
if (! $upgrade->quiet) {
|
||||
my $package = $class->import_package($session, $self->file);
|
||||
if (! $self->quiet) {
|
||||
printf "\tImported '%s'\n", $package->title;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue