Skip to content

Commit

Permalink
Simplifying my last edit to MT::Entry::set_defaults and also using $e…
Browse files Browse the repository at this point in the history
…ntry->blog instead of loading it from the blog_id because the former caches the result.

Signed-off-by: Open Melody Software Group <admin@openmelody.org>
  • Loading branch information
jayallen authored and Open Melody Software Group committed Jul 26, 2009
1 parent 9673460 commit e98f0c8
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/MT/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -671,20 +671,17 @@ sub sync_assets {

# See http://bugs.movabletype.org/?82628
sub set_defaults {
my $e = shift or return;

my $app = MT->instance or return;

# Entry blog takes precedence, $app->blog fallback
my $blog = $app->model('blog')->load($e->blog_id) if $e->blog_id;
$blog ||= $app->blog if $app and $app->can('blog');

# API usage will almost always set the entry author directly so if
# it's not set, then it most likely means that the interaction is
# via the browser and the $app->user is the most likely author.
my $user = $e->author ? $e->author
: ($app and $app->can('user')) ? $app->user
: undef;
my $e = shift or return;
my $app = MT->instance;
my $blog = $e->blog;
my $user = $e->author;

# If we have an $app fill in missing values from it if possible.
# $app can be a non-MT::App object so we have to check for methods
if ( $app ) {
$blog ||= $app->blog if $app->can('blog');
$user ||= $app->user if $app->can('user');
}

my (%entry_defaults, %user_defaults, %blog_defaults);

Expand Down

0 comments on commit e98f0c8

Please sign in to comment.