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

Mailing List Archive: Bricolage: users

Date Field Autoupdate

 

 

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


smith_t at denison

Jul 18, 2008, 6:17 AM

Post #1 of 8 (256 views)
Permalink
Date Field Autoupdate

Hey All,

I am in the process of trying to run a script that turns text input
fields into the date field with Year, Month, Day only. I can
correctly pull the data and reformat it from the text input fields
without problems so far. I have it in an array. How do I go about
programatically adding the new date field to each story that I want to
and then setting it with the right date. I've taken a look at the API
and can't seem to understand. I think the fact that it is a date
input adds a degree of complication. Any help would be appreciated!

-Trevor


smith_t at denison

Jul 18, 2008, 10:45 AM

Post #2 of 8 (247 views)
Permalink
Re: Date Field Autoupdate [In reply to]

Okay, so I am successfully now updating the fields with my script
using this code:

my $article_date =
Bric::Biz::ElementType::Parts::FieldType->lookup({ id => 1934 });
$story = $story->add_field($article_date, 'YYYY-MM-DD hh:mm:ss');

Where 1934 is the ID of the element that I want to add and where the
time is an actual value. Now I am running into the problem that it
will not let me delete my old elements, this is the code that I am
trying to use:

foreach $element ($story->get_elements){
if($element->has_name('date')){
$element->do_delete;
$element->save;
}
}

But it keeps returning this error:
Can't locate object method "do_delete" via package
"Bric::Biz::Element::Field"

Any help would be greatly appreciated.

-Trevor

ps - I hope someday I'll know enough to help people on this list
instead of constantly asking questions :)

On Fri, Jul 18, 2008 at 9:17 AM, Trevor Smith <smith_t[at]denison.edu> wrote:
> Hey All,
>
> I am in the process of trying to run a script that turns text input
> fields into the date field with Year, Month, Day only. I can
> correctly pull the data and reformat it from the text input fields
> without problems so far. I have it in an array. How do I go about
> programatically adding the new date field to each story that I want to
> and then setting it with the right date. I've taken a look at the API
> and can't seem to understand. I think the fact that it is a date
> input adds a degree of complication. Any help would be appreciated!
>
> -Trevor
>


greg at node79

Jul 18, 2008, 11:10 AM

Post #3 of 8 (246 views)
Permalink
Re: Date Field Autoupdate [In reply to]

On 18-Jul-08, at 1:45 PM, Trevor Smith wrote:

> Now I am running into the problem that it
> will not let me delete my old elements, this is the code that I am
> trying to use:
>
> foreach $element ($story->get_elements){
> if($element->has_name('date')){
> $element->do_delete;
> $element->save;
> }
> }


Have a look at the API docs for Bric::Biz::Element::Container-
>delete_elements(). I think the element has to be deleted via its
container, not from the element itself (i.e. tell the container to
delete an element inside rather than tell the element to delete itself).

The code that handles this when you delete elements in the UI is in
Bric/App/Callback/ContainerProf.pm. I usually find it helpful to "see
how the UI does it" and then copy/modify to suit.

-Greg


smith_t at denison

Jul 18, 2008, 11:27 AM

Post #4 of 8 (243 views)
Permalink
Re: Date Field Autoupdate [In reply to]

I'm now trying to delete things as you mentioned by category using this code:

my $cat = $story->get_primary_category->get_id;
my @stories = Bric::Biz::Asset::Business::Story->list({ site_id
=> $story->get_site_id, category_id => $cat, active => 1, unexpired =>
1, publish_status => 1, element_key_name => 'news_release' });
foreach my $story (@stories){
$story->delete_elements({ id => 1354 });
}

But I am still getting this error:

Can't locate object method "do_delete" via package
"Bric::Biz::Element::Field"

Thanks,
Trevor


smith_t at denison

Jul 18, 2008, 11:37 AM

Post #5 of 8 (248 views)
Permalink
Re: Date Field Autoupdate [In reply to]

Okay so this is really weird but I just commented this line out of my code:
$story->delete_elements({ id => 1354 });

And I am still getting the error:
Can't locate object method "do_delete" via package
"Bric::Biz::Element::Field"

