Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created February 6, 2012 07:43
Show Gist options
  • Select an option

  • Save mizzy/1750502 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/1750502 to your computer and use it in GitHub Desktop.
Trac Wiki ページ一括移動用スクリプト
#!/usr/bin/perl
use strict;
use warnings;
use RPC::XML::Client;
use Getopt::Long;
GetOptions(
"base-url=s" => \my $base_url,
"base-path=s" => \my $base_path,
"user=s" => \my $user,
"password=s" => \my $password,
"current=s" => \my $current,
"new=s" => \my $new,
);
my $trac = RPC::XML::Client->new("$base_url/login/xmlrpc");
$trac->credentials('private area', $user, $password);
my $pages = $trac->send_request(
'wiki.getAllPages',
);
`rm -rf tmp/*`;
for my $page ( @{ $pages->value } ) {
if ( $page =~ /^$current/ ) {
my $new_page = my $file = $page;
$new_page =~ s/$current/$new/;
$file =~ s{/}{_}g;
`trac-admin $base_path wiki export $page tmp/$file`;
`trac-admin $base_path wiki import $new_page tmp/$file`;
my $attachments = $trac->send_request('wiki.listAttachments', $page);
for my $attachment ( @{ $attachments->value } ) {
my $content = $trac->send_request('wiki.getAttachment', $attachment);
my $new_attachment = $attachment;
$new_attachment =~ s/$current/$new/;
my $res = $trac->send_request('wiki.putAttachment', $new_attachment, $content);
}
my $res = $trac->send_request(
'wiki.putPage',
$page,
"Moved to wiki:$new_page",
RPC::XML::struct->new
);
}
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment