/** * Prepares statement and params */ private function prepareStatement() { $this->stmt = $this->db->Prepare("\n SELECT\n `s`.`server_id` AS `server_id`,\n `s`.`status` AS `status`\n FROM `servers` AS `s`\n LEFT JOIN `server_properties` AS `attempt`\n ON `attempt`.`server_id` = `s`.`server_id` AND `attempt`.`name` = ?\n LEFT JOIN `server_properties` AS `last_try`\n ON `last_try`.`server_id` = `s`.`server_id` AND `last_try`.`name` = ?\n LEFT JOIN `temporary_server_status_check_config` AS `config`\n ON IF(`attempt`.`value` > ?, ?, `attempt`.`value`) = `config`.`attempt`\n JOIN `clients` AS `c`\n ON `c`.`id` = `client_id`\n JOIN `client_environments` AS `e`\n ON `e`.`id` = `env_id`\n WHERE\n `s`.`status` IN (?, ?) AND `s`.`dtadded` < NOW() - INTERVAL 1 DAY OR (\n `s`.`status` = ? AND\n `c`.`status` = ? AND\n `e`.`status` = ? AND (\n `attempt`.`value` IS NULL OR\n `last_try`.`value` < NOW() - INTERVAL `config`.`interval` DAY_SECOND\n )\n )\n "); $maxAttempts = max(array_keys($this->attemptConfig)); $this->params = [SERVER_PROPERTIES::LAUNCH_ATTEMPT, SERVER_PROPERTIES::LAUNCH_LAST_TRY, $maxAttempts, $maxAttempts, SERVER_STATUS::IMPORTING, SERVER_STATUS::TEMPORARY, SERVER_STATUS::PENDING_LAUNCH, Scalr_Account::STATUS_ACTIVE, Scalr_Environment::STATUS_ACTIVE]; }
/** * {@inheritdoc} * @see UpdateInterface::hasTableCompatibleIndex() */ public function hasTableCompatibleIndex($table, array $columns, $unique = false) { $compatible = null; //Columns may be provided without indexes like ['col1', 'col2', ..., 'colN']. //In this case index should mutually start from 1 instead of specified 0. $dx = isset($columns[0]) ? 1 : 0; $stmt = $this->db->Prepare("SHOW INDEX FROM `{$table}` WHERE `Column_name` = ? AND `Seq_in_index` = ? AND `Non_unique` = ?"); foreach ($columns as $idx => $column) { $entries = $this->db->Execute($stmt, [$column, $idx + $dx, $unique ? 0 : 1]); $indexes = []; foreach ($entries->GetAll() as $entry) { $indexes[] = $entry['Key_name']; } $compatible = empty($compatible) ? $indexes : array_intersect($compatible, $indexes); if (empty($compatible)) { return false; } } return empty($compatible) ? false : $compatible; }