public static function chooseModelDBIndex() { echo CliUtil::delimiter(); echo "Choose model DB index:\n"; //$db_arr = \OLOG\ConfWrapper::value(\OLOG\Model\ModelConstants::MODULE_CONFIG_ROOT_KEY . '.db'); // TODO: check not empty $db_arr = DBConfig::getDBSettingsObjArr(); Assert::assert(count($db_arr) > 0, 'No database settings found in config'); // TODO: select db by index $db_id_by_index = []; $index = 1; foreach ($db_arr as $db_id => $db_settings_obj) { echo "\t" . str_pad($index, 8, '.') . $db_id . "\n"; $db_id_by_index[$index] = $db_id; $index++; } $model_db_index = CliUtil::readStdinAnswer(); if (!array_key_exists($model_db_index, $db_id_by_index)) { throw new \Exception('Wrong index'); } self::$model_db_id = $db_id_by_index[$model_db_index]; // TODO: check db presence in config? self::generateClass(); }
public static function executeSqlScreen() { //echo CliUtil::delimiter(); //echo "Enter database index to execute queries for or press ENTER to execute queries for all databases in config.\n"; $db_arr = DBConfig::getDBSettingsObjArr(); Assert::assert(!empty($db_arr), 'No database entries in config'); /* $db_id_by_index = []; $index = 1; foreach ($db_arr as $db_id => $db_conf) { echo "\t" . str_pad($index, 8, '.') . $db_id . "\n"; $db_id_by_index[$index] = $db_id; $index++; } */ //$command_str = CliUtil::readStdinAnswer(); //if ($command_str == '') { $db_arr = DBConfig::getDBSettingsObjArr(); foreach ($db_arr as $db_id => $db_config) { echo "Database ID in application config: " . $db_id . "\n"; self::process_db($db_id); } echo "All queries executed, press ENTER to continue\n"; $command_str = CliUtil::readStdinAnswer(); return; //} /* $model_db_index = $command_str; if (!array_key_exists($model_db_index, $db_id_by_index)) { throw new \Exception('Wrong index'); } $model_db_id = $db_id_by_index[$model_db_index]; self::process_db($model_db_id); */ }