|
5 | 5 | use Illuminate\Console\Command; |
6 | 6 | use ProcessMaker\Jobs\EvaluateProcessRetentionJob; |
7 | 7 | use ProcessMaker\Models\Process; |
| 8 | +use ProcessMaker\Models\ProcessCategory; |
8 | 9 |
|
9 | 10 | class EvaluateCaseRetention extends Command |
10 | 11 | { |
@@ -39,10 +40,30 @@ public function handle() |
39 | 40 | $this->info('Case retention policy is enabled'); |
40 | 41 | $this->info('Dispatching retention evaluation jobs for all processes'); |
41 | 42 |
|
| 43 | + // Get system category IDs to exclude |
| 44 | + $systemCategoryIds = ProcessCategory::where('is_system', true)->pluck('id'); |
| 45 | + |
42 | 46 | // Process all processes when retention policy is enabled |
| 47 | + // Exclude processes that are templates or in system categories |
43 | 48 | // Processes without retention_period will default to 1_year |
44 | 49 | $jobCount = 0; |
45 | | - Process::chunkById(100, function ($processes) use (&$jobCount) { |
| 50 | + $query = Process::where('is_template', '!=', 1); |
| 51 | + |
| 52 | + // Exclude processes in system categories |
| 53 | + if ($systemCategoryIds->isNotEmpty()) { |
| 54 | + $query->where(function ($q) use ($systemCategoryIds) { |
| 55 | + $q->where(function ($subQuery) use ($systemCategoryIds) { |
| 56 | + $subQuery->whereNotIn('process_category_id', $systemCategoryIds) |
| 57 | + ->orWhereNull('process_category_id'); |
| 58 | + }); |
| 59 | + }) |
| 60 | + ->whereDoesntHave('categories', function ($q) use ($systemCategoryIds) { |
| 61 | + // Exclude processes with any category assignment to system categories |
| 62 | + $q->whereIn('id', $systemCategoryIds); |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + $query->chunkById(100, function ($processes) use (&$jobCount) { |
46 | 67 | foreach ($processes as $process) { |
47 | 68 | dispatch(new EvaluateProcessRetentionJob($process->id)); |
48 | 69 | $jobCount++; |
|
0 commit comments