RT#14829: automatic payments triggered by bill now show up as Payment by fs_queue
[freeside.git] / FS / bin / freeside-queued
index 70d8534..398b03d 100644 (file)
@@ -196,7 +196,7 @@ while (1) {
       dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
 
       #auto-use classes...
-      if (    $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg|Cron)::\w+)::/
+      if (    $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg|part_pkg|Cron)::\w+)::/
            || $ljob->job =~ /(FS::\w+)::/
          )
       {
@@ -218,8 +218,13 @@ while (1) {
       # don't put @args in the log, may expose passwords
       $log->info('starting job ('.$ljob->job.')');
       warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG;
+      # switch user only if a job user is available
+      my $oldCurrentUser = $FS::CurrentUser::CurrentUser;
+      my $jobuser = $ljob->access_user;
+      local $FS::CurrentUser::CurrentUser = $jobuser if $jobuser;
       local $FS::UID::AutoCommit = 0; # so that we can clean up failures
       eval $eval; #throw away return value?  suppose so
+      $FS::CurrentUser::CurrentUser = $oldCurrentUser if $jobuser;
       if ( $@ ) {
         dbh->rollback;
         my %hash = $ljob->hash;