Beispiel #1
0
func (a *Asset) confirmChecksum(coll *mgo.Collection, finished chan int) {
	defer func() { finished <- 1 }()

	fmt.Printf("Checking %s\n", a.Url)

	activeRequests <- 1
	resp, err := http.Get(a.Url)
	<-activeRequests

	if err != nil {
		fmt.Printf("Got HTTP Error for %s.  Error: %v\n", a.Url, err)
		return
	}

	newHasher := md5.New()
	io.Copy(newHasher, resp.Body)
	newHash := hex.EncodeToString(newHasher.Sum(nil))

	if newHash != a.Checksum {
		fmt.Printf("Hashes did not match: %s != %s\n", newHash, a.Checksum)
		a.Checksum = newHash
		err = coll.Update(bson.M{"_id": a.Id}, a)
		if err != nil {
			fmt.Printf("Error updating hash, got error %v\n", err)
		}
	} else {
		fmt.Printf("Hashes Matched!\n")
	}

}
Beispiel #2
0
// Update Account into Mongo
func update(u Account, s *mgo.Collection) {
	colQuerier := bson.M{"name": u.Name}
	change := bson.M{"$set": bson.M{"email": u.Email, "phone": u.Phone, "password": u.Password, "type": u.Type}}
	err := s.Update(colQuerier, change)
	if err != nil {
		panic(err)
	}
}
Beispiel #3
0
func checkSpecialActionVerbs(w http.ResponseWriter, statementsC *mgo.Collection, statement Statement) int {

	//voiding
	if statement.Verb.Id == "http://adlnet.gov/expapi/verbs/voided" {

		// check has statementId to void
		if statement.Object.ObjectType != "StatementRef" {
			// fmt.Fprint(w, "StatementRef")
			return http.StatusBadRequest
		}

		if statement.Object.Id == "" {
			// fmt.Fprint(w, "Object.Id")
			return http.StatusBadRequest
		}

		// find if statement to be voided exists
		var result Statement
		err := statementsC.Find(bson.M{"id": statement.Object.Id}).One(&result)
		if err != nil {
			// fmt.Fprint(w, "not found refrence"+statement.Object.Id)
			// fmt.Fprint(w, err)
			return http.StatusBadRequest
		}

		// if statement hasn't been voided do so
		if result.Void != true {
			err = statementsC.Update(bson.M{"id": result.Id}, bson.M{"$set": bson.M{"void": true}})
			if err != nil {
				// fmt.Fprint(w, "cant update")
				//fmt.Fprint(w, err)
				return http.StatusBadRequest
			}
		}
	} else if statement.Object.ObjectType == "StatementRef" { //check if statement's ref exists (might be moved to validate)
		if statement.Object.Id == "" {
			//fmt.Fprint(w, "Object.Id")
			return http.StatusBadRequest
		}

		// find if statement to be voided exists
		var result Statement
		err := statementsC.Find(bson.M{"id": statement.Object.Id}).One(&result)
		if err != nil {
			//fmt.Fprint(w, "not found refrence")
			return http.StatusBadRequest
		}
	}
	return 0
}
Beispiel #4
0
func savePost(collection *mgo.Collection, shortID int, title, subtitle, slugString, category, body string) (post models.Post) {
	// Update Dataz
	err := collection.Update(bson.M{"shortid": shortID}, bson.M{
		"$set": bson.M{
			"title":    title,
			"subtitle": subtitle,
			"category": category,
			"slug":     slugString,
			"body":     body,
		},
	})

	if err != nil {
		panic(err)
	}

	result := models.Post{}
	collection.Find(bson.M{"title": title}).One(&result)
	return result
}
Beispiel #5
0
func Update(col *mgo.Collection, key int, newname string) error {
	return col.Update(bson.M{keyfield: key}, bson.M{namefield: newname})
}
Beispiel #6
0
func (executor *OpsExecutor) ExecUpdate(
	content Document, coll *mgo.Collection) error {
	return coll.Update(content["query"], content["updateobj"])
}
Beispiel #7
0
func UpdateByIdAndUserId2(collection *mgo.Collection, id, userId bson.ObjectId, i interface{}) bool {
	err := collection.Update(GetIdAndUserIdBsonQ(id, userId), i)
	return Err(err)
}
Beispiel #8
0
func UpdateByIdAndUserId(collection *mgo.Collection, id, userId string, i interface{}) bool {
	err := collection.Update(GetIdAndUserIdQ(id, userId), i)
	return Err(err)
}
Beispiel #9
0
// 适合一条记录全部更新
func Update(collection *mgo.Collection, query interface{}, i interface{}) bool {
	err := collection.Update(query, i)
	return Err(err)
}