Scalr\Upgrade\Updates\Update20150818090745::run2 PHP Method

run2() protected method

protected run2 ( $stage )
    protected function run2($stage)
    {
        $this->console->out("Populating new properties");
        $platforms = $envs = [];
        foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) {
            $platforms[$platform] = PlatformFactory::NewPlatform($platform);
        }
        $result = $this->db->Execute("\n                SELECT s.server_id, s.`platform`, s.`cloud_location`, s.env_id, s.`type`\n                FROM servers AS s\n                WHERE s.`status` NOT IN (?, ?) AND s.`type` IS NOT NULL\n            ", [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED]);
        while ($row = $result->FetchRow()) {
            if (!empty($row["type"])) {
                if (!array_key_exists($row["env_id"], $envs)) {
                    $envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]);
                }
                if ($this->isPlatformEnabled($envs[$row["env_id"]], $row["platform"])) {
                    try {
                        $instanceTypeInfo = $platforms[$row["platform"]]->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
                        if ($instanceTypeInfo instanceof CloudInstanceType) {
                            $vcpus = $instanceTypeInfo->vcpus;
                        } else {
                            if (isset($instanceTypeInfo['vcpus'])) {
                                $vcpus = $instanceTypeInfo['vcpus'];
                            } else {
                                trigger_error("Value of vcpus for instance type " . $row["type"] . " is missing for platform " . $row["platform"], E_USER_WARNING);
                                $vcpus = 0;
                            }
                        }
                        if ((int) $vcpus > 0) {
                            $this->db->Execute("\n                                INSERT IGNORE INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n                            ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $vcpus]);
                        }
                    } catch (\Exception $e) {
                        $this->console->warning("Can't get access to %s, error: %s", $row["platform"], $e->getMessage());
                    }
                }
            }
        }
    }