-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLegacyDeleteBudgetPlan.php
More file actions
49 lines (42 loc) · 1.53 KB
/
LegacyDeleteBudgetPlan.php
File metadata and controls
49 lines (42 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace App\Console\Commands;
use App\Models\Legacy\LegacyBudgetItem;
use App\Models\Legacy\LegacyBudgetPlan;
use Illuminate\Console\Command;
class LegacyDeleteBudgetPlan extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'legacy:delete-hhp {id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Deletes a given HHP - DANGER - deletes old one without looking out for foreign keys - Potentially corrupting datas ';
/**
* Execute the console command.
*/
public function handle(): void
{
$hhp = LegacyBudgetPlan::findOrFail($this->argument('id'));
$groups = $hhp->budgetGroups();
$title = LegacyBudgetItem::whereIn('hhpgruppen_id', $groups->pluck('id'));
$this->info("Found {$title->count()} titles");
$this->warn('This operation cannot be rolled back and will be done without checking corresponding foreign keys');
if (! $this->confirm("Are you sure you want to delete HHP from {$hhp->von} to {$hhp->bis} in state {$hhp->state}?")) {
return;
}
\DB::transaction(function () use ($hhp, $groups, $title): void {
\Schema::disableForeignKeyConstraints();
$title->delete();
$groups->delete();
$hhp->delete();
\Schema::enableForeignKeyConstraints();
$this->info('Plan, Groups and Bugets are deleted successfully!');
});
}
}