İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// Get the test_pack_base_status that is being deleted
|
||||
$testPackBaseStatus = db("test_pack_base_statuses")->where("id", $request['key'])->first();
|
||||
|
||||
if ($testPackBaseStatus) {
|
||||
try {
|
||||
$testPackageNo = $testPackBaseStatus->test_package_no;
|
||||
|
||||
// Check if there are any remaining test_pack_base_statuses records with the same test_package_no
|
||||
$remainingCount = db("test_pack_base_statuses")
|
||||
->where("test_package_no", $testPackageNo)
|
||||
->where("id", "!=", $request['key']) // Exclude the current record being deleted
|
||||
->count();
|
||||
|
||||
// Only delete test_packages if no other test_pack_base_statuses records exist for this test_package_no
|
||||
if ($remainingCount == 0) {
|
||||
// Check if there are any weld_logs records with this test_package_no
|
||||
$weldLogsCount = db("weld_logs")
|
||||
->where("test_package_no", $testPackageNo)
|
||||
->count();
|
||||
|
||||
if ($weldLogsCount > 0) {
|
||||
dump("Cannot delete test_packages. Found $weldLogsCount weld_logs records for test_package_no: $testPackageNo");
|
||||
} else {
|
||||
$deletedCount = db("test_packages")
|
||||
->where("test_package_number", $testPackageNo)
|
||||
->delete();
|
||||
|
||||
dump("No remaining test_pack_base_statuses for test_package_no: $testPackageNo. Deleted $deletedCount test_packages records.");
|
||||
}
|
||||
} else {
|
||||
dump("Found $remainingCount remaining test_pack_base_statuses for test_package_no: $testPackageNo. Keeping test_packages records.");
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
dump("Error processing test_packages deletion: " . $th->getMessage());
|
||||
Log::error("DeleteTrigger test_pack_base_statuses error: " . $th->getMessage());
|
||||
}
|
||||
} else {
|
||||
dump("Test pack base status not found with id: " . $request['key']);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user