#!/usr/bin/perl -w use strict; # DO NOT USE THIS SCRIPT WITHOUT FULLY BACKING UP YOUR ENTIRE DADA MAIL INSTALL # REALLY. use DADA::Config; use DADA::App::Guts; my $database = $SQL_PARAMS{database}; my $dbserver = $SQL_PARAMS{dbserver}; my $port = $SQL_PARAMS{port}; my $user = $SQL_PARAMS{user}; my $pass = $SQL_PARAMS{pass}; my $dbtype = $SQL_PARAMS{dbtype}; if(!$dbtype){ $dbtype = 'mysql' if $DB_TYPE eq 'MySQL'; $dbtype = 'Pg' if $DB_TYPE eq 'PostgreSQL'; } use lib qw(./ ../ ../../ ../../../ ./../../DADA ../../perllib); my $dbh; use CGI qw(:standard); print header(); print '
';
use Fcntl qw(
O_RDWR O_CREAT);
use lib qw(./ ./DADA ./DADA/perllib);
use AnyDBM_File;
use DBI;
connectdb();
print "beginning...\n";
foreach my $list(DADA::App::Guts::available_lists()){
print "\tworking on list: '$list'...\n";
my %old_data;
print "\t" . $ARCHIVES . '/mj-' . $list . '-archive' . "\n";
my $filename = $ARCHIVES . '/mj-' . $list . '-archive';
tie %old_data, "AnyDBM_File", $filename, O_RDWR|O_CREAT or die $!;
foreach my $key(keys %old_data){
my $entry = $old_data{$key};
my ($subject, $message, $format, $raw_msg) = split(/\[::\]/, $entry);
set_archive_info($list, $key, $subject, $message, $format, $raw_msg);
print "\t\tentry $key... Done!\n";
}
untie %old_data;
}
print "Done.\n\n";
disconnectdb();
sub connectdb {
my $data_source = "dbi:$dbtype:dbname=$database;host=$dbserver;port=$port";
$dbh = DBI->connect("$data_source", $user, $pass) || die("can't connect to db: $!");
}
sub disconnectdb {
$dbh->disconnect;
}
sub set_archive_info {
my $list = shift;
my $key = shift;
my $new_subject = shift;
my $new_message = shift;
my $new_format = shift;
my $raw_msg = shift;
my $query = 'INSERT INTO '. $SQL_PARAMS{archives_table} .' VALUES (?,?,?,?,?,?)';
my $sth = $dbh->prepare($query);
$sth->execute($list, $key, $new_subject, $new_message, $new_format, $raw_msg);
return 1;
}
__END__
=cut
=pod
=head1 Name dada_archive_dbtosql.pl
=head1 Description
Cute name, huh?
Basically, this small script takes the information of a Dada Mail archive in the DB File and ports it to the MySQL format.
Fairly simple and straightforward.
=head1 How to use this script
=over
=item * Backup Everything
SQL tables, list files (all of them)
=item * Create the Archives SQL table
The SQL statement to run should be saved in a file called I which is located in the I directory of the distribution
=item * Set B to the correct SQL type (MySQL, Postgres)
Directions are located in the Config.pm about this, search for, I<$ARCHIVE_DB_TYPE>
=item * Fill in %SQL_PARAMS in the Config.pm file
Again, directions should be supplied in the Config.pm file.
=back
After the above (do not skip a step) are done, make sure Dada Mail is still running by visiting it in your webbrowser. The program should run exactly as before, except no archives should be available.
Upload this script into the same directory that you have the I script in, and run it, either from your web browser, or via the command line.
That should be it.
ps. backup everything.
=head1 COPYRIGHT
Copyright (c) 1999 - 2005 Justin Simoni All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=cut