3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
19 use File
::Spec
::Functions qw
/catfile/;
23 use File
::Slurp qw
/ slurp /;
26 getopts
('',\
%opt) or pod2usage
(1);
32 # the page name is just the directory name, so use basename()
33 # to take the beginning part of the path off to get the page
35 my $page_name = basename
($dir_name);
37 #### the file 'current' in the page's directory holds the revision number of the current revision of that page.
39 # first, assemble the full path to that file, then get the contents of that file
40 my $current_revision_file = catfile
( $dir_name, 'current' );
41 if( -f
$current_revision_file ) {
42 my $current_revision = slurp
( $current_revision_file );
43 $current_revision =~ s/\s//g; #remove all whitespace from what we got from that file
45 if( $current_revision ) { #< if there was a current revision
47 #now finally we know where the contents of the page is
48 my $current_page_file = catfile
( $dir_name, 'revisions', $current_revision );
49 $page_name => $current_page_file
52 () #< if no current revision, return an empty list from
53 #the map to skip this one
56 () #< if no current revision file, skip
58 } glob("/data/shared/wiki/data/pages/*/");
60 print Dumper \
%page_files;
63 my $dbh = DBI
->connect('DBI:Pg:dbname=trac_cxgn;host=localhost', 'trac', 'chaije9S', {AutoCommit
=> 0});
65 while ( my ($name,$file) = each %page_files ){
67 #skip page if it already exists in the trac wiki
68 next if $dbh->selectrow_arrayref( <<EOQ, undef, $name );
74 #extract version number and remove leading zeros
75 my ($version) = $file =~ /(\d+)$/;
78 #get time, author, and IP number
80 my $author = "internalsite_migration";
81 my $ipnr = "127.0.0.1";
85 open my $fh,'<',"$file" or next; #skip if the page is no longer in use (no current version #)
89 #leave comment and readonly as undef
90 my $comment = "page automatically migrated from old moinmoin internal site";
93 #insert page into trac wiki
94 $dbh->do( <<EOQ , undef, $name, $version, $time, $author, $ipnr, $text, $comment, $readonly );
95 INSERT INTO public.wiki (name, version, time, author, ipnr, text, comment, readonly)
96 VALUES (?,?,?,?,?,?,?,?)
107 moinmoin_2_trac.pl - script to migrate internal wiki pages to trac wiki
123 Hannah De Jong, summer intern
125 =head1 COPYRIGHT & LICENSE
127 Copyright 2009 Boyce Thompson Institute for Plant Research
129 This program is free software; you can redistribute it and/or modify
130 it under the same terms as Perl itself.