Scalr_UI_Controller_Scripts::xForkAction PHP Method

xForkAction() public method

public xForkAction ( integer $scriptId, string $name )
$scriptId integer
$name string
    public function xForkAction($scriptId, $name)
    {
        $this->request->restrictAccess('SCRIPTS', 'FORK');
        if (!$name) {
            throw new Scalr_Exception_Core('Name cannot be null');
        }
        /* @var $script Script */
        $script = Script::findPk($scriptId);
        if (!$script) {
            throw new Scalr_UI_Exception_NotFound();
        }
        $script->checkPermission($this->user, $this->getEnvironmentId(true));
        $criteria = [];
        $criteria[] = ['name' => $name];
        switch ($this->request->getScope()) {
            case Script::SCOPE_ENVIRONMENT:
                $criteria[] = ['envId' => $this->getEnvironmentId(true)];
                $criteria[] = ['accountId' => $this->user->getAccountId()];
                break;
            case Script::SCOPE_ACCOUNT:
                $criteria[] = ['envId' => null];
                $criteria[] = ['accountId' => $this->user->getAccountId()];
                break;
            case Script::SCOPE_SCALR:
                $criteria[] = ['envId' => null];
                $criteria[] = ['accountId' => null];
                break;
        }
        if (Script::findOne($criteria)) {
            throw new Scalr_Exception_Core('Script name must be unique within current scope');
        }
        $forkedScript = $script->fork($name, $this->user, $this->getEnvironmentId(true));
        $this->response->success('Script successfully forked');
        $this->response->data(['script' => array_merge($this->getScript($forkedScript), $this->getScriptInfo($forkedScript))]);
    }