/** * Deletes this script * * @throws Scalr_Exception_Core * @throws Exception * @throws ModelException */ public function delete() { // Check script usage $usage = []; $farmRolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT farm_roleid) FROM farm_role_scripts WHERE scriptid=?", array($this->id)); if ($farmRolesCount > 0) { $message = []; foreach ($this->db()->GetCol("SELECT DISTINCT farm_roleid FROM farm_role_scripts WHERE scriptid = ? LIMIT 3", array($this->id)) as $id) { $dbFarmRole = \DBFarmRole::LoadByID($id); $message[] = $dbFarmRole->GetFarmObject()->Name . ' (' . $dbFarmRole->Alias . ')'; } $usage[] = sprintf("%d farm roles: %s%s", $farmRolesCount, join(', ', $message), $farmRolesCount > 3 ? ' and others' : ''); } $rolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT role_id) FROM role_scripts WHERE script_id=?", array($this->id)); if ($rolesCount > 0) { $message = []; foreach ($this->db()->GetCol("SELECT DISTINCT role_id FROM role_scripts WHERE script_id = ? LIMIT 3", array($this->id)) as $id) { $dbRole = \DBRole::LoadByID($id); $message[] = $dbRole->name; } $usage[] = sprintf("%d roles: %s%s", $rolesCount, join(', ', $message), $rolesCount > 3 ? ' and others' : ''); } $accountCount = $this->db()->GetOne("SELECT COUNT(*) FROM account_scripts WHERE script_id=?", array($this->id)); if ($accountCount > 0) { $usage[] = sprintf("%d orchestration rule(s) on account level", $accountCount); } $taskCount = $this->db()->GetOne("SELECT COUNT(*) FROM scheduler WHERE script_id = ?", array($this->id)); if ($taskCount > 0) { $usage[] = sprintf("%d scheduler task(s)", $taskCount); } if (count($usage)) { throw new Scalr_Exception_Core(sprintf('Script "%s" being used by %s, and can\'t be deleted', $this->name, join(', ', $usage))); } Tag::deleteTags(Tag::RESOURCE_SCRIPT, $this->id); parent::delete(); }
public function GlobalVariablesList($ServerID = null, $FarmID = null, $FarmRoleID = null, $RoleID = null) { if (empty($FarmID) && empty($FarmRoleID) && empty($RoleID) && empty($ServerID)) { $this->restrictAccess(Acl::RESOURCE_ENVADMINISTRATION_GLOBAL_VARIABLES); } $response = $this->CreateInitialResponse(); $response->VariableSet = new stdClass(); $response->VariableSet->Item = array(); if ($ServerID) { $DBServer = DBServer::LoadByID($ServerID); if ($DBServer->envId != $this->Environment->id) { throw new Exception(sprintf("Server ID #%s not found", $ServerID)); } $this->user->getPermissions()->validate($DBServer); $globalVariables = new Scalr_Scripting_GlobalVariables($this->Environment->clientId, $this->Environment->id, Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE); $vars = $globalVariables->listVariables($DBServer->roleId, $DBServer->farmId, $DBServer->farmRoleId, $ServerID); } elseif ($FarmID) { $DBFarm = DBFarm::LoadByID($FarmID); if ($DBFarm->EnvID != $this->Environment->id) { throw new Exception(sprintf("Farm ID #%s not found", $FarmID)); } $this->user->getPermissions()->validate($DBFarm); $globalVariables = new Scalr_Scripting_GlobalVariables($this->Environment->clientId, $this->Environment->id, Scalr_Scripting_GlobalVariables::SCOPE_FARM); $vars = $globalVariables->listVariables(null, $DBFarm->ID, null); } elseif ($RoleID) { $DBRole = DBRole::LoadByID($RoleID); if ($DBRole->envId != $this->Environment->id) { throw new Exception(sprintf("Role ID #%s not found", $RoleID)); } $globalVariables = new Scalr_Scripting_GlobalVariables($this->Environment->clientId, $this->Environment->id, Scalr_Scripting_GlobalVariables::SCOPE_ROLE); $vars = $globalVariables->listVariables($RoleID, null, null); } elseif ($FarmRoleID) { $DBFarmRole = DBFarmRole::LoadByID($FarmRoleID); if ($DBFarmRole->GetFarmObject()->EnvID != $this->Environment->id) { throw new Exception(sprintf("FarmRole ID #%s not found", $FarmRoleID)); } $this->user->getPermissions()->validate($DBFarmRole); $globalVariables = new Scalr_Scripting_GlobalVariables($this->Environment->clientId, $this->Environment->id, Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE); $vars = $globalVariables->listVariables($DBFarmRole->RoleID, $DBFarmRole->FarmID, $DBFarmRole->ID); } else { $globalVariables = new Scalr_Scripting_GlobalVariables($this->Environment->clientId, $this->Environment->id, Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT); $vars = $globalVariables->listVariables(); } foreach ($vars as $v) { $itm = new stdClass(); $itm->{"Name"} = $v['name']; $itm->{"Value"} = $v['value']; $itm->{"Private"} = $v['private']; $response->VariableSet->Item[] = $itm; } return $response; }