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();
$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',
[