|
Revision 357, 1.2 kB
(checked in by ogawa, 21 months ago)
|
|
Uses add_tags instead of set_tags.
|
-
Property svn:executable set to
*
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | # $Id$ |
|---|
| 4 | # A simple tool for adding tags to each entries based on their categories |
|---|
| 5 | # |
|---|
| 6 | # This software is provided as-is. You may use it for commercial or |
|---|
| 7 | # personal use. If you distribute it, please keep this notice intact. |
|---|
| 8 | # |
|---|
| 9 | # Copyright (c) 2006,2007 Hirotaka Ogawa |
|---|
| 10 | |
|---|
| 11 | use strict; |
|---|
| 12 | sub BEGIN { |
|---|
| 13 | my $dir; |
|---|
| 14 | require File::Spec; |
|---|
| 15 | if (!($dir = $ENV{MT_HOME})) { |
|---|
| 16 | if ($0 =~ m!(.*[/\\])!) { |
|---|
| 17 | $dir = $1; |
|---|
| 18 | } else { |
|---|
| 19 | $dir = './'; |
|---|
| 20 | } |
|---|
| 21 | $ENV{MT_HOME} = $dir; |
|---|
| 22 | } |
|---|
| 23 | unshift @INC, File::Spec->catdir($dir, 'lib'); |
|---|
| 24 | unshift @INC, File::Spec->catdir($dir, 'extlib'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | $|=1; |
|---|
| 28 | print "Content-Type: text/html\n\n"; |
|---|
| 29 | print <<HTML; |
|---|
| 30 | <html> |
|---|
| 31 | <head><title>mt-cats2tags</title></head> |
|---|
| 32 | <body> |
|---|
| 33 | <h1>mt-cats2tags</h1> |
|---|
| 34 | |
|---|
| 35 | <pre> |
|---|
| 36 | HTML |
|---|
| 37 | |
|---|
| 38 | use MT; |
|---|
| 39 | use MT::Entry; |
|---|
| 40 | use MT::Category; |
|---|
| 41 | |
|---|
| 42 | my $mt = MT->new or die MT->errstr; |
|---|
| 43 | my $iter = MT::Entry->load_iter; |
|---|
| 44 | |
|---|
| 45 | while (my $e = $iter->()) { |
|---|
| 46 | my $cats = $e->categories; |
|---|
| 47 | next unless $cats && @$cats; |
|---|
| 48 | my @tags = map { $_->label } @$cats; |
|---|
| 49 | $e->add_tags(@tags); |
|---|
| 50 | $e->save_tags; |
|---|
| 51 | print $e->id . ": " . join(', ', @tags) . "\n"; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | print <<HTML; |
|---|
| 55 | </pre> |
|---|
| 56 | <p><strong>Successfully added tags.</strong></p> |
|---|
| 57 | </body> |
|---|
| 58 | </html> |
|---|
| 59 | HTML |
|---|