public function enqueue()
{
$queue = new ArrayObject([]);
$db = \Scalr::getDb();
$replicaCloudPlatforms = $this->getReplicaTypes('type', '[\\w]+');
$replicaAccounts = $this->getReplicaAccounts();
$rs = $db->Execute("\n SELECT f.id, f.clientid AS account_id, s.platform\n FROM farms f\n JOIN clients c ON c.id = f.clientid\n JOIN client_environments ce ON ce.id = f.env_id\n JOIN servers s ON s.farm_id = f.id\n LEFT JOIN client_environment_properties cep ON cep.env_id = f.env_id AND cep.name = CONCAT_WS('.', s.platform, ?)\n WHERE c.status = ? AND ce.status = ? AND (cep.value IS NULL OR cep.value = 0)\n GROUP BY f.id, s.platform\n ", [CloudPlatformSuspensionInfo::NAME_SUSPENDED, Scalr_Account::STATUS_ACTIVE, Scalr_Environment::STATUS_ACTIVE]);
while ($row = $rs->FetchRow()) {
$obj = new stdClass();
$obj->farmId = $row['id'];
$obj->platform = $row['platform'];
//Adjusts object with custom routing address.
//It determines which of the workers pool should handle the task.
$obj->address = $this->name . '.' . (!empty($replicaCloudPlatforms) ? in_array($row['platform'], $replicaCloudPlatforms) ? $row['platform'] : 'all' : 'all') . '.' . (!empty($replicaAccounts) ? in_array($row['account_id'], $replicaAccounts) ? $row['account_id'] : 'all' : 'all');
$queue->append($obj);
}
if ($cnt = count($queue)) {
$this->getLogger()->info("%d farm%s found.", $cnt, $cnt == 1 ? '' : 's');
}
return $queue;
}