fix: Shortcuts now follow their linked asset when trashing, purging, and restoring from trash
This commit is contained in:
parent
e41f544f4f
commit
f684e728c8
4 changed files with 162 additions and 18 deletions
|
|
@ -1976,6 +1976,16 @@ sub publish {
|
|||
$cache->deleteChunk(["asset",$id]);
|
||||
}
|
||||
$self->{_properties}{state} = "published";
|
||||
|
||||
# Also publish any shortcuts to this asset that are in the trash
|
||||
my $shortcuts
|
||||
= WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId, {
|
||||
returnObjects => 1,
|
||||
statesToInclude => ['trash','trash-limbo'],
|
||||
});
|
||||
for my $shortcut ( @$shortcuts ) {
|
||||
$shortcut->publish;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ package WebGUI::Asset::Shortcut;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Carp;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::International;
|
||||
|
|
@ -906,5 +907,43 @@ sub www_view {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head1 STATIC METHODS
|
||||
|
||||
These methods are called using CLASS->method
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getShortcutsForAssetId ( session, assetId [, properties] )
|
||||
|
||||
Get an arrayref of assetIds of all the shortcuts for the passed-in assetId.
|
||||
|
||||
"properties" is a hash reference of properties to give to getLineage.
|
||||
Probably the only useful key will be "returnObjects".
|
||||
|
||||
=cut
|
||||
|
||||
sub getShortcutsForAssetId {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $assetId = shift;
|
||||
my $properties = shift || {};
|
||||
|
||||
croak "First argument to getShortcutsForAssetId must be WebGUI::Session"
|
||||
unless $session && $session->isa("WebGUI::Session");
|
||||
croak "Second argument to getShortcutsForAssetId must be assetId"
|
||||
unless $assetId;
|
||||
croak "Third argument to getShortcutsForAssetId must be hash reference"
|
||||
if $properties && !ref $properties eq "HASH";
|
||||
|
||||
my $db = $session->db;
|
||||
|
||||
$properties->{ joinClass } = 'WebGUI::Asset::Shortcut';
|
||||
$properties->{ whereClause } = 'Shortcut.shortcutToAssetId = ' . $db->quote($assetId);
|
||||
|
||||
return WebGUI::Asset->getRoot($session)->getLineage(['descendants'], $properties);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,16 @@ sub purge {
|
|||
}
|
||||
}
|
||||
|
||||
# Delete shortcuts to this asset
|
||||
# Also publish any shortcuts to this asset that are in the trash
|
||||
my $shortcuts
|
||||
= WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId, {
|
||||
returnObjects => 1,
|
||||
});
|
||||
for my $shortcut ( @$shortcuts ) {
|
||||
$shortcut->purge;
|
||||
}
|
||||
|
||||
# gotta delete stuff we've exported
|
||||
unless ($options->{skipExported}) {
|
||||
$self->_invokeWorkflowOnExportedFiles($self->session->setting->get('purgeWorkflow'), 1);
|
||||
|
|
@ -178,29 +188,40 @@ sub purge {
|
|||
|
||||
=head2 trash ( )
|
||||
|
||||
Removes asset from lineage, places it in trash state. The "gap" in the lineage is changed in state to trash-limbo.
|
||||
Removes asset from lineage, places it in trash state. The "gap" in the
|
||||
lineage is changed in state to trash-limbo.
|
||||
|
||||
=cut
|
||||
|
||||
sub trash {
|
||||
my $self = shift;
|
||||
return undef if ($self->getId eq $self->session->setting->get("defaultPage") || $self->getId eq $self->session->setting->get("notFoundPage"));
|
||||
foreach my $asset ($self, @{$self->getLineage(['descendants'], {returnObjects => 1})}) {
|
||||
$asset->_invokeWorkflowOnExportedFiles($self->session->setting->get('trashWorkflow'), 1);
|
||||
}
|
||||
my $self = shift;
|
||||
return undef if ($self->getId eq $self->session->setting->get("defaultPage") || $self->getId eq $self->session->setting->get("notFoundPage"));
|
||||
for my $asset ($self, @{$self->getLineage(['descendants'], {returnObjects => 1})}) {
|
||||
$asset->_invokeWorkflowOnExportedFiles($self->session->setting->get('trashWorkflow'), 1);
|
||||
}
|
||||
|
||||
my $db = $self->session->db;
|
||||
$db->beginTransaction;
|
||||
my $sth = $db->read("select assetId from asset where lineage like ?",[$self->get("lineage").'%']);
|
||||
while (my ($id) = $sth->array) {
|
||||
$db->write("delete from assetIndex where assetId=?",[$id]);
|
||||
}
|
||||
$db->write("update asset set state='trash-limbo' where lineage like ?",[$self->get("lineage").'%']);
|
||||
$db->write("update asset set state='trash', stateChangedBy=?, stateChanged=? where assetId=?",[$self->session->user->userId, $self->session->datetime->time(), $self->getId]);
|
||||
$db->commit;
|
||||
$self->{_properties}{state} = "trash";
|
||||
$self->updateHistory("trashed");
|
||||
$self->purgeCache;
|
||||
# Trash any shortcuts to this asset
|
||||
my $shortcuts
|
||||
= WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId, { returnObjects => 1});
|
||||
for my $shortcut ( @$shortcuts ) {
|
||||
$shortcut->trash;
|
||||
}
|
||||
|
||||
# Raw database work is more efficient than $asset->update
|
||||
my $db = $self->session->db;
|
||||
$db->beginTransaction;
|
||||
my $sth = $db->read("select assetId from asset where lineage like ?",[$self->get("lineage").'%']);
|
||||
while (my ($id) = $sth->array) {
|
||||
$db->write("delete from assetIndex where assetId=?",[$id]);
|
||||
}
|
||||
$db->write("update asset set state='trash-limbo' where lineage like ?",[$self->get("lineage").'%']);
|
||||
$db->write("update asset set state='trash', stateChangedBy=?, stateChanged=? where assetId=?",[$self->session->user->userId, $self->session->datetime->time(), $self->getId]);
|
||||
$db->commit;
|
||||
|
||||
# Update ourselves since we didn't use update()
|
||||
$self->{_properties}{state} = "trash";
|
||||
$self->updateHistory("trashed");
|
||||
$self->purgeCache;
|
||||
}
|
||||
|
||||
require WebGUI::Workflow::Activity::DeleteExportedFiles;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue