From 52a899ff40a86b7939192fd3d8f5aff7d93dae88 Mon Sep 17 00:00:00 2001 From: Taku Amano Date: Tue, 7 Jul 2009 18:23:09 +0900 Subject: [PATCH] Enhanced a Object's settings. --- config.yaml | 2 +- lib/Lovers/LoveLetter.pm | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 5e27a0e..8b8ffed 100644 --- a/config.yaml +++ b/config.yaml @@ -33,7 +33,7 @@ doc_link: http://mt-acme.sourceforge.jp/lovers/ l10n_class: Lovers::L10N # objects -schema_version: 5 +schema_version: 6 object_types: love_letter: Lovers::LoveLetter diff --git a/lib/Lovers/LoveLetter.pm b/lib/Lovers/LoveLetter.pm index c9f9899..ff63246 100644 --- a/lib/Lovers/LoveLetter.pm +++ b/lib/Lovers/LoveLetter.pm @@ -44,6 +44,7 @@ __PACKAGE__->install_properties({ indexes => { unique_letter => { columns => [ 'letter_identifier', 'entry_id', 'template_id' ], + unique => 1, } }, default => { @@ -51,6 +52,8 @@ __PACKAGE__->install_properties({ }, datasource => 'love_letter', primary_key => 'id', + + child_of => [ 'MT::Entry', 'MT::Template' ], }); sub mail_param { @@ -67,4 +70,57 @@ sub mail_param { $param; } +sub backup_terms_args { + my $class = shift; + my ($blog_ids) = @_; + + if (defined($blog_ids) && scalar(@$blog_ids)) { + my $entry_ids = [ map($_->id, MT::Entry->load( + { 'blog_id' => $blog_ids, }, + { + 'join' => Lovers::LoveLetter->join_on( + 'entry_id', undef, undef + ), + 'fetchonly' => ['id'], + } + )) ]; + my $template_ids = [ map($_->id, MT::Template->load( + { 'blog_id' => $blog_ids, }, + { + 'join' => Lovers::LoveLetter->join_on( + 'template_id', undef, undef + ), + 'fetchonly' => ['id'], + } + )) ]; + return { + terms => [ + [ + { 'entry_id' => @$entry_ids ? $entry_ids : 0 }, + '-and', + { 'template_id' => 0 }, + ], + '-or', + [ + { 'template_id' => @$template_ids ? $template_ids : 0 }, + '-and', + { 'entry_id' => 0 }, + ], + ], + args => undef + }; + } + else { + return { terms => undef, args => undef }; + } +} + +sub parents { + my $obj = shift; + { + entry_id => MT->model('entry'), + template_id => MT->model('template'), + }; +} + 1; -- 2.11.0