Small fixes and checks on phase management

This commit is contained in:
Pinga 2023-12-18 10:14:17 +02:00
parent 34fe2a866f
commit adf0c37174
4 changed files with 42 additions and 20 deletions

View file

@ -1020,21 +1020,46 @@ class SystemController extends Controller
$db->beginTransaction(); $db->beginTransaction();
$existingPhaseType = $db->selectValue( // Check if phaseType is 'Custom' and phaseName is empty
'SELECT COUNT(*) FROM launch_phases WHERE tld_id = ? AND phase_type = ?', 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['tldid'], $sData['phaseType'],
$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 // phase_type already exists for the tldid
$db->rollBack(); $db->rollBack();
$this->container->get('flash')->addMessage('error', 'The phase type already exists for this TLD.'); $this->container->get('flash')->addMessage('error', 'The phase type already exists for this TLD.');
return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302); 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( $db->insert(
'launch_phases', 'launch_phases',
[ [

View file

@ -200,7 +200,6 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>ID</th>
<th>Promotion Name</th> <th>Promotion Name</th>
<th>Start Date</th> <th>Start Date</th>
<th>End Date</th> <th>End Date</th>
@ -212,7 +211,6 @@
<tbody> <tbody>
{% for promo in promotions %} {% for promo in promotions %}
<tr> <tr>
<td>{{ promo.id }}</td>
<td>{{ promo.promo_name }}</td> <td>{{ promo.promo_name }}</td>
<td>{{ promo.start_date }}</td> <td>{{ promo.start_date }}</td>
<td>{{ promo.end_date }}</td> <td>{{ promo.end_date }}</td>
@ -240,13 +238,13 @@
<div class="col-sm-6 col-md-6"> <div class="col-sm-6 col-md-6">
<div class="mb-3"> <div class="mb-3">
<label for="promotionStart" class="form-label required">Promotion Start Date</label> <label for="promotionStart" class="form-label required">Promotion Start Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="promotionStart" name="promotionStart" required> <input type="datetime-local" class="form-control" placeholder="e.g., 01/01/2023" id="promotionStart" name="promotionStart" required>
</div> </div>
</div> </div>
<div class="col-sm-6 col-md-6"> <div class="col-sm-6 col-md-6">
<div class="mb-3"> <div class="mb-3">
<label for="promotionEnd" class="form-label">Promotion End Date</label> <label for="promotionEnd" class="form-label">Promotion End Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="promotionEnd" name="promotionEnd"> <input type="datetime-local" class="form-control" placeholder="e.g., 01/01/2023" id="promotionEnd" name="promotionEnd">
</div> </div>
</div> </div>
</div> </div>
@ -294,7 +292,6 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>ID</th>
<th>Phase Type</th> <th>Phase Type</th>
<th>Phase Name</th> <th>Phase Name</th>
<th>Phase Description</th> <th>Phase Description</th>
@ -305,9 +302,8 @@
<tbody> <tbody>
{% for phase in launch_phases %} {% for phase in launch_phases %}
<tr> <tr>
<td>{{ phase.id }}</td> <td>{{ phase.phase_type|capitalize }}</td>
<td>{{ phase.phase_type }}</td> <td>{{ phase.phase_name|default('N/A') }}</td>
<td>{{ phase.phase_name }}</td>
<td>{{ phase.phase_description }}</td> <td>{{ phase.phase_description }}</td>
<td>{{ phase.start_date }}</td> <td>{{ phase.start_date }}</td>
<td>{{ phase.end_date }}</td> <td>{{ phase.end_date }}</td>
@ -335,8 +331,9 @@
</select> </select>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="phaseName" class="form-label required">Phase Name</label> <label for="phaseName" class="form-label">Phase Name</label>
<input type="text" class="form-control" id="phaseName" name="phaseName" placeholder="Enter phase name" required> <input type="text" class="form-control" id="phaseName" name="phaseName" placeholder="Enter phase name">
<small class="form-hint">The "Phase name" field is required only if the "Type" is set to "Custom".</small>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="phaseDescription" class="form-label required">Phase Description</label> <label for="phaseDescription" class="form-label required">Phase Description</label>
@ -346,13 +343,13 @@
<div class="col-sm-6 col-md-6"> <div class="col-sm-6 col-md-6">
<div class="mb-3"> <div class="mb-3">
<label for="phaseStart" class="form-label required">Phase Start Date</label> <label for="phaseStart" class="form-label required">Phase Start Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="phaseStart" name="phaseStart" required> <input type="datetime-local" class="form-control" placeholder="e.g., 01/01/2023" id="phaseStart" name="phaseStart" required>
</div> </div>
</div> </div>
<div class="col-sm-6 col-md-6"> <div class="col-sm-6 col-md-6">
<div class="mb-3"> <div class="mb-3">
<label for="phaseEnd" class="form-label">Phase End Date</label> <label for="phaseEnd" class="form-label">Phase End Date</label>
<input type="date" class="form-control" placeholder="e.g., 01/01/2023" id="phaseEnd" name="phaseEnd"> <input type="datetime-local" class="form-control" placeholder="e.g., 01/01/2023" id="phaseEnd" name="phaseEnd">
</div> </div>
</div> </div>
</div> </div>

View file

@ -5,7 +5,7 @@ CREATE DATABASE IF NOT EXISTS `registry`;
CREATE TABLE IF NOT EXISTS `registry`.`launch_phases` ( CREATE TABLE IF NOT EXISTS `registry`.`launch_phases` (
`id` INT AUTO_INCREMENT PRIMARY KEY, `id` INT AUTO_INCREMENT PRIMARY KEY,
`tld_id` int(10) unsigned DEFAULT NULL, `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_type` VARCHAR(50) NOT NULL,
`phase_description` TEXT, `phase_description` TEXT,
`start_date` DATETIME(3) NOT NULL, `start_date` DATETIME(3) NOT NULL,

View file

@ -6,7 +6,7 @@ SET search_path TO registry, registryTransaction, public;
CREATE TABLE registry.launch_phases ( CREATE TABLE registry.launch_phases (
"id" SERIAL PRIMARY KEY, "id" SERIAL PRIMARY KEY,
"tld_id" INT CHECK ("tld_id" >= 0), "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_type" VARCHAR(50) NOT NULL,
"phase_description" TEXT, "phase_description" TEXT,
"start_date" TIMESTAMP(3) NOT NULL, "start_date" TIMESTAMP(3) NOT NULL,