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 {
$instanceTypeEntity = $platforms[$row["platform"]]->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
/* @var $instanceTypeEntity CloudInstanceType */
if ($instanceTypeEntity && (int) $instanceTypeEntity->vcpus > 0) {
$this->db->Execute("\n INSERT IGNORE INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $instanceTypeEntity->vcpus]);
}
} catch (\Exception $e) {
$this->console->warning("Can't get access to %s, error: %s", $row["platform"], $e->getMessage());
}
}
}
}
}