summaryrefslogtreecommitdiff
path: root/bin/rt-update-links
blob: 75d554f48a5d0fffefad8939f53f09ec573a6d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;