Files
2026-10-10 15:57:19 +02:00

73 lines
2.5 KiB
PHP

<?php
namespace App\Actions\Cloning;
use App\Models\Projekte;
use App\Models\ProjektMethode;
use App\Models\ProjektObjekte;
use App\Models\ProjektObjekteImDetail;
use Filament\Notifications\Notification;
class Reparieren
{
public static function run(Projekte $record)
{
/**
* projektes
* projekt_users
* projekt_allgemeinflaechens
* projekt_inhaltsverzeichnis
* projekt_merkmales
* projekt_methodes
* projekt_platzhalters
* projekt_objekte_im_details
* projekt_objektes
*/
$ACTIVE_ID = $record->id;
// OBJEKTE IM DETAIL ZU OBJEKTE
// Kontrolliere Verbindungen geklonter und nicht geklonter
// Select all childreen from project
$res = ProjektObjekteImDetail::select('projekt_objekte_id')->where('projekte_id', $ACTIVE_ID)->groupBy('projekt_objekte_id')->get();
foreach ($res as $row) {
// See if parent exists
$res2 = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->where('id', $row->projekt_objekte_id)->first();
if (! $res2) {
// If parent NOT exists delete all childreen
ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->projekt_objekte_id)->delete();
}
}
// OBJEKTE ZU OBJEKTE IM DETAIL
$res = ProjektObjekte::where('projekte_id', $ACTIVE_ID)->get();
foreach ($res as $row) {
// See if cildreen exists
$res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_objekte_id', $row->id)->first();
if (! $res2) {
// If childree NOT exists delete parent
ProjektObjekte::where('id', $row->id)->delete();
}
}
// METHODEN ZU OBJEKTE IM DETAIL
$res = ProjektMethode::where('projekte_id', $ACTIVE_ID)->get();
foreach ($res as $row) {
// See if cildreen exists
$res2 = ProjektObjekteImDetail::where('projekte_id', $ACTIVE_ID)->where('projekt_methode_id', $row->id)->first();
if (! $res2) {
// If childree NOT exists delete parent
ProjektMethode::where('id', $row->id)->delete();
}
}
Notification::make()
->title('Projekt reparieren')
->body('Die Reparatur des Projektes war erfolgreich.')
->icon('heroicon-o-exclamation-triangle')
->duration(10000)
->success()
->send();
}
}