Beispiel #1
0
func importCountries(conn *transaction.Connection, config model.YAMLCountries) (err error) {
	log.Info("Import countries started")

	if err = conn.RemoveCountriesTranslations(); err != nil {
		return
	}
	for countryCode, country := range config.Countries {
		if conn.IsCountryExist(countryCode) == false {
			err = errors.New("Missing country")
			break
		}

		errorInsideTranslation := false
		for languageCode, translation := range country.Translations {
			if conn.IsLanguageExist(languageCode) == false {
				errorInsideTranslation = true
				err = errors.New("No language")
				break
			}

			if err = conn.CreateCountryTranslation(countryCode, languageCode, translation); err != nil {
				errorInsideTranslation = true
				break
			}
		}

		if errorInsideTranslation == true {
			break
		}
	}
	log.Info("Import countries finished")
	return
}
Beispiel #2
0
func importPhoneNumbersCategories(conn *transaction.Connection, config model.YAMLPhoneNumbersCategories) (err error) {
	log.Info("Import phonenumber categories started")

	if err = conn.RemovePhonenumbersAndCategories(); err != nil {
		return
	}

	for categoryCode, category := range config.Categories {
		if err = conn.CreatePhonenumberCategory(categoryCode); err != nil {
			break
		}

		errorInsideTranslation := false
		for languageCode, translation := range category.Translations {
			if conn.IsLanguageExist(languageCode) == false {
				errorInsideTranslation = true
				err = errors.New("No language")
				break
			}

			if err = conn.CreatePhonenumberCategoryTranslation(categoryCode, languageCode, translation); err != nil {
				errorInsideTranslation = true
				break
			}
		}

		if errorInsideTranslation == true {
			break
		}
	}
	log.Info("Import phonenumber categories finished")
	return
}
Beispiel #3
0
func importPhoneNumbers(conn *transaction.Connection, config model.YAMLPhoneNumbers) (err error) {
	log.Info("Import phonenumbers started")

	for countryCode, phonenumbers := range config.Phonenumbers {
		if conn.IsCountryExist(countryCode) == false {
			err = errors.New("No country")
			break
		}

		errorInsidePhonenumber := false
		for _, phonenumber := range phonenumbers {
			if err = conn.CreatePhonenumber(countryCode, phonenumber.Number); err != nil {
				errorInsidePhonenumber = true
				break
			}

			errorInsideAssignement := false
			for _, categoryCode := range phonenumber.Categories {
				if conn.IsCategoryExist(categoryCode) == false {
					err = errors.New("No category " + categoryCode)
					errorInsideAssignement = true
					break
				}

				if err = conn.AssignPhonenumberToCategory(countryCode, phonenumber.Number, categoryCode); err != nil {
					errorInsideAssignement = true
					break
				}
			}

			if errorInsideAssignement == true {
				break
			}
		}

		if errorInsidePhonenumber == true {
			break
		}
	}
	log.Info("Import phonenumbers finished")
	return
}