| Conditions | 3 |
| Paths | 3 |
| Total Lines | 25 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | public function handle(): int |
||
| 29 | { |
||
| 30 | $now = Carbon::now(); |
||
| 31 | |||
| 32 | // Find all active promotions that have passed their end date |
||
| 33 | $expiredPromotions = RolePromotion::where('is_active', true) |
||
| 34 | ->whereNotNull('end_date') |
||
| 35 | ->where('end_date', '<', $now) |
||
| 36 | ->get(); |
||
| 37 | |||
| 38 | if ($expiredPromotions->isEmpty()) { |
||
| 39 | $this->info('No expired promotions found.'); |
||
| 40 | return Command::SUCCESS; |
||
| 41 | } |
||
| 42 | |||
| 43 | $count = 0; |
||
| 44 | foreach ($expiredPromotions as $promotion) { |
||
| 45 | $promotion->update(['is_active' => false]); |
||
| 46 | $this->line("Disabled promotion: {$promotion->name} (ended: {$promotion->end_date->format('Y-m-d')})"); |
||
| 47 | $count++; |
||
| 48 | } |
||
| 49 | |||
| 50 | $this->info("Successfully disabled {$count} expired promotion(s)."); |
||
| 51 | |||
| 52 | return Command::SUCCESS; |
||
| 53 | } |
||
| 56 |