List Info

Thread: changing output channel on several thousand media items




changing output channel on several thousand media items
user name
2007-02-22 19:09:20
I have to swap the output channel from one to another on
several
thousand media files and then republish them.  There are a 7
element
types that, by element_type definition, used to be
associated with the
HTML output channel.  I have since changed these 7
element_types to
use a new output channel that has a different URL format.

The problem is that I've got all the old photos that were
created
before this change and I need to republish them so that they
get the
new URL format specified by this new OC.  However, simply
republishing
them doesn't do this.  When I open an old media file of this
sort, I
have the ability to add the new OC and remove the old one,
but it is
not automatically done already just by having redefined the
element_type's OCs.

Would the easiest way to do this be to write a script to
actually
check out each media file, drop output channel A, add OC B,
and then
republish?  (rather than try to run queries to do this
directly in the
DB)?

best,
JD

Re: changing output channel on several thousand media items
user name
2007-02-23 00:44:41
On Feb 22, 2007, at 17:09, John Durkin wrote:

> Would the easiest way to do this be to write a script
to actually
> check out each media file, drop output channel A, add
OC B, and then
> republish?  (rather than try to run queries to do this
directly in the
> DB)?

Yes, or use bric_soap to do it, although if you don't need
to update  
the file, it'd be pretty wasteful of bandwidth and file
copying. So  
yeah, a script is probably best. Here's one I wrote that
changes all  
"foo" stories to the XHTML and email output
channels:

#!/usr/local/bin/perl -w

use strict;
use lib '/usr/local/bricolage/lib';
use aliased 'Bric::Biz::Asset::Business::Story';
use aliased 'Bric::Biz::OutputChannel';

my $xhtml_oc = OutputChannel->lookup({ id => 1057 });
my $email_oc = OutputChannel->lookup({ id => 1044 });

for my $story (Story->list({ element_key_name => 'foo'
})) {
     # Update the output channels.
     my ocs = $story->get_output_channels;
     $story->add_output_channels($xhtml_oc);
     $story->set_primary_oc_id($xhtml_oc->get_id);
     $story->del_output_channels(ocs);
     $story->add_output_channels($email_oc);
     $story->save;
     print $story->get_primary_uri, $/;
}

HTH,

David

Re: changing output channel on several thousand media items
user name
2007-02-23 12:53:50
thanks very much, david!

On 2/22/07, David E. Wheeler <davidkineticode.com> wrote:
> On Feb 22, 2007, at 17:09, John Durkin wrote:
>
> > Would the easiest way to do this be to write a
script to actually
> > check out each media file, drop output channel A,
add OC B, and then
> > republish?  (rather than try to run queries to do
this directly in the
> > DB)?
>
> Yes, or use bric_soap to do it, although if you don't
need to update
> the file, it'd be pretty wasteful of bandwidth and file
copying. So
> yeah, a script is probably best. Here's one I wrote
that changes all
> "foo" stories to the XHTML and email output
channels:
>
> #!/usr/local/bin/perl -w
>
> use strict;
> use lib '/usr/local/bricolage/lib';
> use aliased 'Bric::Biz::Asset::Business::Story';
> use aliased 'Bric::Biz::OutputChannel';
>
> my $xhtml_oc = OutputChannel->lookup({ id => 1057
});
> my $email_oc = OutputChannel->lookup({ id => 1044
});
>
> for my $story (Story->list({ element_key_name =>
'foo' })) {
>      # Update the output channels.
>      my ocs = $story->get_output_channels;
>      $story->add_output_channels($xhtml_oc);
>     
$story->set_primary_oc_id($xhtml_oc->get_id);
>      $story->del_output_channels(ocs);
>      $story->add_output_channels($email_oc);
>      $story->save;
>      print $story->get_primary_uri, $/;
> }
>
> HTH,
>
> David
>

Re: changing output channel on several thousand media items
user name
2007-02-23 13:46:12
one follow up question... I'm doing this to Media items so I
modified
your script for my purposes, but I get an error that I'm
confused
by...  are these output channel functions not available for
Media?

Here's the error I get:

Can't locate object method "add_output_channels"
via package
"Bric::Biz::Asset::Business::Media::Image" at
./test_ocswitch.pl line
17.

Here's the slightly modified script:

#!/usr/bin/perl -w

use strict;
use lib '/usr/local/bricolage/lib';
use aliased 'Bric::Biz::Asset::Business::Media';
use aliased 'Bric::Biz::OutputChannel';

my $media_oc = OutputChannel->lookup({ id => 1038 });
my $html_oc = OutputChannel->lookup({ id => 1 });

my ekns = qw(lland lport mland mport photograph sland
sport square
thumb xlland xlport xsland);

for my $ekn (ekns) {
        print("working on $eknn");
        for my $media (Media->list({ element_key_name
=> "$ekn" })) {
        # Update the output channels.
            $media->add_output_channels($media_oc);
            $media->set_primary_oc_id(1038);
            $media->del_output_channels($html_oc);
            $media->save;
            print $media->get_primary_uri, $/;

        }

}

