45
45
'authored_on' => 'datetime',
46
46
'week_number' => 'integer',
47
47
'template_id' => 'integer',
48
'comment_count' => 'integer',
49
'ping_count' => 'integer',
48
50
## Have to keep this around for use in mt-upgrade.cgi.
49
51
'category_id' => 'integer',
61
columns => [ 'blog_id', 'basename' ],
63
# Page listings are published in order by title
66
columns => [ 'blog_id', 'class', 'author_id', 'authored_on' ],
68
# For optimizing weekly archives, selected by blog, class,
71
columns => [ 'blog_id', 'class', 'status', 'week_number' ],
73
# For system-overview listings where we list all entries of
74
# a particular class by authored on date
76
columns => [ 'class', 'authored_on' ],
78
# For most blog-level listings, where we list all entries
79
# in a blog with a particular class by authored on date.
61
columns => ['blog_id', 'authored_on'],
81
columns => ['blog_id', 'class', 'authored_on'],
83
# For most publishing listings, where we list entries in a blog
84
# with a particular class, publish status (2) and authored on date
86
columns => ['blog_id', 'class', 'status', 'authored_on', 'id'],
90
columns => ['status', 'class', 'blog_id', 'id'],
64
97
child_of => 'MT::Blog',
65
98
child_classes => ['MT::Comment','MT::Placement','MT::Trackback','MT::FileInfo'],
311
MT::Comment->add_trigger( post_save => sub {
312
my($clone, $comment) = @_;
314
## Note: This flag is set in MT::Comment::visible().
315
if (my $delta = $comment->{__changed}{visibility}) {
316
my $memkey = MT::Entry->cache_key($comment->entry_id, 'commentcount');
317
my $cache = MT::Memcached->instance;
319
$cache->incr($memkey, $delta);
320
} elsif ($delta < 0) {
321
$cache->decr($memkey, abs $delta);
326
MT::Comment->add_trigger( post_remove => sub {
329
## If this comment was published, decrement the cached count of
330
## visible comments on the entry.
331
if ($comment->visible && !$comment->is_changed('visible')) {
332
my $memkey = MT::Entry->cache_key($comment->entry_id, 'commentcount');
333
MT::Memcached->instance->decr($memkey, 1);
339
$entry->cache_property('comment_count', sub {
340
my $cache = MT::Memcached->instance;
341
my $memkey = $entry->cache_key('commentcount');
342
if (defined( my $count = $cache->get($memkey) )) {
346
my $count = MT::Comment->count({
347
entry_id => $entry->id,
350
$cache->add($memkey, $count, 7 * 24 * 60 * 60); ## 1 week.
350
MT::Comment->add_trigger(
353
my $entry = MT::Entry->load( $comment->entry_id )
355
my $count = MT::Comment->count(
357
entry_id => $comment->entry_id,
361
$entry->comment_count($count);
366
MT::Comment->add_trigger(
369
my $entry = MT::Entry->load( $comment->entry_id )
371
if ( $comment->visible ) {
372
my $count = $entry->comment_count > 0 ? $entry->comment_count - 1 : 0;
373
$entry->comment_count($count);
357
380
my $entry = shift;
358
381
my ($terms, $args) = @_;
382
my $tb = $entry->trackback;
383
return undef unless $tb;
359
384
if ($terms || $args) {
361
$terms->{entry_id} = $entry->id;
386
$terms->{tb_id} = $tb->id;
362
387
return [ MT::TBPing->load( $terms, $args ) ];
364
389
$entry->cache_property('pings', sub {
365
[ MT::TBPing->load({ entry_id => $entry->id }) ];
390
[ MT::TBPing->load({ tb_id => $tb->id }) ];
370
MT::TBPing->add_trigger( post_save => sub {
371
my($clone, $ping) = @_;
373
## Note: This flag is set in MT::TBPing::visible().
374
if (my $delta = $ping->{__changed}{visibility}) {
375
my($class, $entry_id) = $ping->parent_id;
376
return unless $entry_id;
377
my $memkey = MT::Entry->cache_key($entry_id, 'pingcount');
378
my $cache = MT::Memcached->instance;
380
$cache->incr($memkey, $delta);
381
} elsif ($delta < 0) {
382
$cache->decr($memkey, abs $delta);
387
MT::TBPing->add_trigger( post_remove => sub {
390
## If this ping was published, decrement the cached count of
391
## visible pings on the entry.
392
if ($ping->visible && !$ping->is_changed('visible')) {
393
my($class, $entry_id) = $ping->parent_id;
394
return unless $entry_id;
395
my $memkey = MT::Entry->cache_key($entry_id, 'pingcount');
396
MT::Memcached->instance->decr($memkey, 1);
402
$entry->cache_property('ping_count', sub {
403
my $cache = MT::Memcached->instance;
404
my $memkey = 'entrypingcount-' . $entry->id;
405
if (defined( my $count = $cache->get($memkey) )) {
409
my $tb = $entry->trackback;
411
$tb ? MT::TBPing->count({ tb_id => $tb->id, visible => 1 }) : 0;
412
$cache->add($memkey, $count, 7 * 24 * 60 * 60); ## 1 week.
395
MT::TBPing->add_trigger(
398
require MT::Trackback;
399
if ( my $tb = MT::Trackback->load( $ping->tb_id ) ) {
400
if ( $tb->entry_id ) {
401
my $entry = MT::Entry->load( $tb->entry_id )
403
my $count = MT::TBPing->count(
409
$entry->ping_count($count);
416
MT::TBPing->add_trigger(
419
require MT::Trackback;
420
if ( my $tb = MT::Trackback->load( $ping->tb_id ) ) {
421
if ( $tb->entry_id && $ping->visible ) {
422
my $entry = MT::Entry->load( $tb->entry_id )
424
my $count = $entry->ping_count > 0 ? $entry->ping_count - 1 : 0;
425
$entry->ping_count($count);
418
432
sub archive_file {
419
433
my $entry = shift;
620
634
my @assets = MT::ObjectAsset->load({
621
635
object_id => $entry->id,
622
636
blog_id => $entry->blog_id,
623
object_ds => $entry->datasource
637
object_ds => $entry->datasource,
625
640
my %assets = map { $_->asset_id => $_->id } @assets;
626
641
while ($text =~ m!<form[^>]*?\smt:asset-id=["'](\d+)["'][^>]*?>(.+?)</form>!gis) {
628
643
my $innards = $2;
631
my $asset = MT->model('asset')->load({ id => $id }) or next;
633
645
# reference to an existing asset...
634
646
if (exists $assets{$id}) {
635
647
$assets{$id} = 0;
650
my $asset = MT->model('asset')->load({ id => $id }) or next;
637
652
my $map = new MT::ObjectAsset;
638
653
$map->blog_id($entry->blog_id);
639
654
$map->asset_id($id);
640
655
$map->object_ds($entry->datasource);
641
656
$map->object_id($entry->id);
643
659
$assets{$id} = 0;
646
662
if (my @old_maps = grep { $assets{$_->asset_id} } @assets) {
647
my @old_ids = map { $_->id } @old_maps;
648
MT::ObjectAsset->remove( { id => \@old_ids });
663
my @old_ids = map { $_->id } grep { $_->embedded } @old_maps;
664
MT::ObjectAsset->remove( { id => \@old_ids })