public function getImage($imageId, $restrictToCurrentScope = false)
{
$criteria = $this->getDefaultCriteria();
$criteria[] = ['hash' => strtolower($imageId)];
$image = Entity\Image::findOne($criteria);
/* @var $image Entity\Image */
if (!$image) {
throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Image either does not exist or is not owned by your environment.");
}
$this->checkPermissions($image);
if ($restrictToCurrentScope) {
if ($image->getScope() !== $this->getScope()) {
throw new ApiErrorException(403, ErrorMessage::ERR_SCOPE_VIOLATION, "The image is not either from the environment scope or owned by your environment.");
}
if ($image->status === Entity\Image::STATUS_DELETE) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_IMAGE_STATUS, sprintf("You can not use the image %s because it awaiting deletion on the cloud.", $image->name));
}
}
return $image;
}