more upgrades progress
This commit is contained in:
parent
00b3113031
commit
adf3dbbe04
17 changed files with 90 additions and 24 deletions
|
|
@ -172,6 +172,12 @@ sub close {
|
||||||
foreach my $key (qw/_asset _datetime _icon _slave _db _form _http _id _output _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler _response _request/) {
|
foreach my $key (qw/_asset _datetime _icon _slave _db _form _http _id _output _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler _response _request/) {
|
||||||
delete $self->{$key};
|
delete $self->{$key};
|
||||||
}
|
}
|
||||||
|
$self->{closed} = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub closed {
|
||||||
|
my $self = shift;
|
||||||
|
return $self->{closed};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package WebGUI::Upgrade;
|
package WebGUI::Upgrade;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use WebGUI::Paths;
|
use WebGUI::Paths;
|
||||||
use WebGUI;
|
|
||||||
use Try::Tiny;
|
|
||||||
use WebGUI::Pluggable;
|
use WebGUI::Pluggable;
|
||||||
use DBI;
|
|
||||||
use WebGUI::Config;
|
use WebGUI::Config;
|
||||||
|
use Try::Tiny;
|
||||||
|
use DBI;
|
||||||
|
|
||||||
sub upgradeSites {
|
sub upgradeSites {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
@ -27,11 +26,17 @@ sub upgradeSites {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getCodeVersion {
|
||||||
|
require WebGUI;
|
||||||
|
return WebGUI->VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
sub upgradeSite {
|
sub upgradeSite {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my ($configFile, $quiet) = @_;
|
my ($configFile, $quiet) = @_;
|
||||||
my $fromVersion = $class->getCurrentVersion($configFile);
|
my $fromVersion = $class->getCurrentVersion($configFile);
|
||||||
my @steps = $class->calcUpgradePath($fromVersion, $WebGUI::VERSION);
|
my $toVersion = $class->getCodeVersion;
|
||||||
|
my @steps = $class->calcUpgradePath($fromVersion, $toVersion);
|
||||||
for my $step ( @steps ) {
|
for my $step ( @steps ) {
|
||||||
$class->runUpgradeStep($configFile, $step, $quiet);
|
$class->runUpgradeStep($configFile, $step, $quiet);
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +49,8 @@ sub calcUpgradePath {
|
||||||
my $toVersion = $class->numericVersion($toVersionStr);
|
my $toVersion = $class->numericVersion($toVersionStr);
|
||||||
|
|
||||||
my %upgrades;
|
my %upgrades;
|
||||||
opendir my $dh, WebGUI::Paths->upgrades;
|
opendir my $dh, WebGUI::Paths->upgrades
|
||||||
|
or die "Upgrades directory doesn't exist.\n";
|
||||||
while ( my $dir = readdir $dh ) {
|
while ( my $dir = readdir $dh ) {
|
||||||
next
|
next
|
||||||
if $dir =~ /^\./;
|
if $dir =~ /^\./;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ my $exporter = Sub::Exporter::build_exporter({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
my $caller_upgrade_file;
|
||||||
sub import {
|
sub import {
|
||||||
my ($class, @args) = @_;
|
my ($class, @args) = @_;
|
||||||
my $extra = shift @args if ref $args[0] eq 'HASH';
|
my $extra = shift @args if ref $args[0] eq 'HASH';
|
||||||
|
|
@ -22,6 +23,8 @@ sub import {
|
||||||
$extra->{into_level}++;
|
$extra->{into_level}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$caller_upgrade_file = (caller 0)[1];
|
||||||
|
|
||||||
feature->import(':5.10');
|
feature->import(':5.10');
|
||||||
strict->import;
|
strict->import;
|
||||||
warnings->import;
|
warnings->import;
|
||||||
|
|
@ -32,7 +35,7 @@ sub import {
|
||||||
my @cleanups;
|
my @cleanups;
|
||||||
|
|
||||||
sub _build_exports {
|
sub _build_exports {
|
||||||
my $configFile = $ENV{WEBGUI_CONFIG};
|
my $configFile = $ENV{WEBGUI_CONFIG} || die 'WEBGUI_CONFIG environment variable must be specified';
|
||||||
my $version = $ENV{WEBGUI_UPGRADE_VERSION};
|
my $version = $ENV{WEBGUI_UPGRADE_VERSION};
|
||||||
my $quiet = $ENV{WEBGUI_UPGRADE_QUIET};
|
my $quiet = $ENV{WEBGUI_UPGRADE_QUIET};
|
||||||
|
|
||||||
|
|
@ -41,6 +44,7 @@ sub _build_exports {
|
||||||
my $dbh;
|
my $dbh;
|
||||||
my $collateral;
|
my $collateral;
|
||||||
my $versionTag;
|
my $versionTag;
|
||||||
|
my $upgrade_file = File::Spec->rel2abs( $caller_upgrade_file );
|
||||||
|
|
||||||
my $subs;
|
my $subs;
|
||||||
|
|
||||||
|
|
@ -66,7 +70,7 @@ sub _build_exports {
|
||||||
quiet => sub () {
|
quiet => sub () {
|
||||||
return $quiet;
|
return $quiet;
|
||||||
},
|
},
|
||||||
report => sub {
|
report => sub (@) {
|
||||||
print @_
|
print @_
|
||||||
unless $quiet;
|
unless $quiet;
|
||||||
},
|
},
|
||||||
|
|
@ -100,7 +104,7 @@ sub _build_exports {
|
||||||
$dbh = WebGUI::Upgrade->dbhForConfig($subs->{config}->());
|
$dbh = WebGUI::Upgrade->dbhForConfig($subs->{config}->());
|
||||||
return $dbh;
|
return $dbh;
|
||||||
},
|
},
|
||||||
version_tag => sub {
|
version_tag => sub (;$) {
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
$check_cleanup->();
|
$check_cleanup->();
|
||||||
require WebGUI::VersionTag;
|
require WebGUI::VersionTag;
|
||||||
|
|
@ -108,12 +112,13 @@ sub _build_exports {
|
||||||
if ($name) {
|
if ($name) {
|
||||||
$versionTag->commit;
|
$versionTag->commit;
|
||||||
}
|
}
|
||||||
elsif ( ! $versionTag->isCommitted ) {
|
elsif ( ! $versionTag->get('isCommitted') ) {
|
||||||
return $versionTag;
|
return $versionTag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! $name) {
|
if (! $name) {
|
||||||
(undef, undef, my $shortname) = File::Spec->splitpath((caller(0))[1]);
|
no warnings 'uninitialized';
|
||||||
|
(undef, undef, my $shortname) = File::Spec->splitpath($upgrade_file);
|
||||||
$shortname =~ s/\.[^.]*$//;
|
$shortname =~ s/\.[^.]*$//;
|
||||||
$name = $shortname;
|
$name = $shortname;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +126,7 @@ sub _build_exports {
|
||||||
$versionTag->set({name => "Upgrade to $version - $name"});
|
$versionTag->set({name => "Upgrade to $version - $name"});
|
||||||
return $versionTag;
|
return $versionTag;
|
||||||
},
|
},
|
||||||
rm_lib => sub {
|
rm_lib => sub (@) {
|
||||||
my @modules = @_;
|
my @modules = @_;
|
||||||
for my $module (@modules) {
|
for my $module (@modules) {
|
||||||
$module =~ s{::}{/}g;
|
$module =~ s{::}{/}g;
|
||||||
|
|
@ -135,19 +140,40 @@ sub _build_exports {
|
||||||
collateral => sub () {
|
collateral => sub () {
|
||||||
return $collateral
|
return $collateral
|
||||||
if $collateral;
|
if $collateral;
|
||||||
(my $vol, my $dir, my $shortname) = File::Spec->splitpath(
|
(my $vol, my $dir, my $shortname) = File::Spec->splitpath( $upgrade_file );
|
||||||
File::Spec->rel2abs( (caller(0))[1] )
|
|
||||||
);
|
|
||||||
$shortname =~ s/\.[^.]*$//;
|
$shortname =~ s/\.[^.]*$//;
|
||||||
my $path = File::Spec->catpath($vol, File::Spec->catdir($dir, $shortname), '');
|
my $path = File::Spec->catpath($vol, File::Spec->catdir($dir, $shortname), '');
|
||||||
$collateral = Path::Class::Dir->new($path);
|
$collateral = Path::Class::Dir->new($path);
|
||||||
return $collateral;
|
return $collateral;
|
||||||
},
|
},
|
||||||
import_package => sub {
|
import_package => sub (@) {
|
||||||
my $fullPath = $subs->{collateral}->()->file(@_);
|
my $fullPath = $subs->{collateral}->()->file(@_);
|
||||||
require WebGUI::Upgrade::File::wgpkg;
|
require WebGUI::Upgrade::File::wgpkg;
|
||||||
WebGUI::Upgrade::File::wgpkg->import_package($subs->{session}->(), $fullPath);
|
WebGUI::Upgrade::File::wgpkg->import_package($subs->{session}->(), $fullPath);
|
||||||
},
|
},
|
||||||
|
root_asset => sub () {
|
||||||
|
require WebGUI::Asset;
|
||||||
|
return WebGUI::Asset->getRoot($subs->{session}->());
|
||||||
|
},
|
||||||
|
import_node => sub () {
|
||||||
|
require WebGUI::Asset;
|
||||||
|
return WebGUI::Asset->getImportNode($subs->{session}->());
|
||||||
|
},
|
||||||
|
asset => sub ($) {
|
||||||
|
require WebGUI::Asset;
|
||||||
|
my $session = $subs->session->();
|
||||||
|
my $assetId = shift;
|
||||||
|
my $asset;
|
||||||
|
if ($session->id->valid($assetId)) {
|
||||||
|
try {
|
||||||
|
$asset = WebGUI::Asset->newById($session, $assetId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if ( ! $asset ) {
|
||||||
|
$asset = WebGUI::Asset->newByUrl($session, $assetId);
|
||||||
|
}
|
||||||
|
return $asset;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
return $subs;
|
return $subs;
|
||||||
}
|
}
|
||||||
|
|
@ -252,6 +278,18 @@ script with the extension stripped off.
|
||||||
|
|
||||||
Imports the specified package from the upgrade script's collateral path.
|
Imports the specified package from the upgrade script's collateral path.
|
||||||
|
|
||||||
|
=head2 root_asset
|
||||||
|
|
||||||
|
Returns the site's root asset.
|
||||||
|
|
||||||
|
=head2 import_node
|
||||||
|
|
||||||
|
Returns the site's import node.
|
||||||
|
|
||||||
|
=head2 asset ( $assetId_or_URL )
|
||||||
|
|
||||||
|
Returns an asset based on an asset ID or URL.
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
These methods are primarily of interest to someone wrapping an upgrade script.
|
These methods are primarily of interest to someone wrapping an upgrade script.
|
||||||
|
|
|
||||||
16
t/Upgrade.t
16
t/Upgrade.t
|
|
@ -14,11 +14,6 @@ use Test::MockObject::Extends;
|
||||||
use File::Temp;
|
use File::Temp;
|
||||||
use File::Path qw(make_path);
|
use File::Path qw(make_path);
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
$INC{'WebGUI.pm'} = 1;
|
|
||||||
$WebGUI::VERSION = '8.4.3';
|
|
||||||
}
|
|
||||||
|
|
||||||
use WebGUI::Paths;
|
use WebGUI::Paths;
|
||||||
use WebGUI::Upgrade;
|
use WebGUI::Upgrade;
|
||||||
use WebGUI::Session::Id;
|
use WebGUI::Session::Id;
|
||||||
|
|
@ -37,6 +32,13 @@ our $configFile = WebGUI::Test->config->getFilename;
|
||||||
|
|
||||||
my $upgrade = Test::MockObject::Extends->new('WebGUI::Upgrade');
|
my $upgrade = Test::MockObject::Extends->new('WebGUI::Upgrade');
|
||||||
$upgrade->set_always('getCurrentVersion', '8.0.0');
|
$upgrade->set_always('getCurrentVersion', '8.0.0');
|
||||||
|
$upgrade->set_always('getCodeVersion', '8.4.3');
|
||||||
|
|
||||||
|
{
|
||||||
|
no warnings 'redefine';
|
||||||
|
*WebGUI::Paths::upgrades = sub { collateral('Upgrade', 'non-existant') } ;
|
||||||
|
}
|
||||||
|
ok ! try { $upgrade->calcUpgradePath('8.0.0', '8.4.3'); 1 }, "calcUpgradePath dies when upgrades path doesn't exist";
|
||||||
|
|
||||||
{
|
{
|
||||||
no warnings 'redefine';
|
no warnings 'redefine';
|
||||||
|
|
@ -65,9 +67,11 @@ capture {
|
||||||
};
|
};
|
||||||
|
|
||||||
$upgrade->called_pos_ok(1, 'getCurrentVersion');
|
$upgrade->called_pos_ok(1, 'getCurrentVersion');
|
||||||
$upgrade->called_pos_ok(2, 'runUpgradeFile');
|
SKIP: {
|
||||||
|
$upgrade->called_pos_ok(2, 'runUpgradeFile') || skip 'upgrade not run', 1;
|
||||||
my $upgradeFile = $upgrade->call_args_pos(2, 4);
|
my $upgradeFile = $upgrade->call_args_pos(2, 4);
|
||||||
ok $upgradeFile =~ /\b00_simple\.pl$/, 'correct upgrade file run';
|
ok $upgradeFile =~ /\b00_simple\.pl$/, 'correct upgrade file run';
|
||||||
|
}
|
||||||
|
|
||||||
$upgrade->clear;
|
$upgrade->clear;
|
||||||
$upgrade->unmock('runUpgradeFile');
|
$upgrade->unmock('runUpgradeFile');
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
my $c = collateral;
|
my $c = collateral;
|
||||||
|
|
||||||
::isa_ok $c, 'Path::Class::Dir';
|
::isa_ok $c, 'Path::Class::Dir';
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
::is config->getFilename, $::configFile, 'config function works correctly';
|
::is config->getFilename, $::configFile, 'config function works correctly';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
my $totalAssets = dbh->selectrow_array('SELECT COUNT(*) FROM asset');
|
my $totalAssets = dbh->selectrow_array('SELECT COUNT(*) FROM asset');
|
||||||
::is $totalAssets, $::totalAssets, 'dbh function working correctly';
|
::is $totalAssets, $::totalAssets, 'dbh function working correctly';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
die "Upgrade failure\n";
|
die "Upgrade failure\n";
|
||||||
|
|
||||||
|
|
|
||||||
0
t/supporting_collateral/Upgrade/impossible/.exists
Normal file
0
t/supporting_collateral/Upgrade/impossible/.exists
Normal file
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
report 'Simple Output';
|
report 'Simple Output';
|
||||||
|
|
||||||
done;
|
done;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
::addToCleanup(version_tag);
|
::addToCleanup(version_tag);
|
||||||
|
|
||||||
import_package('test-template.wgpkg');
|
import_package('test-template.wgpkg');
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
rm_lib 'WebGUI::Upgrade::Test::Module';
|
rm_lib 'WebGUI::Upgrade::Test::Module';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
my $s = session;
|
my $s = session;
|
||||||
::isa_ok $s, 'WebGUI::Session';
|
::isa_ok $s, 'WebGUI::Session';
|
||||||
::is $s, session, 'session properly cached';
|
::is $s, session, 'session properly cached';
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
$variable = "value";
|
$variable = "value";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
report "Simple Upgrade Step";
|
report "Simple Upgrade Step";
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
use WebGUI::Asset::Snippet;
|
use WebGUI::Asset::Snippet;
|
||||||
WebGUI::Asset->getRoot(session)->addChild({
|
WebGUI::Asset->getRoot(session)->addChild({
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use WebGUI::Upgrade::Script;
|
||||||
my $vt = version_tag;
|
my $vt = version_tag;
|
||||||
::addToCleanup($vt);
|
::addToCleanup($vt);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue