Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created September 14, 2009 14:31
Show Gist options
  • Save sinkovsky/186681 to your computer and use it in GitHub Desktop.
Save sinkovsky/186681 to your computer and use it in GitHub Desktop.
if ( $params{categories} ) {
for my $category ( @{$params{categories}}) {
my $cat = MT::Category->load({label => $category,
blog_id => $entry_new->blog_id});
unless ($cat) {
print "Category $category not found. Creating...\n" if $self->{'verbose'};
$cat = MT::Category->new;
$cat->blog_id($entry_new->blog_id);
$cat->label($category);
$cat->save or die $cat->errstr;
}
my $placement = MT::Placement->new;
$placement->entry_id($entry_new->id );
$placement->blog_id($entry_new->blog_id );
$placement->category_id( $cat->id );
$placement->is_primary(0);
$placement->save or die $placement->errstr;
print "Placing entry under category $category\n" if $self->{'verbose'};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment