From db0c0286efa46147d109dfcfccabd222deb99df3 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:05:18 +0200 Subject: [PATCH] Fixed issue with repeating names for launch phases --- cp/app/Controllers/SystemController.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index f7f4800..0025797 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -1497,7 +1497,13 @@ class SystemController extends Controller OR (start_date >= ? AND (end_date IS NULL OR end_date <= ?)) ) AND (end_date IS NULL OR end_date >= NOW()) -- Ensures ongoing phases count - ) AS dateOverlapExists"; + ) AS dateOverlapExists, + + (SELECT COUNT(*) + FROM launch_phases + WHERE tld_id = ? + AND phase_name = ? + ) AS duplicatePhaseNameExists"; $result = $db->selectRow( $query, @@ -1505,7 +1511,8 @@ class SystemController extends Controller $sData['tldid'], $sData['phaseType'], $sData['phaseName'], $sData['tldid'], $sData['phaseEnd'], $sData['phaseStart'], $sData['phaseStart'], $sData['phaseEnd'], - $sData['phaseStart'], $sData['phaseEnd'] + $sData['phaseStart'], $sData['phaseEnd'], + $sData['tldid'], $sData['phaseName'] ] ); @@ -1516,6 +1523,12 @@ class SystemController extends Controller return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302); } + if ($result['duplicatePhaseNameExists'] > 0) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'A phase with this name already exists for this TLD.'); + return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302); + } + if ($result['dateOverlapExists'] > 0) { // Date range overlaps with an existing entry $db->rollBack();