On 2/23/07, John Durkin <john.durkingmail.com> wrote:
> thanks very much, david!
>
> On 2/22/07, David E. Wheeler <davidkineticode.com> wrote:
> > On Feb 22, 2007, at 17:09, John Durkin wrote:
> >
> > > Would the easiest way to do this be to write
a script to actually
> > > check out each media file, drop output
channel A, add OC B, and then
> > > republish?  (rather than try to run queries
to do this directly in the
> > > DB)?
> >
> > Yes, or use bric_soap to do it, although if you
don't need to update
> > the file, it'd be pretty wasteful of bandwidth and
file copying. So
> > yeah, a script is probably best. Here's one I
wrote that changes all
> > "foo" stories to the XHTML and email
output channels:
> >
> > #!/usr/local/bin/perl -w
> >
> > use strict;
> > use lib '/usr/local/bricolage/lib';
> > use aliased 'Bric::Biz::Asset::Business::Story';
> > use aliased 'Bric::Biz::OutputChannel';
> >
> > my $xhtml_oc = OutputChannel->lookup({ id =>
1057 });
> > my $email_oc = OutputChannel->lookup({ id =>
1044 });
> >
> > for my $story (Story->list({ element_key_name
=> 'foo' })) {
> >      # Update the output channels.
> >      my ocs = $story->get_output_channels;
> >      $story->add_output_channels($xhtml_oc);
> >     
$story->set_primary_oc_id($xhtml_oc->get_id);
> >      $story->del_output_channels(ocs);
> >      $story->add_output_channels($email_oc);
> >      $story->save;
> >      print $story->get_primary_uri, $/;
> > }
> >
> > HTH,
> >
> > David
> >
>

Re: changing output channel on several thousand media items
user name
2007-02-23 14:25:26
On Fri, 23 Feb 2007, John Durkin wrote:
> one follow up question... I'm doing this to Media items
so I modified
> your script for my purposes, but I get an error that
I'm confused
> by...  are these output channel functions not available
for Media?
>
> Here's the error I get:
>
> Can't locate object method
"add_output_channels" via package
> "Bric::Biz::Asset::Business::Media::Image" at
./test_ocswitch.pl line
> 17.

I think you'll have to add a
use Bric::Biz::Asset::Business::Media::Image;

> Here's the slightly modified script:
>
> #!/usr/bin/perl -w
>
> use strict;
> use lib '/usr/local/bricolage/lib';
> use aliased 'Bric::Biz::Asset::Business::Media';
> use aliased 'Bric::Biz::OutputChannel';
>
> my $media_oc = OutputChannel->lookup({ id => 1038
});
> my $html_oc = OutputChannel->lookup({ id => 1
});
>
> my ekns = qw(lland lport mland mport photograph sland
sport square
> thumb xlland xlport xsland);
>
> for my $ekn (ekns) {
>       print("working on $eknn");
>       for my $media (Media->list({ element_key_name
=> "$ekn" })) {
>       # Update the output channels.
>           $media->add_output_channels($media_oc);

[snip]

Re: changing output channel on several thousand media items
user name
2007-02-23 14:32:43
Ok the other error was happening when I was trying to delete
the oc
when it doesn't exist anymore (running into already changed
images) -

so thanks again, I've got it working 

JD

On 2/23/07, John Durkin <john.durkingmail.com> wrote:
> Thanks Scott, that worked!  Generated a new error tho
after apparently
> successfully switching some of the images...:
>
>
> Unable to execute SQL statement: DBD::Pg::st execute
failed: ERROR:
> duplicate key violates unique constraint
"pk_media_output_channel"
>  [for Statement "
>                 INSERT INTO media__output_channel
>                             (media_instance__id,
output_channel__id)
>                 VALUES (?, ?)
>             " with ParamValues: 1='19361',
2='1038'] at
> /usr/local/bricolage/lib/Bric/Util/DBI.pm line 1083.
>
>
> On 2/23/07, Scott Lanning <lanningswho.int> wrote:
> > On Fri, 23 Feb 2007, John Durkin wrote:
> > > one follow up question... I'm doing this to
Media items so I modified
> > > your script for my purposes, but I get an
error that I'm confused
> > > by...  are these output channel functions not
available for Media?
> > >
> > > Here's the error I get:
> > >
> > > Can't locate object method
"add_output_channels" via package
> > >
"Bric::Biz::Asset::Business::Media::Image" at
./test_ocswitch.pl line
> > > 17.
> >
> > I think you'll have to add a
> > use Bric::Biz::Asset::Business::Media::Image;
> >
> > > Here's the slightly modified script:
> > >
> > > #!/usr/bin/perl -w
> > >
> > > use strict;
> > > use lib '/usr/local/bricolage/lib';
> > > use aliased
'Bric::Biz::Asset::Business::Media';
> > > use aliased 'Bric::Biz::OutputChannel';
> > >
> > > my $media_oc = OutputChannel->lookup({ id
=> 1038 });
> > > my $html_oc = OutputChannel->lookup({ id
=> 1 });
> > >
> > > my ekns = qw(lland lport mland mport
photograph sland sport square
> > > thumb xlland xlport xsland);
> > >
> > > for my $ekn (ekns) {
> > >       print("working on $eknn");
> > >       for my $media (Media->list({
element_key_name => "$ekn" })) {
> > >       # Update the output channels.
> > >          
$media->add_output_channels($media_oc);
> >
> > [snip]
> >
>

[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )