Skip to content

Commit

Permalink
Item13364: refactored to support bulk operations on extensions. Prett…
Browse files Browse the repository at this point in the history
…y much untested, so help desperately needed!
  • Loading branch information
Comment committed Apr 10, 2015
1 parent 52433f8 commit 74a7bc1
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 134 deletions.
Expand Up @@ -328,9 +328,9 @@ function _id_ify(id) {
var $dlg = $('#hogwarts');
var $div = $('<div class="wiz"></div>');
$div.addClass(id);
$div.html( '<b>The following Wizard is running, Please wait:</b><br/>');
$div.append((params.wizard ? params.wizard + " " : '')
+ params.method + " ");
$div.html( '<b>Waiting for the server, please be patient:</b><br/>');
$div.append((params.wizard ? params.wizard + "/" : '')
+ params.method + " is working");
inline_whirly($div);
$dlg.append($div);
if (!$dlg.hasClass('ui-dialog-content')) {
Expand Down
126 changes: 79 additions & 47 deletions core/lib/Foswiki/Configure/Wizards/ExploreExtensions.pm
Expand Up @@ -214,7 +214,13 @@ sub _get_extensions {

$reporter->NOTE("---++ $set Extensions");
$reporter->NOTE(
'> Each extension is listed along with a "Study" button, which is used to generate a dependency report for the extension. From there, you can proceed with the installation. '
'> Each extension has a check box which you can use to select the extension. Use the "Report" button to generate a dependency report for each selected extensions, or the "'
. ( $set eq 'Installed' ? 'Remove' : 'Install' )
. '" button to '
. (
$set eq 'Installed' ? 'remove' : 'install (or upgrade/re-install)'
)
. ' them. '
);
$reporter->NOTE('> ');

Expand Down Expand Up @@ -242,6 +248,65 @@ sub _get_extensions {
$reporter->NOTE("> *Found $uninstalledCount Uninstalled extensions* ");
}

$reporter->NOTE(
$reporter->WIZARD(
'Report',
{
wizard => 'InstallExtensions',
method => 'depreport',
form => "#${set}_extensions_list",
args => {

# will be extended by the #extensions_list form
# SIMULATE =>
# NODEPS =>
# USELOCAL =>
}
}
)
. $reporter->WIZARD(
( $set eq 'Installed' ? 'Upgrade' : 'Install' ),
{
wizard => 'InstallExtensions',
method => 'add',
form => "#${set}_extensions_list",
args => {

# will be extended by the #extensions_list form
# SIMULATE =>
# NODEPS =>
# USELOCAL =>
}
}
)
. $reporter->WIZARD(
'Remove',
{
wizard => 'InstallExtensions',
method => 'remove',
form => "#${set}_extensions_list",
args => {

# will be extended by the #extensions_list form
# SIMULATE =>
# NODEPS =>
# USELOCAL =>
}
}
)
. "<form id='${set}_extensions_list'>"
);

$reporter->NOTE(<<SIMULATE);
<input id="simulate" type='checkbox' name='SIMULATE' value='1' title="Check to get a detailed report on what will happen during installation, without actually installing." />
<label for="simulate">Simulated install</label>
SIMULATE

$reporter->NOTE(<<NODEPS);
<input id="nodeps" type='checkbox' name='NODEPS' value='1' title="If this is unchecked, any required dependencies will automatically be installed. Check to install ONLY the extensions, IGNORING any dependencies." />
<label for="nodeps">Don't install dependencies</label>
NODEPS

# Table heads
$reporter->NOTE(
'|'
Expand Down Expand Up @@ -272,77 +337,45 @@ sub _get_extensions {
# is the version number read from FastReport, and {release} will be
# the latest release from there.

my $install = 'Study';
my $uninstall = '';
my $status = "";

if ( $ext->{installedRelease} ) {

# The module is installed; check the version
if ( $ext->{installedVersion} eq '9999.99_999' ) {

# pseudo-installed
$install = 'pseudo-installed';
$status = ' _is pseudo-installed_ ';
}
elsif ( $ext->compare_versions( '<', $ext->{release} ) ) {

# Installed version is < available version

$install = 'Upgrade';
$uninstall = 'Uninstall';
$status = ' *has a more recent version available* ';
}
else {

# Installed version is current version

$install = 'Re-install';
$uninstall = 'Uninstall';
$status = ' _is installed_ ';
}
}

$install = $reporter->WIZARD(
$install,
{
wizard => 'InstallExtensions',
method => 'depreport',
args => {
repository => $ext->{repository},
module => $ext->{name},
installable => ( $install ne 'pseudo-installed' ),

# SIMULATE =>
# NODEPS =>
# USELOCAL =>
}
}
);

if ($uninstall) {
$uninstall = $reporter->WIZARD(
$uninstall,
{
wizard => 'InstallExtensions',
method => 'remove',
args => {
repository => $ext->{repository},
module => $ext->{name},

# SIMULATE =>
# NODEPS =>
# USELOCAL =>
}
}
);
}

# Do the title + actions row
my $thd = $ext->{name} || 'Unknown';
$thd =~ s/!(\w+)/$1/g; # remove ! escape syntax from text
$thd = "[[$ext->{data}$ext->{name}][$thd]]";
$thd .= " <sup>[$ext->{repository}]</sup>"
if ( scalar(@consultedLocations) > 1 );

$reporter->NOTE(
"| $thd" . '|' x scalar( @{ $tableHeads{$set} } ) . " $install |" );
# The nice thing about checkboxes is that they don't get added
# to the query unless they are checked, and then the value returned
# is the value we give them here i.e. the repo
my $buttons = "<input type='checkbox' name='$ext->{name}'"
. " value='$ext->{repository}'/>";

$reporter->NOTE( "| $buttons $thd $status "
. '|' x ( scalar( @{ $tableHeads{$set} } ) ) );

# Do the data row
my @cols;
Expand All @@ -354,11 +387,10 @@ sub _get_extensions {
}
push( @cols, $tdd );
}
push( @cols, $uninstall );

$reporter->NOTE( '|' . join( '|', map { " $_ " } @cols ) . '|' );
}
$reporter->NOTE("</div>");
$reporter->NOTE("</form></div>");
}

=begin TML
Expand Down
126 changes: 42 additions & 84 deletions core/lib/Foswiki/Configure/Wizards/InstallExtensions.pm
Expand Up @@ -31,7 +31,7 @@ our $installRoot;

# Common initialisation
sub _getPackage {
my ( $this, $reporter, $seen ) = @_;
my ( $this, $reporter, $module, $repo, $seen ) = @_;

my ( $fwi, $ver, $fwp ) =
Foswiki::Configure::Dependency::extractModuleVersion( 'Foswiki', 1 );
Expand All @@ -46,16 +46,6 @@ sub _getPackage {

my $args = $this->param('args');

# SMELL: This is called with repository as a simple string in
# the Dependency report, and then again as a hash when running
# the installer. The fix is probably elsewhere to use consistent
# calls, but hack hack cough... this works.
my $repo = $args->{repository};
$repo = $repo->{name} if ( ref($repo) eq 'HASH' );

die "No repository specified" unless $args->{repository};
die "No extension specified" unless $args->{module};

my $repository;
foreach my $place (
Foswiki::Configure::Wizards::ExploreExtensions::findRepositories() )
Expand All @@ -67,24 +57,25 @@ sub _getPackage {
}
if ( !$repository ) {
if ( $args->{USELOCAL} ) {
$reporter->WARN(
"Repository not found: $args->{repository}",
"Will try to use previously downloaded local copy"
);
$reporter->WARN( "Repository not found: $repo",
"Will try to use previously downloaded local copy" );
}
else {
$reporter->ERROR(
"Repository $args->{repository} not found\n> Cannot proceed.");
$reporter->ERROR("Repository $repo not found\n> Cannot proceed.");
return undef;
}
}
delete $args->{repository};

my $pkg = Foswiki::Configure::Package->new(
root => $installRoot,
repository => $repository,
seen => $seen,
%$args
module => $module,
USELOCAL => $args->{USELOCAL},
EXPANDED => $args->{EXPANDED},
NODEPS => $args->{NODEPS},
SIMULATE => $args->{SIMULATE},
CONTINUE => $args->{CONTINUE},
);

return $pkg;
Expand All @@ -103,64 +94,27 @@ sub depreport {

my $seen = {}; # Hash to prevent duplicate installs

my $pkg = $this->_getPackage( $reporter, $seen );
return unless $pkg;

$reporter->NOTE( "---++ Dependency report for " . $pkg->module() );
$pkg->loadInstaller($reporter);
my ( $installed, $missing ) = $pkg->checkDependencies();
$reporter->NOTE( "> *INSTALLED*", map { "\t* $_" } @$installed )
if (@$installed);
if (@$missing) {
$reporter->NOTE( "> *MISSING*", map { "\t* $_" } @$missing );
$reporter->WARN( <<DEPS );
> *Caution:* If you proceed with install, the missing dependencies listed as _Required_
will be automatically installed. Be sure that this is what you want.
DEPS
}
else {
$reporter->NOTE("> All dependencies satisfied");
}
my $args = $this->param('args');

$reporter->WARN(
"\t* Click 'Install' to proceed with the installation.",
"\t* Click 'Simulate' to get a detailed report on what",
"\t will happen during installation."
);
while ( my ( $module, $repo ) = each %$args ) {

$reporter->WARN(
"\t* Click 'Install without Dependencies' to install",
"\t _only_ this extension, ignoring the dependencies."
) if (@$missing);

if ( $this->param('args')->{installable} ) {
my %data = (
wizard => 'InstallExtensions',
method => 'add',
args => {
repository => $pkg->repository(),
module => $pkg->module(),
SIMULATE => 0,
NODEPS => 0,

# USELOCAL =>
}
);
$reporter->NOTE( $reporter->WIZARD( "Install", \%data ) );

$data{args}->{SIMULATE} = 1;
$reporter->NOTE( $reporter->WIZARD( "Simulate", \%data ) );
my $pkg = $this->_getPackage( $reporter, $module, $repo, $seen );
next unless $pkg;

$reporter->NOTE( "---++ Dependency report for " . $pkg->module() );
$pkg->loadInstaller($reporter);
my ( $installed, $missing ) = $pkg->checkDependencies();
$reporter->NOTE( "> *INSTALLED*", map { "\t* $_" } @$installed )
if (@$installed);
if (@$missing) {
$data{args}->{SIMULATE} = 0;
$data{args}->{NODEPS} = 1;
$reporter->NOTE(
$reporter->WIZARD( "Install without dependencies", \%data ) );
$reporter->NOTE( "> *MISSING*", map { "\t* $_" } @$missing );
}
else {
$reporter->NOTE("> All dependencies satisfied");
}
}

$pkg->finish();
undef $pkg;
$pkg->finish();
}
}

=begin TML
Expand All @@ -175,18 +129,20 @@ sub add {
my ( $this, $reporter ) = @_;
my $seen = {};

my $pkg = $this->_getPackage( $reporter, $seen );
return unless $pkg;
my $args = $this->param('args');
while ( my ( $module, $repo ) = each %$args ) {
my $pkg = $this->_getPackage( $reporter, $module, $repo, $seen );
next unless $pkg;

my $extension = $pkg->module();
unless ( $pkg->install($reporter) ) {
$reporter->ERROR( <<OMG );
my $extension = $pkg->module();
unless ( $pkg->install($reporter) ) {
$reporter->ERROR( <<OMG );
The Extension may not be usable due to errors. Installation terminated.
OMG
}
}

$pkg->finish();
undef $pkg;
$pkg->finish();
}

return undef; # return the report
}
Expand All @@ -202,13 +158,15 @@ Uninstall an extension
sub remove {
my ( $this, $reporter ) = @_;

my $pkg = $this->_getPackage($reporter);
return unless $pkg;
my $args = $this->param('args');
while ( my ( $module, $repo ) = each %$args ) {
my $pkg = $this->_getPackage( $reporter, $module, $repo );
next unless $pkg;

$pkg->uninstall($reporter);
$pkg->uninstall($reporter);

$pkg->finish();
undef $pkg;
$pkg->finish();
}

return undef;
}
Expand Down

0 comments on commit 74a7bc1

Please sign in to comment.