public function ServerImageCreate($ServerID, $RoleName) { $this->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE); $DBServer = DBServer::LoadByID($ServerID); // Validate client and server if ($DBServer->envId != $this->Environment->id) { throw new Exception(sprintf("Server ID #%s not found", $ServerID)); } $this->user->getPermissions()->validate($DBServer); //Check for already running bundle on selected instance $chk = $this->DB->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($ServerID)); if ($chk) { throw new Exception(sprintf(_("Server '%s' is already synchonizing."), $ServerID)); } //Check is role already synchronizing... $chk = $this->DB->GetOne("SELECT server_id FROM bundle_tasks WHERE prototype_role_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($DBServer->GetFarmRoleObject()->RoleID)); if ($chk && $chk != $DBServer->serverId) { try { $bDBServer = DBServer::LoadByID($chk); if ($bDBServer->farmId == $DBServer->farmId) { throw new Exception(sprintf(_("Role '%s' is already synchonizing."), $DBServer->GetFarmRoleObject()->GetRoleObject()->name)); } } catch (Exception $e) { } } try { $DBRole = DBRole::loadByFilter(array("name" => $RoleName, "env_id" => $DBServer->envId)); } catch (Exception $e) { } if (!$DBRole) { $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($DBServer, $RoleName, SERVER_REPLACEMENT_TYPE::NO_REPLACE, BundleTask::BUNDLETASK_OBJECT_ROLE, 'Bundled via API'); $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo); $BundleTask->createdById = $this->user->id; $BundleTask->createdByEmail = $this->user->getEmail(); $BundleTask->save(); $response = $this->CreateInitialResponse(); $response->BundleTaskID = $BundleTask->id; return $response; } else { throw new Exception(_("Specified role name is already used by another role")); } }
public function downgradeAction() { $dbFarmRole = DBFarmRole::LoadByID($this->getParam(self::CALL_PARAM_NAME)); $this->user->getPermissions()->validate($dbFarmRole); $dbRole = $dbFarmRole->GetRoleObject(); $history = array(); foreach ($dbRole->getRoleHistory(false) as $roleName) { $item = false; try { $hRole = DBRole::loadByFilter(array('name' => $roleName)); if ($hRole->envId != 0) { $this->user->getPermissions()->validate($hRole); } } catch (Exception $e) { $hRole = false; } if ($hRole) { $item = array('xtype' => 'radiofield', 'name' => 'roleId', 'boxLabel' => $hRole->name, 'inputValue' => $hRole->id); } elseif ($roleName) { $item = array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => $roleName . " [ <span style='color:gray;font-style:italic;'>Role was removed and no longer available</span> ]"); } if ($item) { $history[] = $item; } } $history[] = array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => "<b>" . $dbRole->name . "</b> [ Current role ]"); $this->response->page('ui/farms/roles/downgrade.js', array('history' => $history)); }