From 8d43951ebc583cf7c08db584d40b02988136ca48 Mon Sep 17 00:00:00 2001 From: Byrne Date: Fri, 5 Mar 2010 12:22:36 -0800 Subject: [PATCH] [#314] Converted MT::Entry to use new MT::Asset->association methods. Also converted a few calls to use the MT->model() method as opposed to the obsolete require and MT::Object->method syntax. --- lib/MT/Entry.pm | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/MT/Entry.pm b/lib/MT/Entry.pm index 173fdf886..a04e12dea 100644 --- a/lib/MT/Entry.pm +++ b/lib/MT/Entry.pm @@ -660,8 +660,7 @@ sub sync_assets { my $entry = shift; my $text = ($entry->text || '') . "\n" . ($entry->text_more || ''); - require MT::ObjectAsset; - my @assets = MT::ObjectAsset->load({ + my @assets = MT->model('objectasset')->load({ object_id => $entry->id, blog_id => $entry->blog_id, object_ds => $entry->datasource, @@ -678,20 +677,13 @@ sub sync_assets { } else { # is asset exists? my $asset = MT->model('asset')->load({ id => $id }) or next; - - my $map = new MT::ObjectAsset; - $map->blog_id($entry->blog_id); - $map->asset_id($id); - $map->object_ds($entry->datasource); - $map->object_id($entry->id); - $map->embedded(1); - $map->save; + $asset->associate( $entry, 1 ); $assets{$id} = 0; } } if (my @old_maps = grep { $assets{$_->asset_id} } @assets) { my @old_ids = map { $_->id } grep { $_->embedded } @old_maps; - MT::ObjectAsset->remove( { id => \@old_ids }) + MT->model('objectasset')->remove( { id => \@old_ids }) if @old_ids; } return 1; @@ -809,10 +801,7 @@ sub remove { my $entry = shift; if (ref $entry) { $entry->remove_children({ key => 'entry_id' }) or return; - - # Remove MT::ObjectAsset records - my $class = MT->model('objectasset'); - $class->remove({ object_id => $entry->id, object_ds => $entry->class_type }); + MT->model('asset')->clear_associations( $entry ); } $entry->SUPER::remove(@_);