summaryrefslogtreecommitdiff
path: root/bin/fs-migrate-part_svc
blob: b0f3ac57eabd8f13a6fd7076bdf1f8413a41b729 (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
37
38
39
40
41
#!/usr/bin/perl

use strict;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch fields);
use FS::part_svc;

my $user = shift or die &usage;
my $dbh = adminsuidsetup $user;

my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;

foreach my $part_svc ( qsearch('part_svc', {} ) ) {
  foreach my $field (
    grep { defined($part_svc->getfield($part_svc->svcdb.'__'.$_.'_flag') ) }
      fields($part_svc->svcdb)
  ) {
    my $flag = $part_svc->getfield($part_svc->svcdb.'__'.$field.'_flag');
    if ( uc($flag) =~ /^([DF])$/ ) {
      my $part_svc_column = new FS::part_svc_column {
        'svcpart' => $part_svc->svcpart,
        'columnname' => $field,
        'columnflag' => $1,
        'columnvalue' => $part_svc->getfield($part_svc->svcdb.'__'.$field),
      };
      my $error = $part_svc_column->insert;
      if ( $error ) {
        $dbh->rollback if $oldAutoCommit;
        die $error;
      }
    }
  }
}

$dbh->commit or die $dbh->errstr;

sub usage {
  die "Usage:\n  fs-migrate-part_svc user\n"; 
}