diff options
author | Ivan Kohler <ivan@freeside.biz> | 2016-09-01 17:00:22 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2016-09-01 17:00:22 -0700 |
commit | ddb601f6bb7bdce8e0912e78472335f5613d20db (patch) | |
tree | c332e0d18be5f14e1cfb8c42ccd2a46122e3b163 /bin/part_pkg-clone_fix_options | |
parent | 4a896c6c3703b5f509fc75e98a7982fbcd85f9ae (diff) | |
parent | f33281a9f445b06e319c45f393c71577701eff67 (diff) |
Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE_3_BRANCH
Diffstat (limited to 'bin/part_pkg-clone_fix_options')
-rwxr-xr-x | bin/part_pkg-clone_fix_options | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bin/part_pkg-clone_fix_options b/bin/part_pkg-clone_fix_options new file mode 100755 index 000000000..4d8192bce --- /dev/null +++ b/bin/part_pkg-clone_fix_options @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use strict; +use FS::Misc::Getopt; +use FS::part_pkg; +use FS::Record qw(qsearch dbh); + +our %opt; +getopts('p:'); # pkgpart +$FS::UID::AutoCommit = 0; + +sub usage { + die "Usage: part_pkg-clone_fix_options -p pkgpart[,pkgpart...] user\n\n"; +} + +my @pkgpart = split(',',$opt{p}) or usage(); +foreach my $base_pkgpart (@pkgpart) { + my $base_part_pkg = FS::part_pkg->by_key($base_pkgpart); + warn "Base package '".$base_part_pkg->pkg."'\n"; + my @children = qsearch('part_pkg', { 'family_pkgpart' => $base_pkgpart }); + next if !@children; + my $n_pkg = 0; + my $n_upd = 0; + my %base_options = $base_part_pkg->options; + my %report_classes = map { $_ => $base_options{$_} } + grep /^report_option_/, keys %base_options; + if (!keys %report_classes) { + warn "No report classes.\n"; + next; + } + + foreach my $part_pkg (@children) { + my $pkgpart = $part_pkg->pkgpart; + next if $pkgpart == $base_pkgpart; + $n_pkg++; + + # don't do this if it has report options already + my %options = $part_pkg->options; + if (grep /^report_option_/, keys %options) { + warn "#$pkgpart has report classes; skipped\n"; + } else { + %options = ( %options, %report_classes ); + my $error = $part_pkg->replace(options => \%options); + die "#$pkgpart: $error\n" if $error; + $n_upd++; + } + } + warn "Updated $n_upd / $n_pkg child packages.\n"; +} + +warn "Finished.\n"; +dbh->commit; + |