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

_owner() public method

public _owner ( $from, $to, $action )
    public function _owner($from, $to, $action)
    {
        switch ($action) {
            case static::ACT_CONVERT_TO_OBJECT:
                /* @var $from Farm */
                $to->owner = ['id' => $from->ownerId];
                break;
            case static::ACT_CONVERT_TO_ENTITY:
                /* @var $to Farm */
                $owner = ApiController::getBareId($from, 'owner');
                if (!isset($owner)) {
                    throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed owner.id property");
                }
                if (!empty($to->ownerId) && $to->ownerId != $owner) {
                    $this->controller->checkPermissions($to, Acl::PERM_FARMS_CHANGE_OWNERSHIP);
                    $user = User::findOne([['id' => $owner], ['accountId' => $this->controller->getUser()->getAccountId()]]);
                    /* @var $user User */
                    if (!$user) {
                        throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested User either does not exist or is not owned by current account");
                    }
                    $to->createdByEmail = $user->getEmail();
                    FarmSetting::addOwnerHistory($to, $user, $this->controller->getUser());
                }
                $to->ownerId = $owner;
                break;
            case static::ACT_GET_FILTER_CRITERIA:
                $owner = ApiController::getBareId($from, 'owner');
                return [['ownerId' => $owner]];
                break;
        }
    }