Scalr\Api\Service\User\V1beta0\Adapter\FarmAdapter::_vpc PHP Method

_vpc() public method

public _vpc ( $from, $to, $action )
    public function _vpc($from, $to, $action)
    {
        switch ($action) {
            case static::ACT_CONVERT_TO_OBJECT:
                /* @var $from Farm */
                $vpc = [];
                if (!empty($from->settings[FarmSetting::EC2_VPC_ID])) {
                    $vpc['id'] = $from->settings[FarmSetting::EC2_VPC_ID];
                }
                if (!empty($from->settings[FarmSetting::EC2_VPC_REGION])) {
                    $vpc['region'] = $from->settings[FarmSetting::EC2_VPC_REGION];
                }
                if (!empty($vpc)) {
                    $to->vpc = (object) $vpc;
                }
                break;
            case static::ACT_CONVERT_TO_ENTITY:
                /* @var $to Farm */
                $vpcId = ApiController::getBareId($from, 'vpc');
                if (!is_string($vpcId)) {
                    throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed vpc.id property");
                }
                if ($to->status || FarmRole::find([['farmId' => $to->id], ['platform' => \SERVER_PLATFORMS::EC2]], null, null, null, null, true)->totalNumber) {
                    throw new ApiErrorException(400, ErrorMessage::ERR_OBJECT_IN_USE, "To change VPC settings you must first stop farm and remove all EC2 farm-roles");
                }
                $to->settings[FarmSetting::EC2_VPC_ID] = $vpcId;
                if (!empty($from->vpc->region)) {
                    $to->settings[FarmSetting::EC2_VPC_REGION] = $from->vpc->region;
                }
                break;
            case static::ACT_GET_FILTER_CRITERIA:
                $farm = new Farm();
                $farmSetting = new FarmSetting();
                $vpcId = ApiController::getBareId($from, 'vpc');
                return [AbstractEntity::STMT_FROM => "\n                        JOIN  {$farmSetting->table('fsv')}  ON  {$farmSetting->columnFarmId('fsv')}  = {$farm->columnId()}\n                            AND  {$farmSetting->columnName('fsv')}  = " . $farmSetting->qstr('name', FarmSetting::EC2_VPC_ID) . "\n                    ", AbstractEntity::STMT_WHERE => "{$farmSetting->columnValue('fsv')}  = " . $farmSetting->qstr('value', $vpcId)];
        }
    }