Scalr\Model\Entity\Script::fork PHP Method

fork() public method

Forks specified script into new script
public fork ( string $name, Scalr_Account_Use\Scalr_Account_User $user, integer $envId = null ) : Script
$name string New script name
$user Scalr_Account_Use\Scalr_Account_User User performs a fork
$envId integer Environment of the new script
return Script Forked script
    public function fork($name, Scalr_Account_User $user, $envId = null)
    {
        $script = new static();
        $script->name = $name;
        $script->description = $this->description;
        $script->os = $this->os;
        $script->isSync = $this->isSync;
        $script->allowScriptParameters = $this->allowScriptParameters;
        $script->timeout = $this->timeout;
        $script->accountId = $user->getAccountId() ?: NULL;
        $script->envId = $envId ? $envId : $this->envId;
        $script->createdById = $user->getId();
        $script->createdByEmail = $user->getEmail();
        $script->save();
        $version = new ScriptVersion();
        $version->scriptId = $script->id;
        $version->changedById = $user->getId();
        $version->changedByEmail = $user->getEmail();
        $version->content = $this->getLatestVersion()->content;
        $version->version = 1;
        $version->save();
        return $script;
    }