Ejemplo n.º 1
0
// getOfferData gather all data for offer and return filled object to channel
func getOfferData(dbConn *db.DB, offerId int, specialsMap db.SpecialsMap, offersChan chan *xml.Offer) {
	var (
		err error
	)
	offer := db.NewOffer(dbConn, offerId)
	utils.LogErrf(offer.Get(), "Get offer (%d)", offerId)
	// contact and owner data
	personId := offer.StringAt(db.ID_WPROWADZAJACEGO)
	contactId := offer.StringAt(db.ID_WLASCICIELA)
	person := db.NewPerson(dbConn)
	utils.LogErrf(person.Get(personId), "Get person (%s) for offer (%d)", personId, offerId)
	contact := db.NewPerson(dbConn)
	utils.LogErrf(contact.Get(contactId), "Get contact (%s) for offer (%d)", personId, offerId)
	// additionals data
	add := db.NewAdditional(dbConn)
	utils.LogErrf(add.Get(offerId), "Get additional data for offer (%d)", offerId)
	//
	xmlOffer := fillOffer(offer, add, person, contact)
	sid := offer.StrId()
	var imgIds []string
	// images and specials
	images := db.NewImages(dbConn, sid)
	if imgIds, err = images.FileNames(); err != nil {
		utils.LogErrf(err, "Images ids for offer (%d)", offerId)
	}
	go getImages(imagesChan, images, workDir)
	xmlOffer.Pictures = xml.NewListElem("zdjecia", "zdjecie")
	xmlOffer.Pictures.AddMany(imgIds...)
	xmlOffer.Specials = xml.NewListElem("wyroznienia", "wyroznienie")
	xmlOffer.Specials.AddMany(specialsMap[sid]...)
	offersChan <- xmlOffer
}
Ejemplo n.º 2
0
func main() {
	var (
		err      error
		offersNo int
		types    []string
	)
	if len(settings.exports) == 0 {
		types = allExportsTypes
	} else {
		types = strings.Split(settings.exports, ",")
		for _, typ := range types {
			if _, ok := exports[typ]; !ok {
				log.Fatalf("Unsupported export name %s", typ)
			}
		}
	}
	setCredentials("db")
	startTime := time.Now()
	// validate paths, remove / create dirctory
	if err = validPaths(settings); err != nil {
		utils.LogErrf(err, "Settings paths")
	}

	if !settings.sendOnly {
		// dump to XML
		log.Printf("Start getting data from DB\n")
		offersNo, err = dumpAsXML(settings)
		utils.LogErr(err, "Dump XML")
		log.Printf("Got %d offers from DB (in %v)\n", offersNo, time.Now().Sub(startTime))
	}

	for _, name := range types {
		if err = exports[name](name, settings); err != nil {
			utils.LogErrf(err, "Error durring process %s", name)
		}
	}
	log.Printf("All done in %v\n", time.Now().Sub(startTime))
}