当前位置: 首页>>代码示例>>PHP>>正文


PHP DBFarm::__getNewFarmObject方法代码示例

本文整理汇总了PHP中DBFarm::__getNewFarmObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarm::__getNewFarmObject方法的具体用法?PHP DBFarm::__getNewFarmObject怎么用?PHP DBFarm::__getNewFarmObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBFarm的用法示例。


在下文中一共展示了DBFarm::__getNewFarmObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xReplaceRoleAction

 public function xReplaceRoleAction()
 {
     if (!$this->request->getParam('roleId')) {
         throw new Exception("Please select role");
     }
     $dbFarmRole = DBFarmRole::LoadByID($this->getParam(self::CALL_PARAM_NAME));
     $this->user->getPermissions()->validate($dbFarmRole);
     $this->request->checkPermissions($this->dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_UPDATE);
     $newRole = DBRole::loadById($this->request->getParam('roleId'));
     $this->request->checkPermissions($newRole->__getNewRoleObject());
     if (!empty($envs = $newRole->__getNewRoleObject()->getAllowedEnvironments())) {
         if (!in_array($this->getEnvironmentId(), $envs)) {
             throw new Exception("You don't have access to this role");
         }
     }
     //TODO: Add validation of cloud/location/os_family and behavior
     $oldName = $dbFarmRole->GetRoleObject()->name;
     $dbFarmRole->RoleID = $newRole->id;
     $dbFarmRole->Save();
     \Scalr::getContainer()->logger(LOG_CATEGORY::FARM)->warn(new FarmLogMessage(!empty($dbFarmRole->FarmID) ? $dbFarmRole->FarmID : null, sprintf("Role '%s' was upgraded to role '%s'", $oldName, !empty($newRole->name) ? $newRole->name : null)));
     $image = $newRole->__getNewRoleObject()->getImage($dbFarmRole->Platform, $dbFarmRole->CloudLocation)->getImage();
     $this->response->success("Role successfully replaced.");
     $this->response->data(array('role' => array('role_id' => $newRole->id, 'name' => $newRole->name, 'os' => $newRole->getOs()->name, 'osId' => $newRole->getOs()->id, 'generation' => $newRole->generation, 'image' => ['id' => $image->id, 'type' => $image->type, 'architecture' => $image->architecture], 'behaviors' => join(",", $newRole->getBehaviors()))));
 }
开发者ID:scalr,项目名称:scalr,代码行数:24,代码来源:Roles.php

示例2: hasAccessFarm

 /**
  * Checks whether current dbFarm object can be accessed by user
  *
  * @param    \DBFarm               $dbFarm   DbFarm object
  * @param    string                $perm
  * @throws   Scalr_Exception_Core
  * @return   boolean         Returns true if access is granted
  */
 public function hasAccessFarm($dbFarm, $perm = null)
 {
     //It may not be provided in several cases
     if (!$dbFarm instanceof \DBFarm) {
         return true;
     }
     if (!$this->hasAccessEnvironment($dbFarm->EnvID)) {
         return false;
     }
     $superposition = $this->user->getAclRolesByEnvironment($this->envId);
     $result = $superposition->isAllowed(Acl::RESOURCE_FARMS, $perm);
     if (!$result && $dbFarm->__getNewFarmObject()->hasUserTeamOwnership($this->user)) {
         $result = $superposition->isAllowed(Acl::RESOURCE_TEAM_FARMS, $perm);
     }
     if (!$result && $dbFarm->ownerId && $this->user->id == $dbFarm->ownerId) {
         $result = $superposition->isAllowed(Acl::RESOURCE_OWN_FARMS, $perm);
     }
     return $result;
 }
开发者ID:scalr,项目名称:scalr,代码行数:27,代码来源:Permissions.php

