+ # now upgrade to the explicit custom flag
+
+ @part_pkg = qsearch({
+ 'table' => 'part_pkg',
+ 'hashref' => { disabled => 'Y', custom => '' },
+ 'extra_sql' => "AND comment LIKE '(CUSTOM) %'",
+ });
+
+ foreach my $part_pkg (@part_pkg) {
+ my $new = new FS::part_pkg { $part_pkg->hash };
+ $new->custom('Y');
+ my $comment = $part_pkg->comment;
+ $comment =~ s/^\(CUSTOM\) //;
+ $comment = '(none)' unless $comment =~ /\S/;
+ $new->comment($comment);
+
+ my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc };
+ my $primary = $part_pkg->svcpart;
+ my $options = { $part_pkg->options };
+
+ my $error = $new->replace( $part_pkg,
+ 'pkg_svc' => $pkg_svc,
+ 'primary_svc' => $primary,
+ 'options' => $options,
+ );
+ die $error if $error;
+ }
+
+ my @part_pkg_option = qsearch('part_pkg_option',
+ { 'optionname' => 'unused_credit',
+ 'optionvalue' => 1,
+ });
+ foreach my $old_opt (@part_pkg_option) {
+ my $pkgpart = $old_opt->pkgpart;
+ my $error = $old_opt->delete;
+ die $error if $error;
+
+ foreach (qw(unused_credit_cancel unused_credit_change)) {
+ my $new_opt = new FS::part_pkg_option {
+ 'pkgpart' => $pkgpart,
+ 'optionname' => $_,
+ 'optionvalue' => 1,
+ };
+ $error = $new_opt->insert;
+ die $error if $error;
+ }
+ }
+
+ # migrate use_disposition_taqua and use_disposition to disposition_in
+ @part_pkg_option = qsearch('part_pkg_option',
+ { 'optionname' => { op => 'LIKE',
+ value => 'use_disposition%',
+ },
+ 'optionvalue' => 1,
+ });
+ my %newopts = map { $_->pkgpart => $_ }
+ qsearch('part_pkg_option', { 'optionname' => 'disposition_in', } );
+ foreach my $old_opt (@part_pkg_option) {
+ my $pkgpart = $old_opt->pkgpart;
+ my $newval = $old_opt->optionname eq 'use_disposition_taqua' ? '100'
+ : 'ANSWERED';
+ my $error = $old_opt->delete;
+ die $error if $error;
+
+ if ( exists($newopts{$pkgpart}) ) {
+ my $opt = $newopts{$pkgpart};
+ $opt->optionvalue($opt->optionvalue.",$newval");
+ $error = $opt->replace;
+ die $error if $error;
+ } else {
+ my $new_opt = new FS::part_pkg_option {
+ 'pkgpart' => $pkgpart,
+ 'optionname' => 'disposition_in',
+ 'optionvalue' => $newval,
+ };
+ $error = $new_opt->insert;
+ die $error if $error;
+ $newopts{$pkgpart} = $new_opt;
+ }
+ }
+