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


PHP DBFarm::setProject方法代码示例

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


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

示例1: FarmCreate

 public function FarmCreate($Name, $Description = "", $ProjectID = "")
 {
     $this->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE);
     $ProjectID = strtolower($ProjectID);
     $response = $this->CreateInitialResponse();
     $Name = $this->stripValue($Name);
     $Description = $this->stripValue($Description);
     if (!$Name || strlen($Name) < 5) {
         throw new Exception('Name should be at least 5 characters');
     }
     $dbFarm = new DBFarm();
     $dbFarm->ClientID = $this->user->getAccountId();
     $dbFarm->EnvID = $this->Environment->id;
     $dbFarm->Status = FARM_STATUS::TERMINATED;
     $dbFarm->createdByUserId = $this->user->getId();
     $dbFarm->createdByUserEmail = $this->user->getEmail();
     $dbFarm->changedByUserId = $this->user->getId();
     $dbFarm->changedTime = microtime();
     $dbFarm->Name = $Name;
     $dbFarm->RolesLaunchOrder = 0;
     $dbFarm->Comments = $Description;
     $dbFarm->save();
     //Associates cost analytics project with the farm.
     $dbFarm->setProject(!empty($ProjectID) ? $ProjectID : null);
     $governance = new Scalr_Governance($this->Environment->id);
     if ($governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE)) {
         $dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
         // for created farm
     }
     $response->FarmID = $dbFarm->ID;
     return $response;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:32,代码来源:class.ScalrAPI_2_3_0.php

示例2: xBuildAction

 public function xBuildAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'roles' => array('type' => 'json'), 'farm' => array('type' => 'json'), 'roleUpdate' => array('type' => 'int')));
     $this->request->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE);
     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);
         $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;
         }
         $dbFarm->changedByUserId = $this->user->getId();
         $dbFarm->changedTime = microtime();
         $bNew = false;
     } else {
         $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->createdByUserId = $this->user->getId();
         $dbFarm->createdByUserEmail = $this->user->getEmail();
         $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"));
     }
     if (!$bNew && $farm['owner'] && $farm['owner'] != $dbFarm->createdByUserId) {
         if ($dbFarm->createdByUserId == $this->user->getId() || $this->user->isAccountOwner()) {
             $user = (new Scalr_Account_User())->loadById($farm['owner']);
             $dbFarm->createdByUserId = $user->getId();
             $dbFarm->createdByUserEmail = $user->getEmail();
             // TODO: move to subclass \Farm\Setting\OwnerHistory
             $history = unserialize($dbFarm->GetSetting(DBFarm::SETTING_OWNER_HISTORY));
             if (!is_array($history)) {
                 $history = [];
             }
             $history[] = ['newId' => $user->getId(), 'newEmail' => $user->getEmail(), 'changedById' => $this->user->getId(), 'changedByEmail' => $this->user->getEmail(), 'dt' => date('Y-m-d H:i:s')];
             $dbFarm->SetSetting(DBFarm::SETTING_OWNER_HISTORY, serialize($history));
         }
     }
     $dbFarm->save();
     $governance = new Scalr_Governance($this->getEnvironmentId());
     if (!$this->getParam('farmId') && $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE)) {
         $dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
         // for created farm
     }
     if (isset($farm['variables'])) {
         $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
         $variables->setValues(is_array($farm['variables']) ? $farm['variables'] : [], 0, $dbFarm->ID, 0, '', false, true);
     }
     if (!$farm['timezone']) {
         $farm['timezone'] = date_default_timezone_get();
     }
     $dbFarm->SetSetting(DBFarm::SETTING_TIMEZONE, $farm['timezone']);
     $dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_ID, $farm['vpc_id']);
     $dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_REGION, $farm['vpc_region']);
     if (!$dbFarm->GetSetting(DBFarm::SETTING_CRYPTO_KEY)) {
         $dbFarm->SetSetting(DBFarm::SETTING_CRYPTO_KEY, Scalr::GenerateRandomKey(40));
     }
     if ($this->getContainer()->analytics->enabled) {
         if ($this->request->isInterfaceBetaOrNotHostedScalr()) {
             //Cost analytics project must be set for the Farm object
             $dbFarm->setProject(!empty($farm['projectId']) ? $farm['projectId'] : null, $this->request->isInterfaceBetaOrNotHostedScalr());
         } else {
             if (isset($bNew)) {
                 //Default project is set for hosted scalr accounts. Users cannot manage it.
                 $farm['projectId'] = $dbFarm->setProject(null);
             }
         }
     }
     $virtualFarmRoles = array();
     $roles = $this->getParam('roles');
//.........这里部分代码省略.........
开发者ID:rickb838,项目名称:scalr,代码行数:101,代码来源:Builder.php

