Mailing List Archive

Add output channel to all stories returned by query
I have added new output channels to an element type, and since I have
hundreds of stories already in existence & published in the element type,
I'd like to add the new output channels and republish each.

I don't see any method that does so on a story level in the API docs. Can
anyone suggest a way?

To be clear what I'm asking:

When a new story is created, it has all the output channels defined by the
element type, but old stories don't get them automatically when publishing
or modifying the element type.

Thanks & Happy new year!

Bryan
RE: Add output channel to all stories returned by query [ In reply to ]
> I have added new output channels to an element type, and since I have
> hundreds of stories already in existence & published in the element type,
> I'd like to add the new output channels and republish each.

If I understand you correctly, I think I had a similar situation. We created a separate mobile site whose content was the same, but the markup was different. Instead of adding the new mobile OC to all the existing stories, I created a utility template that was executed anytime a story was previewed or published again. So when I republished the entire site, the new output channel was automatically added.

>
> I don't see any method that does so on a story level in the API docs. Can
> anyone suggest a way?
>
> To be clear what I'm asking:
>
> When a new story is created, it has all the output channels defined by the
> element type, but old stories don't get them automatically when publishing
> or modifying the element type.

Not sure if this is the best way, but this worked for me. Create a utility template so you can use it in any of your story element types. In my case, it was saved as '/util/mobile_oc.mc'.

<%args>
$current_oc_id => undef # ID of OC currently being processed
</%args>
<%init>
my $target_oc_id;

# determine what the new OC ID is
if ($current_oc_id == 1) { # 1 is original OC
$target_oc_id = 1035; # 1035 is new OC
} elsif ($current_oc_id == 1034) { # 1034 is an another original OC
$target_oc_id = 1040; # 1040 is new OC
}

# check if we need to add the new OC (assuming it isn't the OC that called this template)
if ($target_oc_id && $current_oc_id != $target_oc_id) {
my $mobile_oc = Bric::Biz::OutputChannel->lookup({ id => "$target_oc_id" }); # get OC object
my @ocs = $story->get_output_channels; # get all currently assigned OC's
my $need = 1; # assume we need to add it
# check to make sure the new OC hasn't already been assigned
foreach my $oc (@ocs) {
$need = 0 if ($oc->get_id == $target_oc_id);
}
# if new OC is still needed, add it and save story
if ($need) {
$story->add_output_channels($mobile_oc);
$story->save;
}
}
return 1;
</%init>

Then from your story template for the original OC, add:

my $oc_id = $burner->get_oc->get_id; # get output channel ID
$m->comp('/util/mobile_oc.mc', current_oc_id => $oc_id);

>
> Thanks & Happy new year!
>
> Bryan
Re: Add output channel to all stories returned by query [ In reply to ]
Fantastic thanks very much -- that method "add_output_channels" was what I
couldn't find on the story object docs

I'll likely do something very similar to this code


CHeers,

Bryan


On Mon, Dec 31, 2012 at 4:18 PM, Schults, Chris <chris.schults@pccsea.com>wrote:

> > I have added new output channels to an element type, and since I have
> > hundreds of stories already in existence & published in the element type,
> > I'd like to add the new output channels and republish each.
>
> If I understand you correctly, I think I had a similar situation. We
> created a separate mobile site whose content was the same, but the markup
> was different. Instead of adding the new mobile OC to all the existing
> stories, I created a utility template that was executed anytime a story was
> previewed or published again. So when I republished the entire site, the
> new output channel was automatically added.
>
> >
> > I don't see any method that does so on a story level in the API docs. Can
> > anyone suggest a way?
> >
> > To be clear what I'm asking:
> >
> > When a new story is created, it has all the output channels defined by
> the
> > element type, but old stories don't get them automatically when
> publishing
> > or modifying the element type.
>
> Not sure if this is the best way, but this worked for me. Create a utility
> template so you can use it in any of your story element types. In my case,
> it was saved as '/util/mobile_oc.mc'.
>
> <%args>
> $current_oc_id => undef # ID of OC currently being processed
> </%args>
> <%init>
> my $target_oc_id;
>
> # determine what the new OC ID is
> if ($current_oc_id == 1) { # 1 is original OC
> $target_oc_id = 1035; # 1035 is new OC
> } elsif ($current_oc_id == 1034) { # 1034 is an another original OC
> $target_oc_id = 1040; # 1040 is new OC
> }
>
> # check if we need to add the new OC (assuming it isn't the OC that called
> this template)
> if ($target_oc_id && $current_oc_id != $target_oc_id) {
> my $mobile_oc = Bric::Biz::OutputChannel->lookup({ id => "$target_oc_id"
> }); # get OC object
> my @ocs = $story->get_output_channels; # get all currently assigned OC's
> my $need = 1; # assume we need to add it
> # check to make sure the new OC hasn't already been assigned
> foreach my $oc (@ocs) {
> $need = 0 if ($oc->get_id == $target_oc_id);
> }
> # if new OC is still needed, add it and save story
> if ($need) {
> $story->add_output_channels($mobile_oc);
> $story->save;
> }
> }
> return 1;
> </%init>
>
> Then from your story template for the original OC, add:
>
> my $oc_id = $burner->get_oc->get_id; # get output channel ID
> $m->comp('/util/mobile_oc.mc', current_oc_id => $oc_id);
>
> >
> > Thanks & Happy new year!
> >
> > Bryan
>
RE: Add output channel to all stories returned by query [ In reply to ]
> Fantastic thanks very much -- that method "add_output_channels" was what I
> couldn't find on the story object docs

You're welcome. It is under Bric::Biz::Asset::Business in the online documentation.

>
> I'll likely do something very similar to this code
>
>
> CHeers,
>
> Bryan