root/IndexTemplateRebuilder/trunk/plugins/IndexTemplateRebuilder.pl

Revision 55, 1.7 kB (checked in by piroli, 8 ヶ月 ago)

リモート操作による項目の追加

X:\Web\magicvox.net\home\magicvox\www\www\cgi-bin\mt\plugins\builder\IndexTemplateRebuilder.pl

Line 
1 package MT::Plugin::OMV::IndexTemplateRebuilder;
2
3 use strict;
4 use MT::Blog;
5 use MT::Util;
6 use MT::Template;
7 use MT::Template::Context;
8 #use Data::Dumper;#DEBUG
9
10
11
12 MT::Template::Context->add_tag( BuildIndexTemplate  => \&_hdlr_build_index_template );
13 sub _hdlr_build_index_template {
14     my( $ctx, $args, $cond ) = @_;
15
16     ### Template to rebuild
17     my $tmpl_name = $args->{name}
18         or return $ctx->error( MT->translate( "You must set the Template Name." ));
19     my $blog = $ctx->stash( 'blog' );
20     if( defined( my $blog_id = $args->{blog_id})) {
21         $blog = MT::Blog->load({ id => $blog_id });
22     }
23     $blog or return $ctx->error( MT->translate( "Load of blog failed: [_1]", $ctx->stash( 'tag' )));
24
25     ### Loading specified template
26     my $tmpl = MT::Template->load({ type => 'index', blog_id => $blog->id, identifier => $tmpl_name })
27             || MT::Template->load({ type => 'index', blog_id => $blog->id, name => $tmpl_name })
28             || MT::Template->load({ type => 'index', blog_id => $blog->id, outfile => $tmpl_name })
29         or return $ctx->error( MT->translate( "Can't find template '[_1]'", $tmpl_name ));
30
31     ### Asynchronous rebuild
32     if( $args->{async} || $args->{background} ) {
33         MT::Util::start_background_task( sub {
34             MT->instance->rebuild_indexes( Blog => $blog, Template => $tmpl, Force => 1 )
35                 or return;
36         });
37     }
38     ### Synchronous
39     else {
40         MT->instance->rebuild_indexes( Blog => $blog, Template => $tmpl, Force => 1 )
41             or return;
42     }
43
44     ### My Outputs
45     $args->{verbose}
46         ? "<!-- ". localtime( time ()). ' - '. MT::Util::encode_html( $tmpl_name ). ' -->'
47         : '' # Empty return
48 }
49
50 1;
Note: See TracBrowser for help on using the browser.