Skip to content

Commit dc5ca0d

Browse files
Prevent job from running on system & template processs
1 parent a1223b0 commit dc5ca0d

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎ProcessMaker/Console/Commands/EvaluateCaseRetention.php‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Command;
66
use ProcessMaker\Jobs\EvaluateProcessRetentionJob;
77
use ProcessMaker\Models\Process;
8+
use ProcessMaker\Models\ProcessCategory;
89

910
class EvaluateCaseRetention extends Command
1011
{
@@ -39,10 +40,30 @@ public function handle()
3940
$this->info('Case retention policy is enabled');
4041
$this->info('Dispatching retention evaluation jobs for all processes');
4142

43+
// Get system category IDs to exclude
44+
$systemCategoryIds = ProcessCategory::where('is_system', true)->pluck('id');
45+
4246
// Process all processes when retention policy is enabled
47+
// Exclude processes that are templates or in system categories
4348
// Processes without retention_period will default to 1_year
4449
$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) {
4667
foreach ($processes as $process) {
4768
dispatch(new EvaluateProcessRetentionJob($process->id));
4869
$jobCount++;

0 commit comments

Comments
 (0)