OSDN Git Service

Enhanced a Object's settings.
authorTaku Amano <taku@toi-planning.net>
Tue, 7 Jul 2009 09:23:09 +0000 (18:23 +0900)
committerTaku Amano <taku@toi-planning.net>
Wed, 2 Sep 2009 03:07:44 +0000 (12:07 +0900)
config.yaml
lib/Lovers/LoveLetter.pm

index 5e27a0e..8b8ffed 100644 (file)
@@ -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
 
index c9f9899..ff63246 100644 (file)
@@ -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;