mt-rebuild-monthly.cgi

任意の月の Monthly Archive のみを rebuild する CGI (perlスクリプト) です。

本 CGI は 「new script: mt-rebuild-all.cgi, rebuilt all blogs from MT browser gui」 を参考にしています。

#!/usr/bin/perl -w
# mt-rebuild-monthly.cgi         04 Nov 2003
#    written by H.Tsujimura (tsupo@na.rim.or.jp)
#    last updated by H.Tsujimura 26 Nov 2003
#
#   usege:
#      http://yourBlogCGIPath/mt-rebuild-monthly.cgi
#        to rebuild the monthly archive last entry belongs to
#
#      http://yourBlogCGIPath/mt-rebuild-monthly.cgi?entry_id
#        to rebuild the monthly archive the entry specified entry_id belongs to
#
use strict; 
use CGI::Carp qw(fatalsToBrowser);

my($MT_DIR);
BEGIN {
   if ($0 =~ m!(.*[/\\])!) {$MT_DIR = $1;} else {$MT_DIR = './'; }
   unshift @INC, $MT_DIR . 'lib';
   unshift @INC, $MT_DIR . 'extlib';
}

require MT;
my $mt = MT->new(Config => $MT_DIR .'mt.cfg',
                 Directory => $MT_DIR)
             || die print "Error".(MT->errstr);

require MT::Blog;
require MT::Entry;

print "Content-type: text/html\n\n<html lang=\"ja\">\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html;";
print " charset=UTF-8\" />\n";
print "<title>rebuild monthly archive</title>\n</head>\n\n<body>\n";

my $entry_id = $ENV{'QUERY_STRING'};

my $entry;
my $blog_id=1;
my $blog = MT::Blog->load($blog_id);
if (!$blog) {print "failed to load blog $blog_id\n";  exit 1;}

if (!$entry_id) {
  # if NOT specified entry_id, considered the last entry is the target entry. 
  # entry_id が指定されていない場合は、最新のエントリを対象とする
    my $iter = MT::Entry->load_iter(
            { blog_id => $blog_id },
            { 'sort' => 'created_on',
              direction => 'descend',
              limit => 5 });
    $entry = $iter->(); # いちばん最新のエントリ
}
else {
  # if specified entry_id, that's just the target entry.
  # entry_id が指定されている場合は、当該エントリを対象とする
    $entry = MT::Entry->load($entry_id);
}

# rebuilding the monthly archive to which a specification entry belongs
# 指定エントリの投稿月の monthly archive のみを rebuild する
#   (エントリの投稿年月日が yyyy年mm月dd日 なら yyyy年mm月の
#    monthly archive のみを rebuild する)
print "<p>Rebuild Monthly Archive ... </p>\n<blockquote>\n";
    print "EnteryTitle    = ", $entry->title, "<br>\n";
    print "EnteryDateTime = ", $entry->created_on, "<br>\n";
    print "<strong>Target Monthly Archive is ``", substr($entry->created_on,0,4),
          "_", substr($entry->created_on,4,2), "''...</strong><br>\n";
    $mt->_rebuild_entry_archive_type(Entry => $entry,
                                     Blog => $blog,
                                     ArchiveType => 'Monthly')
        or die $mt->errstr;
print "</blockquote>\n<p>done.</p>\n<hr>\n";

if ( $blog_id != $entry->blog_id ) {
    $blog_id = $entry->blog_id;
    $blog = MT::Blog->load($blog_id);
}

print "<font class='message'>";
print "Completed: ".($blog->name).", elapsed time = ".(time - $^T);
print " seconds </font><br><br>\n";

END {
print "</html>","\n";
}    

[「rebuild支援ツール」の説明に戻る] [プログラミングへ戻る]
[Activity Memoへ戻る]
[Tsuporoneのトップページへ戻る]


Google

Access Count: 

Copyright (c) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009, 2010, 2011, 2012 by Hiroshi Tsujimura (tsupo@na.rim.or.jp) Some Rights Reserved.
Last Modified: Wednesday, 29-Aug-2007 03:54:10 JST