diff options
author | ivan <ivan> | 2006-07-25 07:27:32 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-07-25 07:27:32 +0000 |
commit | 4f056133e2a2bd84d8d789acf24aba695a6e3688 (patch) | |
tree | 5e7d751a26cfdf80a394ae170bc2623d7ccdcb3f /bin | |
parent | c4dd2593a5cf5c4463a9180fbc5aef1f2c76f6e2 (diff) |
quick script to convert rt links from one database name to another
Diffstat (limited to 'bin')
-rw-r--r-- | bin/rt-update-links | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/rt-update-links b/bin/rt-update-links new file mode 100644 index 000000000..75d554f48 --- /dev/null +++ b/bin/rt-update-links @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +use FS::UID qw(adminsuidsetup); + +my( $olddb, $newdb ) = ( shift, shift ); + +$FS::CurrentUser::upgrade_hack = 1; +my $dbh = adminsuidsetup; + +my $statement = "select * from links where base like 'fsck.com-rt://$olddb/%' OR target like 'fsck.com-rt://$olddb/%'"; + +my $sth = $dbh->prepare($statement) or die $dbh->errstr; +$sth->execute or die $sth->errstr; + +while ( my $row = $sth->fetchrow_hashref ) { + + ( my $base = $row->{'base'} ) + =~ s(^fsck\.com-rt://$olddb/)(fsck.com-rt://$newdb/); + + ( my $target = $row->{'target'} ) + =~ s(^fsck\.com-rt://$olddb/)(fsck.com-rt://$newdb/); + + if ( $row->{'base'} ne $base || $row->{'target'} ne $target ) { + + my $update = 'UPDATE links SET base = ?, target = ? where id = ?'; + my @param = ( $base, $target, $row->{'id'} ); + + warn "$update : ". join(', ', @param). "\n"; + $dbh->do($update, {}, @param ); + + } + +} + +$dbh->commit; + |