Bug 22566: Accept 'all' in the branch params
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 18 Jun 2019 11:57:07 +0000 (12:57 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 25 Jun 2019 16:01:17 +0000 (17:01 +0100)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

misc/cronjobs/stockrotation.pl

index f3c6b91..3143839 100755 (executable)
@@ -126,20 +126,25 @@ my $ok = GetOptions(
     'admin-email|a=s' => \$admin_email,
     'branchcode|b=s'  => sub {
         my ( $opt_name, $opt_value ) = @_;
-        my $branches = Koha::Libraries->search( {},
-            { order_by => { -asc => 'branchname' } } );
-        my $brnch = $branches->find($opt_value);
-        if ($brnch) {
-            $branch = $brnch;
-            return $brnch;
+        if ( $opt_value eq 'all' ) {
+            $branch = 0;
         }
         else {
-            printf("Option $opt_name should be one of (name -> code):\n");
-            while ( my $candidate = $branches->next ) {
-                printf( "  %-40s  ->  %s\n",
-                    $candidate->branchname, $candidate->branchcode );
+            my $branches = Koha::Libraries->search( {},
+                { order_by => { -asc => 'branchname' } } );
+            my $brnch = $branches->find($opt_value);
+            if ($brnch) {
+                $branch = $brnch;
+                return $brnch;
+            }
+            else {
+                printf("Option $opt_name should be one of (name -> code):\n");
+                while ( my $candidate = $branches->next ) {
+                    printf( "  %-40s  ->  %s\n",
+                        $candidate->branchname, $candidate->branchcode );
+                }
+                exit 1;
             }
-            exit 1;
         }
     },
     'execute|x'  => \$execute,