From: <bra...@kr...> - 2013-10-21 18:45:38
|
Revision: 6930 Author: bradoaks Date: 2013-10-21 14:45:31 -0400 (Mon, 21 Oct 2013) Log Message: ----------- track the original story that is responsible for any linked assets which are published Modified Paths: -------------- trunk/krang/docs/changelog.pod trunk/krang/lib/Krang/CGI/History.pm trunk/krang/lib/Krang/History.pm trunk/krang/lib/Krang/Publisher.pm trunk/krang/sql/history.sql trunk/krang/upgrade/V3_24.pm Modified: trunk/krang/docs/changelog.pod =================================================================== --- trunk/krang/docs/changelog.pod 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/docs/changelog.pod 2013-10-21 18:45:31 UTC (rev 6930) @@ -22,6 +22,14 @@ Fixed bug where tag information was lost on stories when editting the categories. [Michael Peters] +=item * + +Scheduled jobs created after this release record the user_id for use in add_history. [Brad Oaks] + +=item * + +The history screen will show that an asset is published because of its link to another asset. [Brad Oaks] + =back =head2 3.23 - July 31st, 2013 Modified: trunk/krang/lib/Krang/CGI/History.pm =================================================================== --- trunk/krang/lib/Krang/CGI/History.pm 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/lib/Krang/CGI/History.pm 2013-10-21 18:45:31 UTC (rev 6930) @@ -233,6 +233,8 @@ $attr .= localize("Desk:") . ' ' . localize((pkg('Desk')->find(desk_id => $history->desk_id))[0]->name) if $history->desk_id; + $attr .= localize("from") . ' ' . $history->origin + if $history->origin; $row->{attr} = $q->escapeHTML($attr); } Modified: trunk/krang/lib/Krang/History.pm =================================================================== --- trunk/krang/lib/Krang/History.pm 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/lib/Krang/History.pm 2013-10-21 18:45:31 UTC (rev 6930) @@ -83,7 +83,7 @@ =cut sub fields { - return qw( object_type object_id action version desk_id user_id schedule_id timestamp ); + return qw( object_type object_id action version desk_id user_id schedule_id origin timestamp ); } } Modified: trunk/krang/lib/Krang/Publisher.pm =================================================================== --- trunk/krang/lib/Krang/Publisher.pm 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/lib/Krang/Publisher.pm 2013-10-21 18:45:31 UTC (rev 6930) @@ -453,6 +453,8 @@ $history_args{schedule_id} = $args{schedule_id}; } + my $implication_map = { map {$self->_implication_key($_) => 'original publish list'} (ref $story eq 'ARRAY') ? @$story : ($story) }; + # callbacks my $callback = $args{callback}; my $skip_callback = $args{skip_callback}; @@ -502,6 +504,7 @@ } else { $publish_list = $self->asset_list( story => $story, + implication_map => $implication_map, version_check => $version_check, maintain_versions => $maintain_versions ); @@ -509,6 +512,7 @@ $self->_process_assets( publish_list => $publish_list, + implication_map => $implication_map, skip_callback => $skip_callback, callback => $callback, user_id => $user_id, @@ -792,6 +796,7 @@ if ( exists($args{scheduled_by}) ) { $history_args{scheduled_by} = $args{scheduled_by}; } + my $implication_map = { map {$self->_implication_key($_) => 'original publish list'} (ref $args{media} eq 'ARRAY') ? @{$args{media}} : ($args{media}) }; my $publish_list; if (ref $args{media} eq 'ARRAY') { @@ -800,10 +805,11 @@ push @$publish_list, $args{media}; } - $publish_list = $self->_add_category_linked_stories($publish_list) unless $ENV{KRANG_TEST}; + $publish_list = $self->_add_category_linked_stories($publish_list, $implication_map) unless $ENV{KRANG_TEST}; my @urls = $self->_process_assets( publish_list => $publish_list, + implication_map => $implication_map, skip_callback => $skip_callback, callback => $callback, user_id => $ENV{REMOTE_USER}, @@ -886,6 +892,7 @@ my $story = $args{story} || croak __PACKAGE__ . ": Missing parameter 'story'"; my $mode = $args{mode}; + my $implication_map = $args{implication_map}; # my $keep_list = $args{keep_asset_list} || 0; # my $keep_list = 0; @@ -908,13 +915,14 @@ my @publish_list = $self->_build_asset_list( object => $story, + implication_map => $implication_map, version_check => $version_check, maintain_versions => $maintain_versions, initial_assets => 1 ); my $publish_list = \@publish_list; - $publish_list = $self->_add_category_linked_stories($publish_list) + $publish_list = $self->_add_category_linked_stories($publish_list, $implication_map) if $mode eq 'publish' and not $ENV{KRANG_TEST}; # unless ($keep_list) { @@ -975,6 +983,7 @@ my @media_urls; foreach my $object (@{$args{publish_list}}) { + $args{history_args}{origin} = $self->_stringify_implication_chain($args{implication_map}, $object); if ($object->isa('Krang::Story')) { if ($object->checked_out) { if ($user_id != $object->checked_out_by) { @@ -2051,6 +2060,7 @@ my ($self, %args) = @_; my $object = $args{object}; + my $implication_map = $args{implication_map}; my $version_check = (exists($args{version_check})) ? $args{version_check} : 1; my $initial_assets = (exists($args{initial_assets})) ? $args{initial_assets} : 0; my $maintain_versions = (exists($args{maintain_versions})) ? $args{maintain_versions} : 0; @@ -2088,8 +2098,16 @@ if ($check_links) { my $check_stories = !($self->is_preview && IgnorePreviewRelatedStoryAssets); my $check_media = !($self->is_preview && IgnorePreviewRelatedMediaAssets); - push @check_list, $o->linked_stories(publisher => $self) if $check_stories; - push @check_list, $o->linked_media if $check_media; + if ($check_stories) { + my @linked_stories = $o->linked_stories(publisher => $self); + $self->_update_implication_map($implication_map, $o, \@linked_stories); + push @check_list, @linked_stories; + } + if ($check_media) { + my @linked_media = $o->linked_media; + $self->_update_implication_map($implication_map, $o, \@linked_media); + push @check_list, @linked_media; + } } } @@ -2097,6 +2115,7 @@ push @asset_list, $self->_build_asset_list( object => \@check_list, + implication_map => $implication_map, version_check => $version_check, maintain_versions => $maintain_versions, initial_assets => 0, @@ -2105,6 +2124,41 @@ return @asset_list; } +sub _stringify_implication_chain { + my $self = shift; + my $implication_map = shift; + my $o = shift; + die "Error: cannot find a chain without a starting point" unless $o; + + my $object_key = $self->_implication_key($o); + die sprintf 'Error: object_key [%s] not found in implication_map', ($object_key || '-undef-') + unless (defined $implication_map->{$object_key}); + return if ($implication_map->{$object_key} eq 'original publish list'); + return $implication_map->{$object_key}; +} +sub _update_implication_map { + my $self = shift; + my $implication_map = shift; + my $o = shift; + my $linked_assets = shift; + my $object_key = $self->_implication_key($o); + map { + my $candidate_key = $self->_implication_key($_); + next if $implication_map->{$candidate_key}; + $implication_map->{$candidate_key} = $object_key; + } @{$linked_assets}; +} + +sub _implication_key { + my $self = shift; + my $o = shift; + if ($o->isa('Krang::Story')) { + return 'story' . $o->story_id; + } else { + return 'media' . $o->media_id; + } +} + # # ($publish_ok, $check_links) = _check_object_status(object => $object, # initial_assets => 1 @@ -2553,7 +2607,7 @@ } sub _add_category_linked_stories { - my ($self, $publish_list) = @_; + my ($self, $publish_list, $implication_map) = @_; my $user_id = $ENV{REMOTE_USER}; my %linked_stories = (); @@ -2614,6 +2668,7 @@ ) { $linked_stories{$candidate_story_id} = $candidate; + $self->_update_implication_map($implication_map, $object, [$candidate]); } } } @@ -2655,6 +2710,7 @@ ) { $linked_stories{$candidate_story_id} = $candidate; + $self->_update_implication_map($implication_map, $object, [$candidate]); } } } Modified: trunk/krang/sql/history.sql =================================================================== --- trunk/krang/sql/history.sql 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/sql/history.sql 2013-10-21 18:45:31 UTC (rev 6930) @@ -12,6 +12,7 @@ desk_id int(10) unsigned default NULL, user_id int(10) unsigned not NULL, schedule_id int(10) unsigned default NULL, + origin varchar(255) default NULL, timestamp datetime default NULL, INDEX (object_type, object_id) ) ENGINE=MyISAM; Modified: trunk/krang/upgrade/V3_24.pm =================================================================== --- trunk/krang/upgrade/V3_24.pm 2013-10-21 18:45:15 UTC (rev 6929) +++ trunk/krang/upgrade/V3_24.pm 2013-10-21 18:45:31 UTC (rev 6930) @@ -11,7 +11,8 @@ return if $args{no_db}; my $dbh = dbh(); $dbh->do('ALTER TABLE history - ADD COLUMN `schedule_id` INT(10) UNSIGNED DEFAULT NULL after `user_id` + ADD COLUMN `schedule_id` INT(10) UNSIGNED DEFAULT NULL after `user_id`, + ADD COLUMN `origin` VARCHAR(255) DEFAULT NULL after `schedule_id` '); } |