Scalr\Model\Entity\Server::getHistory PHP Method

getHistory() public method

Gets server history entity
public getHistory ( ) : Scalr\Model\Entity\Server\History
return Scalr\Model\Entity\Server\History Returns server history entity
    public function getHistory()
    {
        $bSave = false;
        $mapping = ['envId' => 'envId', 'farmId' => 'farmId', 'farmRoleId' => 'farmRoleId', 'serverIndex' => 'index', 'cloudLocation' => 'cloudLocation'];
        if (!isset($this->_serverHistory)) {
            $entity = Entity\Server\History::findPk($this->serverId);
            if (!$entity) {
                $this->_serverHistory = new Entity\Server\History();
                $this->_serverHistory->clientId = $this->accountId;
                $this->_serverHistory->serverId = $this->serverId;
                $this->_serverHistory->platform = $this->platform;
                $this->_serverHistory->cloudLocation = $this->cloudLocation;
                $this->_serverHistory->instanceTypeName = $this->instanceTypeName;
                $this->_serverHistory->roleId = $this->properties[Entity\Server::ROLE_ID];
                $this->_serverHistory->farmCreatedById = $this->properties[Entity\Server::FARM_CREATED_BY_ID];
                $this->_serverHistory->osType = $this->os;
                $this->_serverHistory->type = $this->type;
                $bSave = true;
            } else {
                $this->_serverHistory = $entity;
            }
            if (Scalr::getContainer()->analytics->enabled) {
                $this->_serverHistory->projectId = $this->properties[Entity\Server::FARM_PROJECT_ID];
                $this->_serverHistory->ccId = $this->properties[Entity\Server::ENV_CC_ID];
                $bSave = true;
            }
        }
        foreach ($mapping as $prop => $key) {
            if ($this->_serverHistory->{$prop} != $this->{$key}) {
                $this->_serverHistory->{$prop} = $this->{$key};
                $bSave = true;
            }
        }
        if (!empty($bSave)) {
            $this->_serverHistory->save();
        }
        return $this->_serverHistory;
    }