remove peripheral repositories from get_sgn_repos
[sgn-devtools.git] / one-offs / moinmoin_2_trac.pl
blob8907b6510ee5b0fa602804dbafb288dc993e4c10
1 #!/usr/bin/env perl
3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
6 use strict;
7 use warnings;
9 use DBI;
11 use Carp;
12 use FindBin;
14 use Getopt::Std;
15 use Pod::Usage;
17 use File::Basename;
19 use File::Spec::Functions qw/catfile/;
21 use Data::Dumper;
23 use File::Slurp qw/ slurp /;
25 our %opt;
26 getopts('',\%opt) or pod2usage(1);
28 my %page_files =
29 map {
30 my $dir_name = $_;
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
34 # name
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
51 else {
52 () #< if no current revision, return an empty list from
53 #the map to skip this one
55 }else{
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 );
69 SELECT name
70 FROM public.wiki
71 WHERE name = ?
72 EOQ
74 #extract version number and remove leading zeros
75 my ($version) = $file =~ /(\d+)$/;
76 $version += 0;
78 #get time, author, and IP number
79 my $time = time();
80 my $author = "internalsite_migration";
81 my $ipnr = "127.0.0.1";
83 #read in text of page
84 local $/;
85 open my $fh,'<',"$file" or next; #skip if the page is no longer in use (no current version #)
86 my $text = <$fh>;
87 close $fh;
89 #leave comment and readonly as undef
90 my $comment = "page automatically migrated from old moinmoin internal site";
91 my $readonly = undef;
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 (?,?,?,?,?,?,?,?)
97 EOQ
100 $dbh->commit();
101 $dbh->disconnect();
103 __END__
105 =head1 NAME
107 moinmoin_2_trac.pl - script to migrate internal wiki pages to trac wiki
109 =head1 SYNOPSIS
111 moinmoin_2_trac.pl
113 Options:
115 none
117 =head1 MAINTAINER
119 Rob Buels
121 =head1 AUTHOR
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.
132 =cut