Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Using Bric::Biz::Asset::Business::Story->new

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


tom.ash at newint

May 6, 2011, 9:44 AM

Post #1 of 9 (1393 views)
Permalink
Using Bric::Biz::Asset::Business::Story->new

Hello,

I am trying to make our /story.mc template create and publish a separate new story in certain cases. To do this I've tried including the following code:

my $new_bio_story = Bric::Biz::Asset::Business::Story->new({
element_type => 'global_contributor', # This is the name of one of our story types
source__id => $story->get_source__id,
site_id => $story->get_site_id,
user__id => Bric::App::Session::get_user_id(),
title => $contrib_name,
});

However I get the following error:

Can't locate object method "get_id" via package "global_contributor" (perhaps you forgot to load "global_contributor"?) at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2449, <GEN491> line 619.

Any help much appreciated,

Tom
(Relative Bricolage newbie)


paulo at digitalcraftsmen

May 6, 2011, 9:51 AM

Post #2 of 9 (1333 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Hi Tom,

The element_type has to be an element type object rather than the name
of the element_type, your best bet is to find the element type id number
of the global contributor story type and use that as

element_type_id => '1024' # or whatever

regards,

Paul


On 06/05/2011 17:44, Tom Ash wrote:
> Hello,
>
> I am trying to make our /story.mc template create and publish a separate new story in certain cases. To do this I've tried including the following code:
>
> my $new_bio_story = Bric::Biz::Asset::Business::Story->new({
> element_type => 'global_contributor', # This is the name of one of our story types
> source__id => $story->get_source__id,
> site_id => $story->get_site_id,
> user__id => Bric::App::Session::get_user_id(),
> title => $contrib_name,
> });
>
> However I get the following error:
>
> Can't locate object method "get_id" via package "global_contributor" (perhaps you forgot to load "global_contributor"?) at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2449,<GEN491> line 619.
>
> Any help much appreciated,
>
> Tom
> (Relative Bricolage newbie)


bret at pectopah

May 6, 2011, 10:08 AM

Post #3 of 9 (1334 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Hi Tom,

Another option is to instantiate the element type object based on the
key name:

element_type => Bric::Biz::ElementType->lookup({key_name =>
'global_contributor'}),


Hope this helps,

Bret



On Fri, 2011-05-06 at 17:51 +0100, Paul Orrock wrote:
> Hi Tom,
>
> The element_type has to be an element type object rather than the name
> of the element_type, your best bet is to find the element type id number
> of the global contributor story type and use that as
>
> element_type_id => '1024' # or whatever
>
> regards,
>
> Paul
>
>
> On 06/05/2011 17:44, Tom Ash wrote:
> > Hello,
> >
> > I am trying to make our /story.mc template create and publish a separate new story in certain cases. To do this I've tried including the following code:
> >
> > my $new_bio_story = Bric::Biz::Asset::Business::Story->new({
> > element_type => 'global_contributor', # This is the name of one of our story types
> > source__id => $story->get_source__id,
> > site_id => $story->get_site_id,
> > user__id => Bric::App::Session::get_user_id(),
> > title => $contrib_name,
> > });
> >
> > However I get the following error:
> >
> > Can't locate object method "get_id" via package "global_contributor" (perhaps you forgot to load "global_contributor"?) at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2449,<GEN491> line 619.
> >
> > Any help much appreciated,
> >
> > Tom
> > (Relative Bricolage newbie)
>

--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret [at] pectopah
www.pectopah.com


tom.ash at newint

May 13, 2011, 4:32 AM

Post #4 of 9 (1297 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Thanks for the helpful replies. How do I set the new story's primary category? In http://bricolagecms.org/docs/current/api/Bric/Biz/Asset/Business/Story.html I see to following function mentioned:

$story = $story->set_primary_category($cat_id || $cat)
Defines a category as being the the primary one for this story. If a category is already marked as being primary, this will disassociate it.

And later on:
$ba = $ba->add_categories(@categories)
This will take a list category objects or Is and will associate them with the story.

However, I find the latter description confusing. What argument should I pass to $new_bio_story->add_categories() to associate a category called '/contributors' with ID 1662? The number doesn't work.

For reference, here is my existing code - it'd be great to know what to slot in (or if I'm doing anything wrong).

my $new_bio_story = Bric::Biz::Asset::Business::Story->new({
element_type_id => '1124',
source__id => $story->get_source__id,
site_id => $story->get_site_id,
user__id => Bric::App::Session::get_user_id(),
title => $contrib_name,
slug => $contrib_slug,

});
# $new_bio_story->add_categories(1662); #doesn't work
$new_bio_story->set_primary_category(1662);
print $burner->blaze_another($new_bio_story);

Many thanks,
Tom


On 6 May 2011, at 18:08, Bret Dawson wrote:

> Hi Tom,
>
> Another option is to instantiate the element type object based on the
> key name:
>
> element_type => Bric::Biz::ElementType->lookup({key_name =>
> 'global_contributor'}),
>
>
> Hope this helps,
>
> Bret
>
>
>
> On Fri, 2011-05-06 at 17:51 +0100, Paul Orrock wrote:
>> Hi Tom,
>>
>> The element_type has to be an element type object rather than the name
>> of the element_type, your best bet is to find the element type id number
>> of the global contributor story type and use that as
>>
>> element_type_id => '1024' # or whatever
>>
>> regards,
>>
>> Paul
>>
>>
>> On 06/05/2011 17:44, Tom Ash wrote:
>>> Hello,
>>>
>>> I am trying to make our /story.mc template create and publish a separate new story in certain cases. To do this I've tried including the following code:
>>>
>>> my $new_bio_story = Bric::Biz::Asset::Business::Story->new({
>>> element_type => 'global_contributor', # This is the name of one of our story types
>>> source__id => $story->get_source__id,
>>> site_id => $story->get_site_id,
>>> user__id => Bric::App::Session::get_user_id(),
>>> title => $contrib_name,
>>> });
>>>
>>> However I get the following error:
>>>
>>> Can't locate object method "get_id" via package "global_contributor" (perhaps you forgot to load "global_contributor"?) at /home/newint/bricolage2/lib/Bric/Biz/Asset/Business.pm line 2449,<GEN491> line 619.
>>>
>>> Any help much appreciated,
>>>
>>> Tom
>>> (Relative Bricolage newbie)
>>
>
> --
> Bret Dawson
> Producer
> Pectopah Productions Inc.
> (416) 895-7635
> bret [at] pectopah
> www.pectopah.com
>


greg at node79

May 13, 2011, 5:34 AM

Post #5 of 9 (1297 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Hi Tom,

> However, I find the latter description confusing. What argument should I pass to $new_bio_story->add_categories() to associate a category called '/contributors' with ID 1662? The number doesn't work.

set_primary_category() works just as you said. The add_categories() method takes an array reference, so you would call it like this to add categories:

my @categories_to_add = (1031, 1033, 1034);
$new_story->add_categories(\@categories_to_add);

a little more concise with anonymous array references:

$new_story->add_categories([1024]);
$new_story->add_categories([1024, 1030, 1045]);

HTH,
--Greg


===
Greg Heo
416.826.7630
http://node79.com


tom.ash at newint

May 13, 2011, 7:09 AM

Post #6 of 9 (1298 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Thanks a lot Greg, that worked. However, I get the error below (under '**Blaze Error**' on previewing the story, which the stack trace reveals to be due to this line in the code I posted in the last message:

print $burner->blaze_another($new_bio_story);

If I change the method in this line to publish_another and try publishing a story which uses this template, I get the error under **Publish error** below, which mentions that the new story I'm creating in the case of this story is "checked out" - despite it being a new story, and not showing up in 'Find stories' within Bricolage's interface.

Any help on this - hopefully! - final problem much appreciated,
Tom

-----
**Blaze Error**

An error occurred while processing your request:

Unable to execute SQL statement

DBD::Pg::st execute failed: ERROR: invalid input syntax for integer: ""
[for Statement "
INSERT INTO story__resource (resource__id, story__id)
VALUES (?, ?)
" with ParamValues: 2='', 1='444735'] at /home/newint/bricolage2/lib/Bric/Util/DBI.pm line 1138, <GEN889> line 1298.

Stack:
[/home/newint/bricolage2/lib/Bric/Util/DBI.pm:1138]
[/home/newint/bricolage2/lib/Bric/Dist/Resource.pm:2270]
[/home/newint/bricolage2/lib/Bric/Dist/Resource.pm:1688]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:2144]
[/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm:591]
[/home/newint/bricolage2/lib/Bric/Util/Burner/Mason.pm:290]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:1585]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:1022]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:1137]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:1171]
[/home/newint/bricolage2/lib/Bric/Util/Burner.pm:1207]
[/home/newint/bricolage2/data/burn/sandbox/user_2298/oc_1/story.mc:368]
<snip>


---

**Publish error**:

An error occurred while processing your request:

Cannot publish story "/contributors/skye_hohmann/" because it is checked out. Your best bet is to pass `published_version => 1` when looking up documents to pass to burn_another()

(/contributors/skye_hohmann/ being the URI of the new story I'm creating in this case)


On 13 May 2011, at 13:34, Greg Heo wrote:

> Hi Tom,
>
>> However, I find the latter description confusing. What argument should I pass to $new_bio_story->add_categories() to associate a category called '/contributors' with ID 1662? The number doesn't work.
>
> set_primary_category() works just as you said. The add_categories() method takes an array reference, so you would call it like this to add categories:
>
> my @categories_to_add = (1031, 1033, 1034);
> $new_story->add_categories(\@categories_to_add);
>
> a little more concise with anonymous array references:
>
> $new_story->add_categories([1024]);
> $new_story->add_categories([1024, 1030, 1045]);
>
> HTH,
> --Greg
>
>
> ===
> Greg Heo
> 416.826.7630
> http://node79.com
>


greg at node79

May 13, 2011, 8:03 AM

Post #7 of 9 (1298 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

On 2011-05-13, at 10:09 AM, Tom Ash wrote:

> If I change the method in this line to publish_another and try publishing a story which uses this template, I get the error under **Publish error** below, which mentions that the new story I'm creating in the case of this story is "checked out" - despite it being a new story, and not showing up in 'Find stories' within Bricolage's interface.

Technically, the story is checked out to you (or whoever is running the template) since you just created it with Story->new(). Once the new story is ready, it has to be checked in and saved before the publish.

Here's some good sample code to look at from the set of examples templates:
https://github.com/bricoleurs/templates/blob/master/publish_daily_archive.mc


===
Greg Heo
416.826.7630
http://node79.com


tom.ash at newint

May 18, 2011, 8:43 AM

Post #8 of 9 (1278 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Thank you Greg. One final question - how do I associate a contributor with this new story? I can't find the answer in the API documentation.

Tom

On 13 May 2011, at 16:03, Greg Heo wrote:

> On 2011-05-13, at 10:09 AM, Tom Ash wrote:
>
>> If I change the method in this line to publish_another and try publishing a story which uses this template, I get the error under **Publish error** below, which mentions that the new story I'm creating in the case of this story is "checked out" - despite it being a new story, and not showing up in 'Find stories' within Bricolage's interface.
>
> Technically, the story is checked out to you (or whoever is running the template) since you just created it with Story->new(). Once the new story is ready, it has to be checked in and saved before the publish.
>
> Here's some good sample code to look at from the set of examples templates:
> https://github.com/bricoleurs/templates/blob/master/publish_daily_archive.mc
>
>
> ===
> Greg Heo
> 416.826.7630
> http://node79.com
>


bret at pectopah

May 18, 2011, 8:57 AM

Post #9 of 9 (1275 views)
Permalink
Re: Using Bric::Biz::Asset::Business::Story->new [In reply to]

Hi Tom,

You can just call $story->add_contributor(), passing it either a
contributor object or a contributor ID. The $story object inherits the
method from Bric::Biz::Asset::Business.

More details are here in these pieces of the documentation:

Bric::Biz::Asset::Business
Bric::Util::Grp::Parts::Member::Contrib
Bric::Util::Grp::Person


Hope this helps,

Bret


On Wed, 2011-05-18 at 16:43 +0100, Tom Ash wrote:
> Thank you Greg. One final question - how do I associate a contributor with this new story? I can't find the answer in the API documentation.
>
> Tom
>
> On 13 May 2011, at 16:03, Greg Heo wrote:
>
> > On 2011-05-13, at 10:09 AM, Tom Ash wrote:
> >
> >> If I change the method in this line to publish_another and try publishing a story which uses this template, I get the error under **Publish error** below, which mentions that the new story I'm creating in the case of this story is "checked out" - despite it being a new story, and not showing up in 'Find stories' within Bricolage's interface.
> >
> > Technically, the story is checked out to you (or whoever is running the template) since you just created it with Story->new(). Once the new story is ready, it has to be checked in and saved before the publish.
> >
> > Here's some good sample code to look at from the set of examples templates:
> > https://github.com/bricoleurs/templates/blob/master/publish_daily_archive.mc
> >
> >
> > ===
> > Greg Heo
> > 416.826.7630
> > http://node79.com
> >
>
>

--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret [at] pectopah
www.pectopah.com

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.