diff --git a/frontend/classes/class.template.php b/frontend/classes/class.template.php index b85505a..4fab2c5 100644 --- a/frontend/classes/class.template.php +++ b/frontend/classes/class.template.php @@ -31,6 +31,18 @@ class Template extends CPHPDatabaseRecordClass 'IsOutdated' => "Outdated" ) ); + + function CheckAvailable() + { + if($this->sIsAvailable === true) + { + return true; + } + else + { + throw new TemplateUnavailableException("This template is not available."); + } + } } ?> diff --git a/frontend/includes/include.exceptions.php b/frontend/includes/include.exceptions.php index 444f09b..1a8b99b 100644 --- a/frontend/includes/include.exceptions.php +++ b/frontend/includes/include.exceptions.php @@ -53,4 +53,5 @@ class ContainerIpRemoveException extends ContainerException {} class ContainerTrafficRetrieveException extends ContainerException {} class UnauthorizedException extends Exception {} +class TemplateUnavailableException extends Exception {} ?> diff --git a/frontend/module.vps.reinstall.php b/frontend/module.vps.reinstall.php index 6a56544..4542ace 100644 --- a/frontend/module.vps.reinstall.php +++ b/frontend/module.vps.reinstall.php @@ -22,49 +22,42 @@ if(isset($_POST['submit'])) try { $sTemplate = new Template($_POST['template']); + $sTemplate->CheckAvailable(); - if($sTemplate->sIsAvailable === true) + if(isset($_POST['confirm'])) { - if(isset($_POST['confirm'])) + if($sContainer->sStatus != CVM_STATUS_SUSPENDED) { - if($sContainer->sStatus != CVM_STATUS_SUSPENDED) + try { - try - { - $sContainer->uTemplateId = $sTemplate->sId; - $sContainer->InsertIntoDatabase(); - $sContainer->Reinstall(); - $sContainer->Start(); - - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Reinstallation succeeded!", "Your VPS was successfully reinstalled."); - $sPageContents .= $err->Render(); - } - catch (ContainerReinstallException $e) - { - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation failed", "Something went wrong during the reinstallation of your VPS. Please try again. If the reinstallation fails again, please contact support."); - $sPageContents .= $err->Render(); - } - catch (ContainerStartException $e) - { - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_WARNING, "Failed to start", "The VPS was successfully reinstalled, but it could not be started. If the issue persists, please contact support."); - $sPageContents .= $err->Render(); - } + $sContainer->uTemplateId = $sTemplate->sId; + $sContainer->InsertIntoDatabase(); + $sContainer->Reinstall(); + $sContainer->Start(); + + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Reinstallation succeeded!", "Your VPS was successfully reinstalled."); + $sPageContents .= $err->Render(); + } + catch (ContainerReinstallException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation failed", "Something went wrong during the reinstallation of your VPS. Please try again. If the reinstallation fails again, please contact support."); + $sPageContents .= $err->Render(); } - else + catch (ContainerStartException $e) { - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "You can not reinstall this VPS, because it is suspended. If you believe this is in error, please contact support."); + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_WARNING, "Failed to start", "The VPS was successfully reinstalled, but it could not be started. If the issue persists, please contact support."); $sPageContents .= $err->Render(); } } else { - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "You did not tick the checkbox at the bottom of the page. Please carefully read the warning, tick the checkbox, and try again."); + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "You can not reinstall this VPS, because it is suspended. If you believe this is in error, please contact support."); $sPageContents .= $err->Render(); } } else { - $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "The template you selected is not available. Please select a different template."); + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "You did not tick the checkbox at the bottom of the page. Please carefully read the warning, tick the checkbox, and try again."); $sPageContents .= $err->Render(); } } @@ -73,6 +66,11 @@ if(isset($_POST['submit'])) $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "The template you selected does not exist (anymore). Please select a different template."); $sPageContents .= $err->Render(); } + catch (TemplateUnavailableException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Reinstallation aborted", "The template you selected is not available. Please select a different template."); + $sPageContents .= $err->Render(); + } } else {