public function getImage()
{
if (empty($this->_image) && !empty($this->roleId) && !empty($this->platform)) {
$i = new Image();
$ri = new RoleImage();
$rec = $this->db()->GetRow("\n SELECT {$i->fields()}\n FROM {$i->table()}\n LEFT JOIN {$ri->table()} ON {$i->columnPlatform} = {$ri->columnPlatform}\n AND {$i->columnCloudLocation} = {$ri->columnCloudLocation}\n AND {$i->columnId} = {$ri->columnImageId}\n WHERE {$ri->columnRoleId} = ?\n AND {$ri->columnPlatform} = ?\n AND {$ri->columnCloudLocation} = ?\n AND ({$i->columnAccountId} IS NULL OR {$i->columnAccountId} = ?\n AND ({$i->columnEnvId} IS NULL OR {$i->columnEnvId} = ?)\n )\n ", [$this->roleId, $this->platform, in_array($this->platform, [SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::AZURE]) ? '' : $this->cloudLocation, $this->getFarm()->accountId, $this->getFarm()->envId]);
if ($rec) {
$this->_image = $i;
$this->_image->load($rec);
}
}
return $this->_image;
}
/** * Check if instances are valid * * @throws ValidationErrorException */ protected function validate() { $farm = $this->farmRole->getFarm(); if ($farm->status != Entity\Farm::STATUS_RUNNING) { throw new ValidationErrorException('Farm should be in the Running state to import the Instance.'); } $role = $this->farmRole->getRole(); if ($role->isScalarized) { throw new ValidationErrorException('Only non-scalarized Roles are supported.'); } if ($this->farmRole->getImage()->id != $this->orphaned->imageId) { throw new ValidationErrorException('ID of the FarmRole Image must match ID of the Image of the Instance.'); } if ($this->farmRole->settings[Entity\FarmRoleSetting::SCALING_ENABLED] == 1) { throw new ValidationErrorException('Scaling should be set to manual before importing instance'); } }