I did a search on the string 'do_delete' and nothing showed up in my
code. I've attached my whole code just in case you think you can
help. Thanks.

-Trevor

On Fri, Jul 18, 2008 at 2:27 PM, Trevor Smith <smith_t[at]denison.edu> wrote:
> I'm now trying to delete things as you mentioned by category using this code:
>
> my $cat = $story->get_primary_category->get_id;
> my @stories = Bric::Biz::Asset::Business::Story->list({ site_id
> => $story->get_site_id, category_id => $cat, active => 1, unexpired =>
> 1, publish_status => 1, element_key_name => 'news_release' });
> foreach my $story (@stories){
> $story->delete_elements({ id => 1354 });
> }
>
> But I am still getting this error:
>
> Can't locate object method "do_delete" via package
> "Bric::Biz::Element::Field"
>
> Thanks,
> Trevor
>
Attachments: news_archive.txt (2.14 KB)


smith_t at denison

Jul 18, 2008, 12:17 PM

Post #6 of 8 (245 views)
Permalink
Re: Date Field Autoupdate [In reply to]

Okay, so apparently that last error was caused by a weird Bricolage
caching error of some sort, but now my template code is again actually
being the one called for preview. And with this method:
> $story->delete_elements({ id => 1354 });
I am still getting this error:
> Can't locate object method "do_delete" via package "Bric::Biz::Element::Field"
Help anyone?

T


david at kineticode

Jul 18, 2008, 1:30 PM

Post #7 of 8 (244 views)
Permalink
Re: Date Field Autoupdate [In reply to]

On Jul 18, 2008, at 11:27, Trevor Smith wrote:

> I'm now trying to delete things as you mentioned by category using
> this code:
>
> my $cat = $story->get_primary_category->get_id;
> my @stories = Bric::Biz::Asset::Business::Story->list({ site_id
> => $story->get_site_id, category_id => $cat, active => 1, unexpired =>
> 1, publish_status => 1, element_key_name => 'news_release' });
> foreach my $story (@stories){
> $story->delete_elements({ id => 1354 });
> }
>
> But I am still getting this error:
>
> Can't locate object method "do_delete" via package
> "Bric::Biz::Element::Field"

I've no idea what's happening there, but if what you want is to delete
the "mumble" fields associated with the top-level element of those
stories, you'd have to do this:

foreach my $story (@stories) {
my $elem = $story->get_element;
if (my @fields = $elem->get_fields('mumble')) {
$elem->delete_elements(\@fields);
$elem->save;
}
}

Note how I'm finding the fields to delete using key name rather than
an ID.

HTH,

David


smith_t at denison

Jul 19, 2008, 6:42 AM

Post #8 of 8 (237 views)
Permalink
Re: Date Field Autoupdate [In reply to]

Worked great, thanks for the help.

T

On Fri, Jul 18, 2008 at 4:30 PM, David E. Wheeler <david[at]kineticode.com> wrote:
> On Jul 18, 2008, at 11:27, Trevor Smith wrote:
>
>> I'm now trying to delete things as you mentioned by category using this
>> code:
>>
>> my $cat = $story->get_primary_category->get_id;
>> my @stories = Bric::Biz::Asset::Business::Story->list({ site_id
>> => $story->get_site_id, category_id => $cat, active => 1, unexpired =>
>> 1, publish_status => 1, element_key_name => 'news_release' });
>> foreach my $story (@stories){
>> $story->delete_elements({ id => 1354 });
>> }
>>
>> But I am still getting this error:
>>
>> Can't locate object method "do_delete" via package
>> "Bric::Biz::Element::Field"
>
> I've no idea what's happening there, but if what you want is to delete the
> "mumble" fields associated with the top-level element of those stories,
> you'd have to do this:
>
> foreach my $story (@stories) {
> my $elem = $story->get_element;
> if (my @fields = $elem->get_fields('mumble')) {
> $elem->delete_elements(\@fields);
> $elem->save;
> }
> }
>
> Note how I'm finding the fields to delete using key name rather than an ID.
>
> HTH,
>
> David
>

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


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.