示例3: xBuildAction

 public function xBuildAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'roles' => array('type' => 'json'), 'rolesToRemove' => array('type' => 'json'), 'farm' => array('type' => 'json'), 'launch' => array('type' => 'bool')));
     if (!$this->isFarmConfigurationValid($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'))) {
         if ($this->errors['error_count'] != 0) {
             $this->response->failure();
             $this->response->data(array('errors' => $this->errors));
             return;
         }
     }
     $farm = $this->getParam('farm');
     $client = Client::Load($this->user->getAccountId());
     if ($this->getParam('farmId')) {
         $dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
         $this->user->getPermissions()->validate($dbFarm);
         $this->request->checkPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_UPDATE);
         $dbFarm->isLocked();
         if ($this->getParam('changed') && $dbFarm->changedTime && $this->getParam('changed') != $dbFarm->changedTime) {
             $userName = 'Someone';
             $changed = explode(' ', $this->getParam('changed'));
             $changedTime = intval($changed[1]);
             try {
                 $user = new Scalr_Account_User();
                 $user->loadById($dbFarm->changedByUserId);
                 $userName = $user->getEmail();
             } catch (Exception $e) {
             }
             $this->response->failure();
             $this->response->data(array('changedFailure' => sprintf('%s changed this farm at %s', $userName, Scalr_Util_DateTime::convertTz($changedTime))));
             return;
         } else {
             if ($this->getParam('changed')) {
                 $this->checkFarmConfigurationIntegrity($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'), (array) $this->getParam('rolesToRemove'));
             }
         }
         $dbFarm->changedByUserId = $this->user->getId();
         $dbFarm->changedTime = microtime();
         if ($this->getContainer()->analytics->enabled) {
             $projectId = $farm['projectId'];
             if (empty($projectId)) {
                 $ccId = $dbFarm->GetEnvironmentObject()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
                 if (!empty($ccId)) {
                     //Assigns Project automatically only if it is the one withing the Cost Center
                     $projects = ProjectEntity::findByCcId($ccId);
                     if (count($projects) == 1) {
                         $projectId = $projects->getArrayCopy()[0]->projectId;
                     }
                 }
             }
             if (!empty($projectId) && $dbFarm->GetSetting(Entity\FarmSetting::PROJECT_ID) != $projectId) {
                 $this->request->checkPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_PROJECTS);
             }
         }
         $bNew = false;
     } else {
         $this->request->restrictAccess(Acl::RESOURCE_OWN_FARMS, Acl::PERM_FARMS_CREATE);
         $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_FARMS, 1);
         $dbFarm = new DBFarm();
         $dbFarm->ClientID = $this->user->getAccountId();
         $dbFarm->EnvID = $this->getEnvironmentId();
         $dbFarm->Status = FARM_STATUS::TERMINATED;
         $dbFarm->ownerId = $this->user->getId();
         $dbFarm->changedByUserId = $this->user->getId();
         $dbFarm->changedTime = microtime();
         $bNew = true;
     }
     if ($this->getParam('farm')) {
         $dbFarm->Name = $this->request->stripValue($farm['name']);
         $dbFarm->RolesLaunchOrder = $farm['rolesLaunchOrder'];
         $dbFarm->Comments = $this->request->stripValue($farm['description']);
     }
     if (empty($dbFarm->Name)) {
         throw new Exception(_("Farm name required"));
     }
     $setFarmTeams = false;
     if ($bNew) {
         $setFarmTeams = true;
     } else {
         if ($dbFarm->ownerId == $this->user->getId() || $this->request->hasPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_CHANGE_OWNERSHIP)) {
             if (is_numeric($farm['owner']) && $farm['owner'] != $dbFarm->ownerId) {
                 $dbFarm->ownerId = $farm['owner'];
                 $f = Entity\Farm::findPk($dbFarm->ID);
                 Entity\FarmSetting::addOwnerHistory($f, User::findPk($farm['owner']), User::findPk($this->user->getId()));
                 $f->save();
             }
             $setFarmTeams = true;
         }
     }
     $dbFarm->save();
     if ($setFarmTeams && is_array($farm['teamOwner'])) {
         /* @var $f Entity\Farm */
         $f = Entity\Farm::findPk($dbFarm->ID);
         $f->setTeams(empty($farm['teamOwner']) ? [] : Entity\Account\Team::find([['name' => ['$in' => $farm['teamOwner']]], ['accountId' => $this->getUser()->accountId]]));
         $f->save();
     }
     if ($bNew) {
         $dbFarm->SetSetting(Entity\FarmSetting::CREATED_BY_ID, $this->user->getId());
         $dbFarm->SetSetting(Entity\FarmSetting::CREATED_BY_EMAIL, $this->user->getEmail());
     }
     $governance = new Scalr_Governance($this->getEnvironmentId());
//.........这里部分代码省略.........
开发者ID:scalr,项目名称:scalr,代码行数:101,代码来源:Builder.php


注:本文中的DBFarm::__getNewFarmObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。