Scalr_UI_Controller_Images::xSaveAction PHP Méthode

xSaveAction() public méthode

public xSaveAction ( string $imageId, string $platform, string $osId, string $name, string $cloudLocation = '', string $architecture = '', integer $size = null, string $ec2Type = null, boolean $ec2Hvm = null, JsonData $software = null, boolean $isScalarized, boolean $hasCloudInit )
$imageId string
$platform string
$osId string
$name string
$cloudLocation string
$architecture string
$size integer
$ec2Type string
$ec2Hvm boolean
$software Scalr\UI\Request\JsonData
$isScalarized boolean
$hasCloudInit boolean
    public function xSaveAction($imageId, $platform, $osId, $name, $cloudLocation = '', $architecture = '', $size = null, $ec2Type = null, $ec2Hvm = null, JsonData $software = null, $isScalarized = 0, $hasCloudInit = 0)
    {
        $this->request->restrictAccess('IMAGES', 'MANAGE');
        if ($platform == SERVER_PLATFORMS::GCE || $platform == SERVER_PLATFORMS::AZURE) {
            $cloudLocation = '';
        }
        if ($accountId = $this->user->getAccountId()) {
            if ($envId = $this->getEnvironmentId(true)) {
                if (Image::findOne([['id' => $imageId], ['envId' => $envId], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
                    throw new Scalr_Exception_Core('This Image has already been registered in the Environment Scope.');
                }
            }
            if (Image::findOne([['id' => $imageId], ['accountId' => $this->user->getAccountId()], ['envId' => null], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
                throw new Scalr_Exception_Core('This Image has already been registered in the Account Scope.');
            }
        }
        if (Image::findOne([['id' => $imageId], ['accountId' => null], ['platform' => $platform], ['cloudLocation' => $cloudLocation]])) {
            $this->response->failure('This Image has already been registered in the Scalr Scope.');
            return;
        }
        if (!Role::isValidName($name)) {
            $this->response->failure('Name should start and end with letter or number and contain only letters, numbers and dashes.');
            return;
        }
        $image = new Image();
        $image->accountId = $this->user->getAccountId() ?: null;
        $image->envId = $this->getEnvironmentId(true);
        $image->id = $imageId;
        $image->platform = $platform;
        $image->cloudLocation = $cloudLocation;
        $image->architecture = 'x86_64';
        $image->isScalarized = $isScalarized ? 1 : 0;
        $image->hasCloudInit = $hasCloudInit ? 1 : 0;
        if ($this->request->getScope() == ScopeInterface::SCOPE_ENVIRONMENT) {
            if ($image->checkImage() === false) {
                $this->response->failure("This Image does not exist, or isn't usable by your account");
                return;
            }
        } else {
            $image->architecture = $architecture;
            $image->size = $size;
            if ($platform == SERVER_PLATFORMS::EC2) {
                if ($ec2Type == 'ebs' || $ec2Type == 'instance-store') {
                    $image->type = $ec2Type;
                    if ($ec2Hvm) {
                        $image->type = $image->type . '-hvm';
                    }
                }
            }
        }
        $image->name = $name;
        $image->source = Image::SOURCE_MANUAL;
        $image->osId = $osId;
        $image->createdById = $this->user->getId();
        $image->createdByEmail = $this->user->getEmail();
        $image->status = Image::STATUS_ACTIVE;
        $image->save();
        $props = [];
        foreach ($software as $value) {
            $props[$value] = null;
        }
        $image->setSoftware($props);
        $this->response->data(['hash' => $image->hash]);
        $this->response->success('Image has been added');
    }