示例3: FarmCreate

 public function FarmCreate($Name, $Description = "", $ProjectID = "", array $Configuration = array())
 {
     $this->restrictFarmAccess(null, Acl::PERM_FARMS_MANAGE);
     $governance = new Scalr_Governance($this->Environment->id);
     $ProjectID = strtolower($ProjectID);
     $response = $this->CreateInitialResponse();
     $Name = $this->stripValue($Name);
     $Description = $this->stripValue($Description);
     if (!$Name || strlen($Name) < 5) {
         throw new Exception('Name should be at least 5 characters');
     }
     if ($Configuration['vpc_region'] && !$Configuration['vpc_id']) {
         throw new Exception("VPC ID is required if VPC region was specified");
     }
     if (!$Configuration['vpc_region'] && $Configuration['vpc_id']) {
         throw new Exception("VPC Region is required if VPC ID was specified");
     }
     // VPC Governance validation
     $vpcGovernance = $governance->getValue('ec2', 'aws.vpc');
     if ($vpcGovernance) {
         $vpcGovernanceRegions = $governance->getValue('ec2', 'aws.vpc', 'regions');
         if (!$Configuration['vpc_region']) {
             throw new Exception("VPC configuration is required according to governance settings");
         }
         if (!in_array($Configuration['vpc_region'], array_keys($vpcGovernanceRegions))) {
             throw new Exception(sprintf("Only %s region(s) allowed according to governance settings", implode(', ', array_keys($vpcGovernanceRegions))));
         }
         if (!in_array($Configuration['vpc_id'], $vpcGovernanceRegions[$Configuration['vpc_region']]['ids'])) {
             throw new Exception(sprintf("Only %s VPC(s) allowed according to governance settings", implode(', ', $vpcGovernanceRegions[$Configuration['vpc_region']]['ids'])));
         }
     }
     $dbFarm = new DBFarm();
     $dbFarm->ClientID = $this->user->getAccountId();
     $dbFarm->EnvID = $this->Environment->id;
     $dbFarm->Status = FARM_STATUS::TERMINATED;
     $dbFarm->createdByUserId = $this->user->getId();
     $dbFarm->createdByUserEmail = $this->user->getEmail();
     $dbFarm->changedByUserId = $this->user->getId();
     $dbFarm->changedTime = microtime();
     $dbFarm->Name = $Name;
     $dbFarm->RolesLaunchOrder = 0;
     $dbFarm->Comments = $Description;
     $dbFarm->save();
     //Associates cost analytics project with the farm.
     $dbFarm->setProject(!empty($ProjectID) ? $ProjectID : null);
     if ($governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE)) {
         $dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
         // for created farm
     }
     if (!$Configuration['timezone']) {
         $Configuration['timezone'] = date_default_timezone_get();
     }
     $dbFarm->SetSetting(DBFarm::SETTING_TIMEZONE, $Configuration['timezone']);
     if ($Configuration['vpc_region']) {
         $dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_ID, $Configuration['vpc_id']);
         $dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_REGION, $Configuration['vpc_region']);
     }
     $response->FarmID = $dbFarm->ID;
     return $response;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:60,代码来源:class.ScalrAPI_2_3_0.php

示例4: xBuildAction


//.........这里部分代码省略.........
     $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());
     if (!$this->getParam('farmId') && $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE)) {
         $dbFarm->SetSetting(Entity\FarmSetting::LEASE_STATUS, 'Active');
         // for created farm
     }
     if (isset($farm['variables'])) {
         $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARM);
         $variables->setValues(is_array($farm['variables']) ? $farm['variables'] : [], 0, $dbFarm->ID, 0, '', false, true);
     }
     if (!$farm['timezone']) {
         $farm['timezone'] = date_default_timezone_get();
     }
     $dbFarm->SetSetting(Entity\FarmSetting::TIMEZONE, $farm['timezone']);
     $dbFarm->SetSetting(Entity\FarmSetting::EC2_VPC_ID, isset($farm["vpc_id"]) ? $farm['vpc_id'] : null);
     $dbFarm->SetSetting(Entity\FarmSetting::EC2_VPC_REGION, isset($farm["vpc_id"]) ? $farm['vpc_region'] : null);
     $dbFarm->SetSetting(Entity\FarmSetting::SZR_UPD_REPOSITORY, $farm[Entity\FarmSetting::SZR_UPD_REPOSITORY]);
     $dbFarm->SetSetting(Entity\FarmSetting::SZR_UPD_SCHEDULE, $farm[Entity\FarmSetting::SZR_UPD_SCHEDULE]);
     if (!$dbFarm->GetSetting(Entity\FarmSetting::CRYPTO_KEY)) {
         $dbFarm->SetSetting(Entity\FarmSetting::CRYPTO_KEY, Scalr::GenerateRandomKey(40));
     }
     if ($this->getContainer()->analytics->enabled) {
         //Cost analytics project must be set for the Farm object
         $dbFarm->setProject(!empty($farm['projectId']) ? $farm['projectId'] : null);
     }
     $virtualFarmRoles = array();
     $roles = $this->getParam('roles');
     if (!empty($roles)) {
         foreach ($roles as $role) {
             if (strpos($role['farm_role_id'], "virtual_") !== false) {
                 $dbRole = DBRole::loadById($role['role_id']);
                 $dbFarmRole = $dbFarm->AddRole($dbRole, $role['platform'], $role['cloud_location'], (int) $role['launch_index'], $role['alias']);
                 $virtualFarmRoles[$role['farm_role_id']] = $dbFarmRole->ID;
             }
         }
     }
     $usedPlatforms = array();
     $farmRoleVariables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARMROLE);
     if (!empty($roles)) {
         foreach ($roles as $role) {
             if ($role['farm_role_id']) {
                 if (isset($virtualFarmRoles[$role['farm_role_id']])) {
                     $role['farm_role_id'] = $virtualFarmRoles[$role['farm_role_id']];
                 }
                 $update = true;
                 $dbFarmRole = DBFarmRole::LoadByID($role['farm_role_id']);
                 $dbRole = DBRole::loadById($dbFarmRole->RoleID);
                 $role['role_id'] = $dbFarmRole->RoleID;
                 if ($dbFarmRole->Platform == SERVER_PLATFORMS::GCE) {
                     $dbFarmRole->CloudLocation = $role['cloud_location'];
                 }
             } else {
                 /** TODO:  Remove because will be handled with virtual_ **/
                 $update = false;
                 $dbRole = DBRole::loadById($role['role_id']);
                 $dbFarmRole = $dbFarm->AddRole($dbRole, $role['platform'], $role['cloud_location'], (int) $role['launch_index']);
开发者ID:scalr,项目名称:scalr,代码行数:67,代码来源:Builder.php


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