| | 351 | } |
| | 352 | |
| | 353 | sub remove_fileinfo { |
| | 354 | my $mt = shift; |
| | 355 | my %param = @_; |
| | 356 | my $at = $param{ArchiveType} |
| | 357 | or return $mt->error( |
| | 358 | MT->translate( "Parameter '[_1]' is required", 'ArchiveType' ) ); |
| | 359 | my $blog_id = $param{Blog} |
| | 360 | or return $mt->error( |
| | 361 | MT->translate( "Parameter '[_1]' is required", 'Blog' ) ); |
| | 362 | my $entry_id = $param{Entry}, my $author_id = $param{Author}; |
| | 363 | my $start = $param{StartDate}; |
| | 364 | my $cat_id = $param{Category}; |
| | 365 | |
| | 366 | require MT::FileInfo; |
| | 367 | my @finfo = MT::FileInfo->load( |
| | 368 | { |
| | 369 | archive_type => $at, |
| | 370 | blog_id => $blog_id, |
| | 371 | ( $entry_id ? ( entry_id => $entry_id ) : () ), |
| | 372 | ( $cat_id ? ( category_id => $cat_id ) : () ), |
| | 373 | ( $start ? ( startdate => $start ) : () ), |
| | 374 | } |
| | 375 | ); |
| | 376 | |
| | 377 | for my $f (@finfo) { |
| | 378 | $f->remove; |
| | 379 | } |
| | 380 | 1; |
| | 381 | } |
| | 382 | |
| | 383 | # rebuild_deleted_entry |
| | 384 | # |
| | 385 | # $mt->rebuild_deleted_entry( |
| | 386 | # Entry => $entry | $entry_id, |
| | 387 | # Blog => [ $blog | $blog_id ], |
| | 388 | # ); |
| | 389 | sub rebuild_deleted_entry { |
| | 390 | my $mt = shift; |
| | 391 | my $app = MT->instance; |
| | 392 | my %param = @_; |
| | 393 | my $entry = $param{Entry} |
| | 394 | or return $mt->error( |
| | 395 | MT->translate( "Parameter '[_1]' is required", 'Entry' ) ); |
| | 396 | require MT::Entry; |
| | 397 | $entry = MT::Entry->load($entry) unless ref $entry; |
| | 398 | return unless $entry; |
| | 399 | |
| | 400 | my $blog; |
| | 401 | unless ( $blog = $param{Blog} ) { |
| | 402 | require MT::Blog; |
| | 403 | my $blog_id = $entry->blog_id; |
| | 404 | $blog = MT::Blog->load($blog_id) |
| | 405 | or return $mt->error( |
| | 406 | MT->translate( |
| | 407 | "Load of blog '[_1]' failed: [_2]", $blog_id, |
| | 408 | MT::Blog->errstr |
| | 409 | ) |
| | 410 | ); |
| | 411 | } |
| | 412 | |
| | 413 | my %rebuild_recip; |
| | 414 | my $at = $blog->archive_type; |
| | 415 | my @at; |
| | 416 | if ( $at && $at ne 'None' ) { |
| | 417 | my @at_orig = split( /,/, $at ); |
| | 418 | @at = grep { $_ ne 'Individual' && $_ ne 'Page' } @at_orig; |
| | 419 | } |
| | 420 | |
| | 421 | # Remove Individual archive file. |
| | 422 | if ( $app->config('DeleteFilesAtRebuild') ) { |
| | 423 | $mt->remove_entry_archive_file( Entry => $entry, ); |
| | 424 | } |
| | 425 | |
| | 426 | # Remove Individual fileinfo records. |
| | 427 | $mt->remove_fileinfo( |
| | 428 | ArchiveType => 'Individual', |
| | 429 | Blog => $blog->id, |
| | 430 | Entry => $entry->id |
| | 431 | ); |
| | 432 | |
| | 433 | require MT::Util; |
| | 434 | for my $at (@at) { |
| | 435 | my $archiver = $mt->archiver($at); |
| | 436 | next unless $archiver; |
| | 437 | |
| | 438 | my ( $start, $end ) = $archiver->date_range( $entry->authored_on ) |
| | 439 | if $archiver->date_based() && $archiver->can('date_range'); |
| | 440 | |
| | 441 | # Remove archive file if archive file has not entries. |
| | 442 | if ( $archiver->category_based() ) { |
| | 443 | my $categories = $entry->categories(); |
| | 444 | for my $cat (@$categories) { |
| | 445 | if ( |
| | 446 | ( $archiver->can('archive_entries_count') ) |
| | 447 | && ( |
| | 448 | $archiver->archive_entries_count( $blog, $at, $entry, |
| | 449 | $cat ) == 1 |
| | 450 | ) |
| | 451 | ) |
| | 452 | { |
| | 453 | $mt->remove_fileinfo( |
| | 454 | ArchiveType => $at, |
| | 455 | Blog => $blog->id, |
| | 456 | Category => $cat->id, |
| | 457 | ( |
| | 458 | $archiver->date_based() |
| | 459 | ? ( startdate => $start ) |
| | 460 | : () |
| | 461 | ), |
| | 462 | ); |
| | 463 | if ( $app->config('DeleteFilesAtRebuild') ) { |
| | 464 | $mt->remove_entry_archive_file( |
| | 465 | Entry => $entry, |
| | 466 | ArchiveType => $at, |
| | 467 | Category => $cat, |
| | 468 | ); |
| | 469 | } |
| | 470 | } |
| | 471 | else { |
| | 472 | if ( $app->config('RebuildAtDelete') ) { |
| | 473 | if ( $archiver->date_based() ) { |
| | 474 | $rebuild_recip{$at}{ $cat->id }{ $start . $end } |
| | 475 | {'Start'} = $start; |
| | 476 | $rebuild_recip{$at}{ $cat->id }{ $start . $end } |
| | 477 | {'End'} = $end; |
| | 478 | $rebuild_recip{$at}{ $cat->id }{ $start . $end } |
| | 479 | {'File'} = MT::Util::archive_file_for( |
| | 480 | $entry, $blog, $at, $cat, |
| | 481 | undef, undef, undef |
| | 482 | ); |
| | 483 | } |
| | 484 | else { |
| | 485 | $rebuild_recip{$at}{ $cat->id }{id} = $cat->id; |
| | 486 | $rebuild_recip{$at}{ $cat->id }{'File'} = |
| | 487 | MT::Util::archive_file_for( |
| | 488 | $entry, $blog, $at, $cat, |
| | 489 | undef, undef, undef |
| | 490 | ); |
| | 491 | } |
| | 492 | } |
| | 493 | } |
| | 494 | } |
| | 495 | } |
| | 496 | else { |
| | 497 | if ( ( $archiver->can('archive_entries_count') ) |
| | 498 | && ( $archiver->archive_entries_count( $blog, $at, $entry ) == |
| | 499 | 1 ) ) |
| | 500 | { |
| | 501 | |
| | 502 | # Remove archives fileinfo records. |
| | 503 | $mt->remove_fileinfo( |
| | 504 | ArchiveType => $at, |
| | 505 | Blog => $blog->id, |
| | 506 | ( |
| | 507 | $archiver->author_based() |
| | 508 | ? ( author_id => $entry->author->id ) |
| | 509 | : () |
| | 510 | ), |
| | 511 | ( $archiver->date_based() ? ( startdate => $start ) : () ), |
| | 512 | ); |
| | 513 | if ( $app->config('DeleteFilesAtRebuild') ) { |
| | 514 | $mt->remove_entry_archive_file( |
| | 515 | Entry => $entry, |
| | 516 | ArchiveType => $at |
| | 517 | ); |
| | 518 | } |
| | 519 | } |
| | 520 | else { |
| | 521 | if ( $app->config('RebuildAtDelete') ) { |
| | 522 | if ( $archiver->author_based() ) { |
| | 523 | if ( $archiver->date_based() ) { |
| | 524 | $rebuild_recip{$at}{ $entry->author->id } |
| | 525 | { $start . $end }{'Start'} = $start; |
| | 526 | $rebuild_recip{$at}{ $entry->author->id } |
| | 527 | { $start . $end }{'End'} = $end; |
| | 528 | $rebuild_recip{$at}{ $entry->author->id } |
| | 529 | { $start . $end }{'File'} = |
| | 530 | MT::Util::archive_file_for( $entry, $blog, $at, |
| | 531 | undef, undef, undef, $entry->author ); |
| | 532 | } |
| | 533 | else { |
| | 534 | $rebuild_recip{$at}{ $entry->author->id }{id} = |
| | 535 | $entry->author->id; |
| | 536 | $rebuild_recip{$at}{ $entry->author->id }{'File'} = |
| | 537 | MT::Util::archive_file_for( $entry, $blog, $at, |
| | 538 | undef, undef, undef, $entry->author ); |
| | 539 | } |
| | 540 | } |
| | 541 | elsif ( $archiver->date_based() ) { |
| | 542 | $rebuild_recip{$at}{ $start . $end }{'Start'} = $start; |
| | 543 | $rebuild_recip{$at}{ $start . $end }{'End'} = $end; |
| | 544 | $rebuild_recip{$at}{ $start . $end }{'File'} = |
| | 545 | MT::Util::archive_file_for( $entry, $blog, $at, undef, |
| | 546 | undef, undef, undef ); |
| | 547 | } |
| | 548 | if ( my $prev = $entry->previous(1) ) { |
| | 549 | $rebuild_recip{Individual}{ $prev->id }{id} = $prev->id; |
| | 550 | $rebuild_recip{Individual}{ $prev->id }{'File'} = |
| | 551 | MT::Util::archive_file_for( $prev, $blog, |
| | 552 | 'Individual', undef, undef, undef, undef ); |
| | 553 | } |
| | 554 | if ( my $next = $entry->next(1) ) { |
| | 555 | $rebuild_recip{Individual}{ $next->id }{id} = $next->id; |
| | 556 | $rebuild_recip{Individual}{ $next->id }{'File'} = |
| | 557 | MT::Util::archive_file_for( $next, $blog, |
| | 558 | 'Individual', undef, undef, undef, undef ); |
| | 559 | } |
| | 560 | } |
| | 561 | } |
| | 562 | } |
| | 563 | } |
| | 564 | |
| | 565 | return %rebuild_recip; |