diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index 6674b00..99f35db 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -1020,21 +1020,46 @@ class SystemController extends Controller $db->beginTransaction(); - $existingPhaseType = $db->selectValue( - 'SELECT COUNT(*) FROM launch_phases WHERE tld_id = ? AND phase_type = ?', + // Check if phaseType is 'Custom' and phaseName is empty + if ($sData['phaseType'] === 'Custom' && (empty($sData['phaseName']) || is_null($sData['phaseName']))) { + // Handle the error scenario + $this->container->get('flash')->addMessage('error', 'Phase name is required when the type is Custom.'); + return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302); + } + + // Check for existing phase_type or date overlap + $query = "SELECT + (SELECT COUNT(*) FROM launch_phases WHERE tld_id = ? AND phase_type = ?) as phaseTypeExists, + (SELECT COUNT(*) FROM launch_phases + WHERE tld_id = ? AND + ((start_date <= ? AND end_date >= ?) OR + (start_date <= ? AND end_date >= ?) OR + (start_date >= ? AND end_date <= ?))) as dateOverlapExists"; + + $result = $db->selectRow( + $query, [ - $sData['tldid'], - $sData['phaseType'] + $sData['tldid'], $sData['phaseType'], + $sData['tldid'], $sData['phaseEnd'], $sData['phaseStart'], + $sData['phaseStart'], $sData['phaseEnd'], + $sData['phaseStart'], $sData['phaseEnd'] ] ); - - if ($existingPhaseType > 0) { + + if ($result['phaseTypeExists'] > 0) { // phase_type already exists for the tldid $db->rollBack(); $this->container->get('flash')->addMessage('error', 'The phase type 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(); + $this->container->get('flash')->addMessage('error', 'Date range overlaps with an existing phase for this TLD.'); + return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302); + } + $db->insert( 'launch_phases', [ diff --git a/cp/resources/views/admin/system/manageTld.twig b/cp/resources/views/admin/system/manageTld.twig index 0985666..ed71372 100644 --- a/cp/resources/views/admin/system/manageTld.twig +++ b/cp/resources/views/admin/system/manageTld.twig @@ -200,7 +200,6 @@ - @@ -212,7 +211,6 @@ {% for promo in promotions %} - @@ -240,13 +238,13 @@
- +
- +
@@ -294,7 +292,6 @@
ID Promotion Name Start Date End Date
{{ promo.id }} {{ promo.promo_name }} {{ promo.start_date }} {{ promo.end_date }}
- @@ -305,9 +302,8 @@ {% for phase in launch_phases %} - - - + + @@ -335,8 +331,9 @@
- - + + + The "Phase name" field is required only if the "Type" is set to "Custom".
@@ -346,13 +343,13 @@
- +
- +
diff --git a/database/registry.mariadb.sql b/database/registry.mariadb.sql index 1a78c2b..e24ba54 100644 --- a/database/registry.mariadb.sql +++ b/database/registry.mariadb.sql @@ -5,7 +5,7 @@ CREATE DATABASE IF NOT EXISTS `registry`; CREATE TABLE IF NOT EXISTS `registry`.`launch_phases` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `tld_id` int(10) unsigned DEFAULT NULL, - `phase_name` VARCHAR(75) NOT NULL, + `phase_name` VARCHAR(75) DEFAULT NULL, `phase_type` VARCHAR(50) NOT NULL, `phase_description` TEXT, `start_date` DATETIME(3) NOT NULL, diff --git a/database/registry.postgres.sql b/database/registry.postgres.sql index 7eae492..5b990f7 100644 --- a/database/registry.postgres.sql +++ b/database/registry.postgres.sql @@ -6,7 +6,7 @@ SET search_path TO registry, registryTransaction, public; CREATE TABLE registry.launch_phases ( "id" SERIAL PRIMARY KEY, "tld_id" INT CHECK ("tld_id" >= 0), - "phase_name" VARCHAR(75) NOT NULL, + "phase_name" VARCHAR(75) DEFAULT NULL, "phase_type" VARCHAR(50) NOT NULL, "phase_description" TEXT, "start_date" TIMESTAMP(3) NOT NULL,
ID Phase Type Phase Name Phase Description
{{ phase.id }}{{ phase.phase_type }}{{ phase.phase_name }}{{ phase.phase_type|capitalize }}{{ phase.phase_name|default('N/A') }} {{ phase.phase_description }} {{ phase.start_date }} {{ phase.end_date }}