Scalr\Upgrade\Updates\Update20151009141048::run1 PHP Method

run1() protected method

protected run1 ( $stage )
    protected function run1($stage)
    {
        $envIds = $this->db->Execute("SELECT `id` FROM `client_environments`");
        $platformVariables = static::getCloudsCredentialProperties();
        foreach ($envIds as $row) {
            $environment = \Scalr_Environment::init()->loadById($row['id']);
            $platforms = [];
            foreach (array_keys(SERVER_PLATFORMS::getList()) as $platform) {
                if ($environment->getPlatformConfigValue($platform . '.is_enabled', false)) {
                    $platforms[] = $platform;
                }
            }
            foreach ($platforms as $platform) {
                try {
                    switch ($platform) {
                        default:
                            $cloudCredentials = new Entity\CloudCredentials();
                            $cloudCredentials->accountId = $environment->getAccountId();
                            $cloudCredentials->envId = $environment->id;
                            $cloudCredentials->cloud = $platform;
                            $cloudCredentials->name = "{$environment->id}-{$environment->getAccountId()}-{$platform}-" . \Scalr::GenerateUID(true);
                            $cloudCredentials->status = Entity\CloudCredentials::STATUS_ENABLED;
                            foreach ($platformVariables[$platform] as $name => $newName) {
                                $value = $environment->getPlatformConfigValue($name);
                                if ($value === null) {
                                    $value = false;
                                }
                                $cloudCredentials->properties[$newName] = $value;
                            }
                            $cloudCredentials->save();
                            $cloudCredentials->bindToEnvironment($environment);
                            break;
                    }
                } catch (Exception $e) {
                    $this->console->error(get_class($e) . " in {$e->getFile()} on line {$e->getLine()}: " . $e->getMessage());
                    error_log(get_class($e) . " in {$e->getFile()} at line {$e->getLine()}: {$e->getMessage()}\n{$e->getTraceAsString()}");
                }
            }
        }
    }