/** * @return Image */ public function createImageEntity() { $snapshot = $this->getSnapshotDetails(); $envId = $this->envId; /* @var Entity\Server $server */ $server = Entity\Server::findOneByServerId($this->serverId); if (!empty($server->farmRoleId)) { /* @var Entity\FarmRole $farmRole */ $farmRole = Entity\FarmRole::findPk($server->farmRoleId); if (!empty($farmRole->roleId)) { /* @var Entity\Role $role */ $role = Entity\Role::findPk($farmRole->roleId); $envId = $role->getScope() == ScopeInterface::SCOPE_ACCOUNT ? NULL : $envId; } } $image = new Image(); $image->id = $this->snapshotId; $image->accountId = $this->clientId; $image->envId = $envId; $image->bundleTaskId = $this->id; $image->platform = $this->platform; $image->cloudLocation = $this->cloudLocation; $image->createdById = $this->createdById; $image->createdByEmail = $this->createdByEmail; $image->architecture = is_null($snapshot['os']->arch) ? 'x86_64' : $snapshot['os']->arch; $image->source = Image::SOURCE_BUNDLE_TASK; $image->status = Image::STATUS_ACTIVE; $image->agentVersion = $snapshot['szr_version']; $image->checkImage(); if (!$image->name) { $image->name = $this->roleName . '-' . date('YmdHi'); } $image->osId = $this->osId; $image->save(); if ($snapshot['software']) { $software = []; foreach ((array) $snapshot['software'] as $soft) { $software[$soft->name] = $soft->version; } $image->setSoftware($software); } return $image; }