mt-rebuild-category.cgi

任意のカテゴリの Category Archive のみを rebuild する CGI (perlスクリプト) です(が、現在の実装上の制限から、複数の Category Archives を rebuild してしまう可能性があります)。

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

#!/usr/bin/perl -w
# mt-rebuild-category.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-category.cgi
#        to rebuild the category archive(s) last entry belongs to
#
#      http://yourBlogCGIPath/mt-rebuild-category.cgi?entry_id
#        to rebuild the category archive(s) 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 category 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->(); # last enrty
                        # いちばん最新のエントリ
}
else {
  # if specified entry_id, that's just the target entry.
  # entry_id が指定されている場合は、当該エントリを対象とする
    $entry = MT::Entry->load($entry_id);
}

# rebuilding the category archive(s) to which a specification entry belongs
# 指定エントリの所属するカテゴリの category archive(s) のみを rebuild する
#   (エントリの所属するカテゴリが aaa と bbb ならカテゴリ aaa と bbb の
#    category archives のみを rebuild する)
print "<p>Rebuild Category Archive ... </p>\n<blockquote>\n";
    my $cats  = $entry->categories;
    print "EnteryTitle    = ".($entry->title)."<br>\n";
    print "EnteryDateTime = ".($entry->created_on)."<br>\n";

    for my $cat (@$cats) {
        print "<strong>Target Category #".($cat->id).": ".($cat->label)." (";
        print $cat->description, ") ...</strong><br>\n";
        $mt->_rebuild_entry_archive_type(
            Entry => $entry, Blog => $blog,
            Category => $cat, ArchiveType => 'Category'
        ) 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'>\n";
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:07 JST