Instrument www_demote, www_promote, demote, promote and swapRank with ProgressBar code.

This commit is contained in:
Colin Kuskie 2009-06-19 15:34:31 +00:00
parent cbc308c55a
commit e518dbe1b3
4 changed files with 70 additions and 18 deletions

View file

@ -17,6 +17,7 @@
- fixed #10551: paypal (link to section of paypal website to enter in WebGUI information) - fixed #10551: paypal (link to section of paypal website to enter in WebGUI information)
- fixed #10550: shipping plugins have no privileges - fixed #10550: shipping plugins have no privileges
- fixed: Add progress bars for paste and edit branch. - fixed: Add progress bars for paste and edit branch.
- fixed: Add progress bars for promote and demote.
- fixed: SurveyJSON database bloating - fixed: SurveyJSON database bloating
7.7.10 7.7.10

View file

@ -333,6 +333,8 @@ sub www_editBranchSave {
}; };
delete $self->{_parent}; delete $self->{_parent};
$self->session->asset($self->getParent); $self->session->asset($self->getParent);
##Since this method originally returned the user to the AssetManager, we don't need
##to use $pb->finish to redirect back there.
return $self->getParent->www_manageAssets; return $self->getParent->www_manageAssets;
} }

View file

@ -138,14 +138,20 @@ Swaps lineage with sister below. Returns 1 if there is a sister to swap. Otherwi
This will update the lineage of $self, but not the sister. This will update the lineage of $self, but not the sister.
=head3 outputSub
A reference to a subroutine that output messages should be sent to. Typically this would
go to ProgressBar.
=cut =cut
sub demote { sub demote {
my $self = shift; my $self = shift;
my $outputSub = shift || sub {};
my ($sisterLineage) = $self->session->db->quickArray("select min(lineage) from asset my ($sisterLineage) = $self->session->db->quickArray("select min(lineage) from asset
where parentId=? and state='published' and lineage>?",[$self->get('parentId'), $self->get('lineage')]); where parentId=? and state='published' and lineage>?",[$self->get('parentId'), $self->get('lineage')]);
if (defined $sisterLineage) { if (defined $sisterLineage) {
$self->swapRank($sisterLineage); $self->swapRank($sisterLineage, undef, $outputSub);
$self->{_properties}{lineage} = $sisterLineage; $self->{_properties}{lineage} = $sisterLineage;
return 1; return 1;
} }
@ -789,20 +795,26 @@ sub newByLineage {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 promote ( ) =head2 promote ( [ $outputSub ] )
Keeps the same rank of lineage, swaps with sister above. Returns 1 if there is a sister to swap. Otherwise returns 0. Keeps the same rank of lineage, swaps with sister above. Returns 1 if there is a sister to swap. Otherwise returns 0.
This will update the lineage of $self, but not the sister. This will update the lineage of $self, but not the sister.
=head3 outputSub
A reference to a subroutine that output messages should be sent to. Typically this would
go to ProgressBar.
=cut =cut
sub promote { sub promote {
my $self = shift; my $self = shift;
my $outputSub = shift || sub {};
my ($sisterLineage) = $self->session->db->quickArray("select max(lineage) from asset my ($sisterLineage) = $self->session->db->quickArray("select max(lineage) from asset
where parentId=? and state='published' and lineage<?",[$self->get("parentId"), $self->get("lineage")]); where parentId=? and state='published' and lineage<?",[$self->get("parentId"), $self->get("lineage")]);
if (defined $sisterLineage) { if (defined $sisterLineage) {
$self->swapRank($sisterLineage); $self->swapRank($sisterLineage, undef, $outputSub);
$self->{_properties}{lineage} = $sisterLineage; $self->{_properties}{lineage} = $sisterLineage;
return 1; return 1;
} }
@ -898,13 +910,16 @@ no in the objects.
=cut =cut
sub swapRank { sub swapRank {
my $self = shift; my $self = shift;
my $second = shift; my $second = shift;
my $first = shift || $self->get("lineage"); my $first = shift || $self->get("lineage");
my $outputSub = shift || sub {};
my $temp = substr($self->session->id->generate(),0,6); # need a temp in order to do the swap my $temp = substr($self->session->id->generate(),0,6); # need a temp in order to do the swap
$self->session->db->beginTransaction; $self->session->db->beginTransaction;
$outputSub->('swap first'); ##Note, i18n call passed in from caller-1
$self->cascadeLineage($temp,$first); $self->cascadeLineage($temp,$first);
$self->cascadeLineage($first,$second); $self->cascadeLineage($first,$second);
$outputSub->('swap second');
$self->cascadeLineage($second,$temp); $self->cascadeLineage($second,$temp);
$self->session->db->commit; $self->session->db->commit;
$self->updateHistory("swapped lineage between ".$first." and ".$second); $self->updateHistory("swapped lineage between ".$first." and ".$second);
@ -921,10 +936,15 @@ Demotes self and returns www_view method of getContainer of self if canEdit, oth
=cut =cut
sub www_demote { sub www_demote {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; my $session = $self->session;
$self->demote; return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->asset($self->getContainer)->www_view; my $i18n = WebGUI::International->new($session, 'Asset');
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($i18n->get('demote'), $session->url->extras('adminConsole/assets.gif'));
$pb->update(sprintf $i18n->get('demote %s'), $self->getTitle);
$self->demote(sub{ $pb->update($i18n->get(shift))});
$pb->finish($self->getContainer->getUrl);
} }
@ -937,10 +957,15 @@ Returns www_view method of getContainer of self. Promotes self. If canEdit is Fa
=cut =cut
sub www_promote { sub www_promote {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; my $session = $self->session;
$self->promote; return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->asset($self->getContainer)->www_view; my $i18n = WebGUI::International->new($session, 'Asset');
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($i18n->get('promote'), $session->url->extras('adminConsole/assets.gif'));
$pb->update(sprintf $i18n->get('promote %s'), $self->getTitle);
$self->promote(sub{ $pb->update($i18n->get(shift))});
$pb->finish($self->getContainer->getUrl);
} }

View file

@ -217,13 +217,31 @@ our $I18N = {
'restore' => { 'restore' => {
message => q|Restore|, message => q|Restore|,
lastUpdated => 0, lastUpdated => 0,
context => q|Used in asset context menus.| context => q|Used in asset context menus.|,
}, },
'promote' => { 'promote' => {
message => q|Promote|, message => q|Promote|,
lastUpdated => 0, lastUpdated => 0,
context => q|Used in asset context menus.| context => q|Used in asset context menus.|,
},
'promote %s' => {
message => q|promote %s|,
lastUpdated => 0,
context => q|Used in asset context menus.|,
},
'swap first' => {
message => q|swap first|,
lastUpdated => 0,
context => q|swap, to exchange places|,
},
'swap second' => {
message => q|swap second|,
lastUpdated => 0,
context => q|swap, to exchange places|,
}, },
'promote help' => { 'promote help' => {
@ -242,6 +260,12 @@ our $I18N = {
lastUpdated => 0, lastUpdated => 0,
}, },
'demote %s' => {
message => q|demote %s|,
lastUpdated => 0,
context => q|Used in asset context menus.|,
},
'cut' => { 'cut' => {
message => q|Cut|, message => q|Cut|,
lastUpdated => 0, lastUpdated => 0,