public function xRemoveVersionAction($scriptId, $version)
{
$this->request->restrictAccess('SCRIPTS', 'MANAGE');
/* @var $script Script */
$script = Script::findPk($scriptId);
if (!$script) {
throw new Scalr_UI_Exception_NotFound();
}
$script->checkPermission($this->user, $this->getEnvironmentId(true));
if (!$script->accountId && $this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
throw new Scalr_Exception_InsufficientPermissions();
}
if ($script->getVersions()->count() == 1) {
throw new Exception('You can\'t delete the last version.');
}
$version = $script->getVersion($version);
if (!$version) {
throw new Scalr_UI_Exception_NotFound();
}
$version->delete();
$script->getVersions(true);
// reset cache
$this->response->success();
$this->response->data(['script' => $this->getScriptInfo($script)]);
}