fix part_pkg-bulk_change when not using -o / -v, RT#41733
authorIvan Kohler <ivan@freeside.biz>
Sat, 14 May 2016 00:27:59 +0000 (17:27 -0700)
committerIvan Kohler <ivan@freeside.biz>
Sat, 14 May 2016 00:27:59 +0000 (17:27 -0700)
bin/part_pkg-bulk_change

index 32a5129..c882954 100755 (executable)
@@ -20,22 +20,28 @@ $search{'comment'} = $opt_m if $opt_m;
 foreach my $part_pkg ( qsearch('part_pkg',\%search) ) {
   next if ! $part_pkg->freq && $opt_r;
 
-  my %hash = (
-    'pkgpart'    => $part_pkg->pkgpart,
-    'optionname' => $opt_o,
-  );
-
-  my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
-
-  if ( $part_pkg_option ) {
-    next if $part_pkg_option->optionvalue eq $opt_v;
-    $part_pkg_option->optionvalue($opt_v);
-    my $error = $part_pkg_option->replace;
-    die $error if $error;
-  } else {
-    $part_pkg_option = new FS::part_pkg_option { %hash, 'optionvalue'=>$opt_v };
-    my $error = $part_pkg_option->insert;
-    die $error if $error;
+  if ( $opt_o ) {
+
+    my %hash = (
+      'pkgpart'    => $part_pkg->pkgpart,
+      'optionname' => $opt_o,
+    );
+
+    my $part_pkg_option = qsearchs('part_pkg_option', \%hash);
+
+    if ( $part_pkg_option ) {
+      next if $part_pkg_option->optionvalue eq $opt_v;
+      $part_pkg_option->optionvalue($opt_v);
+      my $error = $part_pkg_option->replace;
+      die $error if $error;
+    } else {
+      $part_pkg_option = new FS::part_pkg_option { %hash,
+                                                   'optionvalue'=>$opt_v,
+                                                 };
+      my $error = $part_pkg_option->insert;
+      die $error if $error;
+    }
+
   }
 
   if ( $opt_t || $opt_s || $opt_S || $opt_z || $opt_Z ) {