Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for bug 1176, fail on auto-publish of checked out related assets

  • Loading branch information...
commit f774051845e675c0cda629a6458d774ce6750862 1 parent aed270c
@paulorrock paulorrock authored
View
8 conf/bricolage.conf
@@ -293,6 +293,14 @@ DEFAULT_FILE_EXT = html
PUBLISH_RELATED_ASSETS = Yes
+# When publishing related assets (above) the publish process will fail if the
+# any the related assets cannot be published automatically, due to being
+# checked out or not on a publish desk. If you want the process to just supply
+# warnings but allow the publish then PUBLISH_RELATED_FAIL_BEHAVIOUR should be
+# set to warn rather than fail.
+
+PUBLISH_RELATED_FAIL_BEHAVIOUR = fail
+
# Output Channel asset association. Story and Media profiles contain an
# 'Output Channels' section which lets you associate output channels
# with a particular story or media object, separate from the association
View
48 lib/Bric/App/Callback/Desk.pm
@@ -23,6 +23,8 @@ use Bric::Util::Burner;
use Bric::Util::DBI qw(:junction);
use Bric::Util::Priv::Parts::Const qw(:all);
use Bric::Util::Time qw(strfdate);
+use Bric::Util::Fault qw(throw_error);
+use Bric::App::Event qw(clear_events);
my $pkgs = {
story => 'Bric::Biz::Asset::Business::Story',
@@ -181,6 +183,9 @@ sub publish : Callback {
my (@sids, @mids, %desks);
my %seen;
+ my $publish_fail;
+ my @messages;
+
for ([story => \@stories, $story_pub],
[media => \@media, $media_pub]
) {
@@ -196,17 +201,19 @@ sub publish : Callback {
unless (chk_authz($doc, PUBLISH, 1)) {
my $doc_disp_name = lc get_disp_name($key);
- add_msg('You do not have permission to publish '
- . qq{$doc_disp_name "[_1]"}, $doc->get_name);
+ push @messages,['You do not have permission to publish '
+ . qq{$doc_disp_name "[_1]"}, $doc->get_name];
+ $publish_fail++;
next;
}
if ($doc->get_checked_out) {
# Cannot publish checked-out assets.
my $doc_disp_name = lc get_disp_name($key);
- add_msg("Cannot publish $doc_disp_name \"[_1]\" because it is"
- . " checked out.", $doc->get_name);
+ push @messages,["Cannot publish $doc_disp_name \"[_1]\" because it is"
+ . " checked out.", $doc->get_name];
delete $pub_ids->{$vid};
+ $publish_fail++;
next;
}
@@ -232,9 +239,10 @@ sub publish : Callback {
if ($rel->get_checked_out) {
# Cannot publish checked-out assets.
my $rel_disp_name = lc get_disp_name($rel->key_name);
- add_msg("Cannot auto-publish related $rel_disp_name "
+ push @messages,["Cannot auto-publish related $rel_disp_name "
. '"[_1]" because it is checked out.',
- $rel->get_name);
+ $rel->get_name];
+ $publish_fail++;
next;
}
@@ -247,9 +255,10 @@ sub publish : Callback {
});
unless ($desk->can_publish) {
my $rel_disp_name = lc get_disp_name($rel->key_name);
- add_msg("Cannot auto-publish related $rel_disp_name "
+ push @messages,["Cannot auto-publish related $rel_disp_name "
. '"[_1]" because it is not on a publish desk.',
- $rel->get_name);
+ $rel->get_name];
+ $publish_fail++;
next;
}
}
@@ -257,8 +266,9 @@ sub publish : Callback {
unless (chk_authz($rel, PUBLISH, 1)) {
# Permission denied!
my $rel_disp_name = lc get_disp_name($rel->key_name);
- add_msg('You do not have permission to auto-publish '
- . qq{$rel_disp_name "[_1]"}, $rel->get_name);
+ push @messages,['You do not have permission to auto-publish '
+ . qq{$rel_disp_name "[_1]"}, $rel->get_name];
+ $publish_fail++;
next;
}
@@ -287,6 +297,24 @@ sub publish : Callback {
}
+ # By this point we now know if we're going to fail this publish
+ # if we set the fail behaviour to fail rather than warn
+ if ((PUBLISH_RELATED_ASSETS) && ($publish_fail)) {
+ if (PUBLISH_RELATED_FAIL_BEHAVIOUR eq "fail") {
+ clear_msg();
+ clear_events();
+ foreach my $arrayref (@messages) { add_msg(@$arrayref); }
+ add_msg('Publish ABORTED due to errors above. Please fix these and retry.');
+ throw_error( [get_msg()]);
+ } else {
+ # we are set to warn, should we add a further warning to the msg ?
+ foreach my $arrayref (@messages) { add_msg(@$arrayref); }
+ add_msg('Some of the related assets cannot be published automatically.');
+ }
+ } else {
+ foreach my $arrayref (@messages) { add_msg(@$arrayref); }
+ }
+
# For publishing from a desk, I added two new 'publish'
# state data: 'rel_story', 'rel_media'. This is to be
# able to distinguish between related assets and the
View
2  lib/Bric/App/Callback/Profile/Media.pm
@@ -279,6 +279,8 @@ sub checkin : Callback(priority => 6) {
apache_req => $self->apache_req,
params => { media_pub => { $media->get_version_id => $media } },
);
+ $self->clear_my_state;
+ $self->set_redirect("/");
$pub->publish;
} else {
View
2  lib/Bric/App/Callback/Profile/Story.pm
@@ -195,6 +195,8 @@ sub checkin : Callback(priority => 6) {
apache_req => $self->apache_req,
params => { story_pub => { $story->get_version_id => $story } },
);
+ $self->clear_my_state;
+ $self->set_redirect("/");
$pub->publish;
} else {
View
7 lib/Bric/Changes.pod
@@ -79,6 +79,13 @@ template classes. [David]
Aliases are now indicated in Find Stories by an arrow icon just before the
story title. Suggested by Paul Orrock. [David]
+=item *
+
+Added PUBLISH_RELATED_FAIL_BEHAVIOUR directive to be used when auto publishing
+related assets. If the auto publish of a related story or media asset will not
+be possible then the publish request will fail. It can be changed to warn, the
+previous behaviour, if required. [Paul Orrock]
+
=back
=head2 Bug Fixes
View
5 lib/Bric/Config.pm
@@ -98,6 +98,7 @@ our @EXPORT_OK = qw(DBD_PACKAGE
ADMIN_GRP_ID
PASSWD_LENGTH
PUBLISH_RELATED_ASSETS
+ PUBLISH_RELATED_FAIL_BEHAVIOUR
LOGIN_LENGTH
ERROR_URI
ENABLE_DIST
@@ -241,7 +242,8 @@ our %EXPORT_TAGS = (all => \@EXPORT_OK,
MASON_COMP_ROOT
AUTO_PREVIEW_MEDIA
PREVIEW_MASON)],
- pub => [qw(PUBLISH_RELATED_ASSETS)],
+ pub => [qw(PUBLISH_RELATED_ASSETS
+ PUBLISH_RELATED_FAIL_BEHAVIOUR)],
dist => [qw(ENABLE_DIST
QUEUE_PUBLISH_JOBS
FTP_UNLINK_BEFORE_MOVE
@@ -559,6 +561,7 @@ require Bric; our $VERSION = Bric->VERSION;
# Publishing Settings.
use constant PUBLISH_RELATED_ASSETS => $config->{PUBLISH_RELATED_ASSETS};
+ use constant PUBLISH_RELATED_FAIL_BEHAVIOUR => $config->{PUBLISH_RELATED_FAIL_BEHAVIOUR} || 'warn';
# Mason settings.
use constant MASON_COMP_ROOT => PREVIEW_LOCAL && PREVIEW_MASON ?
Please sign in to comment.
Something went wrong with that request. Please try again.