コード例 #1
0
ファイル: store.go プロジェクト: AaronO/lightwave
func (self *store) Dequeue(perma_blobref string, blobref string) (blobrefs []string, err os.Error) {
	parent := datastore.NewKey("perma", perma_blobref, 0, nil)
	key := datastore.NewKey("missing", blobref, 0, parent)
	var m missingStruct
	if err = datastore.Get(self.c, key, &m); err != nil {
		if err == datastore.ErrNoSuchEntity {
			return nil, nil
		}
	}
	err = datastore.Delete(self.c, key)
	if err != nil {
		return
	}
	for _, dep := range m.Pending {
		key := datastore.NewKey("pending", dep, 0, parent)
		var p pendingStruct
		if err = datastore.Get(self.c, key, &m); err != nil {
			if err != datastore.ErrNoSuchEntity {
				continue
			}
		}
		p.WaitingForCount--
		if p.WaitingForCount == 0 {
			blobrefs = append(blobrefs, dep)
			datastore.Delete(self.c, key)
		}
	}
	return
}
コード例 #2
0
func solve(w http.ResponseWriter, r *http.Request) {
	context := appengine.NewContext(r)

	j, err := getParamsJeu(r)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		context.Errorf("%s", err)
		return
	}

	if j.CheckJeu() == false {
		context.Errorf("Données du jeu invalide: Plaques: %d, Total: %d", j.Plaques, j.Total)
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	//Generation de la Key
	k := genStringID(j)
	//Netoyage de pending
	err = datastore.RunInTransaction(context, func(c appengine.Context) error {
		var err error
		key := datastore.NewKey(c, PENDING, k, 0, nil)
		if err = datastore.Delete(c, key); err != nil {
			return err
		}
		//Ajout dans ongoing
		key = datastore.NewKey(c, ONGOING, k, 0, nil)
		if _, err = datastore.Put(c, key, &j); err != nil {
			return err
		}

		//Résolution du compte est bon
		var sol solution
		sol.Resultats = j.Resolv()
		sol.Jeu = j

		//Netoyage de ongoing
		key = datastore.NewKey(c, ONGOING, k, 0, nil)
		if err = datastore.Delete(c, key); err != nil {
			return err
		}

		//Ajout dans finised
		key = datastore.NewKey(c, FINISHED, k, 0, nil)
		if _, err = datastore.Put(c, key, &sol); err != nil {
			return err
		}

		return err
	}, &datastore.TransactionOptions{XG: true})

	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		context.Errorf("%s", err)
		return
	}
	return
}
コード例 #3
0
ファイル: model.go プロジェクト: matryer/gae-records
// Delete deletes a single record of this type.  Returns nil if successful, otherwise
// the datastore error that was returned.
//   people := NewModel("people")
//   people.Delete(1)
//
// Raises events:
//   Model.BeforeDelete with Args(id, nil)
//   Model.AfterDelete with Args(id, nil)
// Note: The Record will not be passed to the events.
func (m *Model) Delete(id int64) os.Error {

	// trigger the BeforeDeleteByID event
	context := m.BeforeDelete.Trigger(id, nil)

	if !context.Cancel {

		err := datastore.Delete(m.AppEngineContext(), m.NewKeyWithID(id))

		if err == nil {

			// trigger the AfterDeleteByID event
			if m.AfterDelete.HasCallbacks() {
				m.AfterDelete.TriggerWithContext(context)
			}

		}

		// return the error
		return err

	}

	return ErrOperationCancelledByEventCallback

}
コード例 #4
0
ファイル: gae_main.go プロジェクト: psyvisions/bitwrk
// Finds the first matching hot bid in the list, and deletes it. Then, returns
// the corresponding "real" bid.
func findValidBid(c appengine.Context, iter *datastore.Iterator, now time.Time) (*datastore.Key, *Bid, error) {
	for {
		var hot hotBid
		key, e := iter.Next(hotBidCodec{&hot})
		if e == datastore.Done {
			break
		} else if e != nil {
			// Error case
			return nil, nil, e
		}

		if now.Before(hot.Expires) {
			if err := datastore.Delete(c, key); err != nil {
				return nil, nil, err
			}

			var bid Bid
			if err := datastore.Get(c, hot.BidKey, bidCodec{&bid}); err != nil {
				return nil, nil, err
			}
			return hot.BidKey, &bid, nil
		}
	}
	return nil, nil, nil
}
コード例 #5
0
ファイル: mutex.go プロジェクト: DaviWei/utils-1
func (self *Mutex) Unlock(c gaecontext.GAEContext) (err error) {
	if err = datastore.Delete(c, lockIdForName(c, self.Name)); err != nil {
		return
	}
	err = memcache.Del(c, lockKeyForName(self.Name))
	return
}
コード例 #6
0
ファイル: cardsetdetail.go プロジェクト: yokano/MemoryBattler
func Cardsetdetail(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	// get key
	encodedKey := r.FormValue("key")
	decodedKey, err := datastore.DecodeKey(encodedKey)
	if err != nil {
		err.Error()
	}

	// delete mode
	if r.FormValue("action") == "delete" {
		err = datastore.Delete(c, decodedKey)
		if err != nil {
			err.Error()
		}
		http.Redirect(w, r, "/cardsetlist", 303)
	}

	// get cardset
	cardset := new(Cardset)
	err = datastore.Get(c, decodedKey, cardset)
	if err != nil {
		err.Error()
	}

	// output html
	material := make(map[string]string)
	material["Name"] = cardset.Name
	material["Key"] = encodedKey
	Output(w, "page/cardset/cardsetdetail.html", material)
}
コード例 #7
0
ファイル: account.go プロジェクト: decitrig/innerhearth
// RewriteID transactionally rewrites the Account under the
// correct (i.e., obfuscated) key.
func (a *Account) RewriteID(c appengine.Context, u *user.User) error {
	var err error
	a.ID, err = ID(u)
	if err != nil {
		return fmt.Errorf("couldn't create ID for %v", u)
	}
	var txnErr error
	for i := 0; i < 10; i++ {
		txnErr = datastore.RunInTransaction(c, func(c appengine.Context) error {
			if err := a.Put(c); err != nil {
				return err
			}
			oldKey := datastore.NewKey(c, "UserAccount", u.ID, 0, nil)
			if err := datastore.Delete(c, oldKey); err != nil {
				return err
			}
			return nil
		}, &datastore.TransactionOptions{XG: true})
		if txnErr != datastore.ErrConcurrentTransaction {
			break
		}
	}
	if txnErr != nil {
		return txnErr
	}
	return nil
}
コード例 #8
0
ファイル: datastore.go プロジェクト: yokano/tango
/**
 * データストアから指定された単語を削除する
 * API
 */
func delete(w http.ResponseWriter, r *http.Request) {
	var c appengine.Context
	var u *user.User
	var query *datastore.Query
	var word string
	var iterator *datastore.Iterator
	var key *datastore.Key
	var err error
	var entity Entity

	word = r.FormValue("word")
	if word == "" {
		return
	}

	c = appengine.NewContext(r)
	u = user.Current(c)
	query = datastore.NewQuery("words").Filter("UserID =", u.ID).Filter("Word =", word)
	iterator = query.Run(c)

	for {
		key, err = iterator.Next(&entity)
		if err != nil {
			break
		}
		err = datastore.Delete(c, key)
		Check(c, err)
	}
}
コード例 #9
0
ファイル: investment.go プロジェクト: danielfireman/isumm
func DeleteInvestment(c appengine.Context, key string) error {
	k, err := datastore.DecodeKey(key)
	if err != nil {
		return err
	}
	return datastore.Delete(c, k)
}
コード例 #10
0
ファイル: items.go プロジェクト: junglesung/Aliza
func deleteOneItem(rw http.ResponseWriter, req *http.Request, keyString string) {
	// To access datastore and to log
	c := appengine.NewContext(req)
	c.Infof("deleteOneItem()")

	// Result
	r := http.StatusNoContent
	defer func() {
		// Return status. WriteHeader() must be called before call to Write
		if r == http.StatusNoContent {
			rw.WriteHeader(http.StatusNoContent)
		} else {
			http.Error(rw, http.StatusText(r), r)
		}
	}()

	key, err := datastore.DecodeKey(keyString)
	if err != nil {
		c.Errorf("%s in decoding key string", err)
		r = http.StatusBadRequest
		return
	}

	// Delete the entity
	if err := datastore.Delete(c, key); err != nil {
		c.Errorf("%s, in deleting entity by key", err)
		r = http.StatusNotFound
		return
	}
	c.Infof("Key %s is deleted", keyString)
}
コード例 #11
0
ファイル: signin.go プロジェクト: jake-chen/signin
func delete(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	var dTile Tile
	//	var now Period
	//	datastore.Get(c, currentSemesterKey(c), &now)
	num, e := strconv.Atoi(r.FormValue("num"))
	sem, e1 := strconv.Atoi(r.FormValue("semester"))
	yr, e2 := strconv.Atoi(r.FormValue("year"))
	if e != nil || e1 != nil || e2 != nil {
		panic("shouldn't happen; semester and year guaranteed to be ints")
	}
	k := datastore.NewKey(c, "Tile", strint(r.FormValue("name"), num), 0, tileRootKey(c, sem, yr))
	datastore.Get(c, k, &dTile)
	if u := user.Current(c); !u.Admin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	} else {
		log.Println("deleting things now...")
		e1 := blobstore.Delete(c, appengine.BlobKey(dTile.Imgref))
		e2 := datastore.Delete(c, k)
		if e1 != nil {
			log.Println("error with blobstore delete")
		}
		if e2 != nil {
			log.Println("error with datastore delete")
		}
	}
	log.Println("redirecting")
	http.Redirect(w, r, "/", http.StatusFound)
}
コード例 #12
0
ファイル: model.go プロジェクト: nus/escape3ds_angularjs
/**
 * データストアからゲームを削除する
 * 削除を命令したユーザとゲームの所有者が一致していることを事前に確認すること
 * この関数内ではチェックを行わない
 * @param {string} encodedGameKey エンコード済みのゲームキー
 */
func (this *Model) deleteGame(encodedGameKey string) {
	gameKey, err := datastore.DecodeKey(encodedGameKey)
	check(this.c, err)

	err = datastore.Delete(this.c, gameKey)
	check(this.c, err)
}
コード例 #13
0
ファイル: items.go プロジェクト: junglesung/Aliza
func deleteAllItem(rw http.ResponseWriter, req *http.Request) {
	// To access datastore and to log
	c := appengine.NewContext(req)
	c.Infof("deleteAll()")

	// Delete root entity after other entities
	r := 0
	pKey := datastore.NewKey(c, ItemKind, ItemRoot, 0, nil)
	if keys, err := datastore.NewQuery(ItemKind).KeysOnly().GetAll(c, nil); err != nil {
		c.Errorf("%s", err)
		r = 1
	} else if err := datastore.DeleteMulti(c, keys); err != nil {
		c.Errorf("%s", err)
		r = 1
	} else if err := datastore.Delete(c, pKey); err != nil {
		c.Errorf("%s", err)
		r = 1
	}

	// Return status. WriteHeader() must be called before call to Write
	if r == 0 {
		rw.WriteHeader(http.StatusOK)
	} else {
		http.Error(rw, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
	}
}
コード例 #14
0
ファイル: feed.go プロジェクト: skiesel/feedme
func (f FeedInfo) updateArticles(c appengine.Context, articles Articles) error {
	key := datastore.NewKey(c, feedKind, f.Url, 0, nil)
	q := datastore.NewQuery(articleKind).Ancestor(key).KeysOnly()
	stored := make(map[string]*datastore.Key)
	for it := q.Run(c); ; {
		k, err := it.Next(nil)
		if err == datastore.Done {
			break
		} else if err != nil {
			return err
		}
		stored[k.StringID()] = k
	}

	for _, a := range articles {
		k := datastore.NewKey(c, articleKind, a.StringID(), 0, key)
		id := k.StringID()
		if _, ok := stored[id]; ok {
			delete(stored, id)
			continue
		}
		if _, err := datastore.Put(c, k, &a); err != nil {
			return err
		}
	}

	for _, k := range stored {
		if err := datastore.Delete(c, k); err != nil {
			return err
		}
	}
	return nil
}
コード例 #15
0
ファイル: team.go プロジェクト: offpath/ironpuzzler
func (t *Team) Delete(c appengine.Context) {
	err := datastore.Delete(c, t.Key)
	if err != nil {
		c.Errorf("Error: %v", err)
		return
	}
}
コード例 #16
0
ファイル: account.go プロジェクト: decitrig/innerhearth
// Delete removes a ClaimedEmail from the datastore, freeing that
// email for reclamation. Should only be used by site admins.
func (e *ClaimedEmail) Delete(c appengine.Context) error {
	key := e.key(c)
	if err := datastore.Delete(c, key); err != nil {
		return err
	}
	return nil
}
コード例 #17
0
ファイル: windmon.go プロジェクト: 80nashi/windmon
func unregisterUser(addr string, c appengine.Context) {
	q := datastore.NewQuery(USER_MODEL).
		Filter("Email =", addr).
		KeysOnly()
	keys, err := q.GetAll(c, nil)
	if err != nil {
		c.Errorf("Cound not query the model for %s: %v", addr, err)
		return
	}
	if len(keys) == 0 {
		c.Infof("No such user to unregister: %s", addr)
		return
	}
	for i := range keys {
		datastore.Delete(c, keys[i])
	}
	c.Infof("Removed user %s", addr)

	msg := &gaeMail.Message{
		Sender:  "*****@*****.**",
		To:      []string{addr},
		Subject: "Email unregistered",
		Body:    "user " + addr + " has been unregistered",
	}
	gaeMail.Send(c, msg)
}
コード例 #18
0
ファイル: web.go プロジェクト: dbratus/impack
func cut(resp http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)

	minuteBack, _ := time.ParseDuration("-1m")
	cutPoint := time.Now().Add(minuteBack)

	q := datastore.NewQuery("SpriteInfo").
		Filter("Timestamp <", cutPoint)

	itr := q.Run(ctx)

	var spriteInfo SpriteInfo

	cnt := 0
	var k *datastore.Key
	var itrErr error

	for k, itrErr = itr.Next(&spriteInfo); itrErr == nil; k, itrErr = itr.Next(&spriteInfo) {
		if err := blobstore.Delete(ctx, spriteInfo.CssId); err != nil {
			ctx.Errorf("Error deleting CSS %s %s.", spriteInfo.CssId, err)
		}

		if err := blobstore.Delete(ctx, spriteInfo.ImageId); err != nil {
			ctx.Errorf("Error deleting image %s %s.", spriteInfo.ImageId, err)
		}

		if err := datastore.Delete(ctx, k); err != nil {
			ctx.Errorf("Error deleting sprite %s %s.", k, err)
		}

		cnt++
	}

	ctx.Infof("Cut stoped with result %v. %d sprites deleted", itrErr, cnt)
}
コード例 #19
0
ファイル: edit.go プロジェクト: Popog/gotemp
func modifyEditHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	if !forceAdmin(c, w, r) {
		return
	}

	Name := r.FormValue("Name")

	switch r.FormValue("Submit") {
	case "Select":
		var template Template
		if Name != "New Template" {
			var err error
			if template, err = (contextTemplateLoader{c}).LoadTemplate(Name); err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}

		if err := modify_edit_handler_template.Execute(w, template); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	case "Remove":
		if err := datastore.Delete(c, datastore.NewKey(c, "Name", Name, 0, nil)); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	default:
		http.Error(w, "form parsing error", http.StatusInternalServerError)
		return
	}
}
コード例 #20
0
ファイル: server_nonce.go プロジェクト: TimSylvester/bitwrk
func checkNonce(c appengine.Context, nonce string) error {
	now := time.Now()

	if len(nonce) < 24 || len(nonce) > 32 {
		return errInvalidNonce
	}

	key := NonceKey(c, nonce)
	return datastore.RunInTransaction(c, func(c appengine.Context) error {
		var dbNonce Nonce
		if err := datastore.Get(c, key, &dbNonce); err != nil {
			return errInvalidNonce
		}

		if !dbNonce.Expires.After(now) {
			return errInvalidNonce
		}

		if err := datastore.Delete(c, key); err != nil {
			return err
		}

		return nil
	}, nil)
}
コード例 #21
0
ファイル: inmail.go プロジェクト: vidoss/goinbox
func publishToChannels(c appengine.Context, msg *Message) error {
	q := datastore.NewQuery("Endpoint").KeysOnly()
	endpoints, err := q.GetAll(c, nil)
	if err != nil {
		c.Errorf("Error getting enpoints: %v", err)
		return err
	}
	message, err := json.Marshal(msg)
	if err != nil {
		c.Errorf("Error marshaling msg -> json: %v", err)
		return err
	}
	errc := make(chan error)
	for _, e := range endpoints {
		go func(e *datastore.Key) {
			err := channel.Send(c, strconv.FormatInt(e.IntID(), 10), string(message))
			if err != nil {
				// Send failed. Delete the endpoint.
				if err := datastore.Delete(c, e); err != nil {
					c.Errorf("deleting endpoint: %v", err)
				}
			}
			errc <- err
		}(e)
	}
	for i := 0; i < len(endpoints); i++ {
		if err := <-errc; err != nil {
			c.Errorf("sending message: %v", err)
		}
	}
	return nil
}
コード例 #22
0
ファイル: handleMsg.go プロジェクト: hokuto007/csnuts
func handleMsgDelete(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	if !user.IsAdmin(c) {
		//Redirect
		w.WriteHeader(http.StatusBadRequest)
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		io.WriteString(w, "Sorry, only site admin can do this.")
		return
	}
	id, err := strconv.ParseInt(r.FormValue("id"), 0, 64)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		io.WriteString(w, "BadRequest")
		return
	}
	k := datastore.NewKey(c, "aMessage", "", id, nil)
	err = datastore.Delete(c, k)
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		io.WriteString(w, "NotFound")
		return
	}
	DecCount(w, r)
	w.WriteHeader(http.StatusOK)
	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	io.WriteString(w, "OK")
	return
}
コード例 #23
0
func getAndStoreTerms(context appengine.Context) ([]Term, error) {
	responseBody, err := runApiRequest(context, "/Terms")
	if err != nil {
		context.Infof("Failed loading the terms!")
		context.Infof(err.Error())
		return nil, err
	}

	context.Infof("About to unmarshal: %s", string(responseBody))
	var termsResponse TermsOverallResponse
	err = json.Unmarshal(responseBody, &termsResponse)
	if err != nil {
		context.Infof("Couldn't unmarshal the terms response")
		context.Infof(err.Error())
		return nil, err
	}

	termsQuery := datastore.NewQuery("Term").KeysOnly()
	termKeys, err := termsQuery.GetAll(context, nil)
	if err != nil {
		context.Infof("There was a problem loading the existing terms from the datastore")
		context.Infof(err.Error())
		return nil, err
	}
	for _, termKey := range termKeys {
		datastore.Delete(context, termKey)
	}

	for _, term := range termsResponse.OverallResponse.Terms {
		datastore.Put(context, datastore.NewIncompleteKey(context, "Term", nil), &term)
	}

	return termsResponse.OverallResponse.Terms, nil
}
コード例 #24
0
ファイル: aeindex.go プロジェクト: sfrdmn/camlistore
func (is *indexStorage) CommitBatch(bm sorted.BatchMutation) error {
	type mutationser interface {
		Mutations() []sorted.Mutation
	}
	var muts []sorted.Mutation
	if m, ok := bm.(mutationser); ok {
		muts = m.Mutations()
	} else {
		panic("unexpected type")
	}
	tryFunc := func(c appengine.Context) error {
		for _, m := range muts {
			dk := is.key(c, m.Key())
			if m.IsDelete() {
				if err := datastore.Delete(c, dk); err != nil {
					return err
				}
			} else {
				// A put.
				ent := &indexRowEnt{
					Value: []byte(m.Value()),
				}
				if _, err := datastore.Put(c, dk, ent); err != nil {
					return err
				}
			}
		}
		return nil
	}
	c := ctxPool.Get()
	defer c.Return()
	return datastore.RunInTransaction(c, tryFunc, crossGroupTransaction)
}
コード例 #25
0
ファイル: datastore.go プロジェクト: huluwa/2016_Gofr
func MoveSubscription(c appengine.Context, subRef SubscriptionRef, destRef FolderRef) error {
	currentSubscriptionKey, err := subRef.key(c)
	if err != nil {
		return err
	}

	newSubRef := SubscriptionRef{
		FolderRef:      destRef,
		SubscriptionID: subRef.SubscriptionID,
	}

	newSubscriptionKey, err := newSubRef.key(c)
	if err != nil {
		return err
	}

	subscription := new(Subscription)
	if err := datastore.Get(c, currentSubscriptionKey, subscription); err != nil {
		c.Errorf("Error reading subscription: %s", err)
		return err
	}

	if _, err := datastore.Put(c, newSubscriptionKey, subscription); err != nil {
		c.Errorf("Error writing subscription: %s", err)
		return err
	}

	if err := datastore.Delete(c, currentSubscriptionKey); err != nil {
		c.Errorf("Error deleting subscription: %s", err)
		return err
	}

	return nil
}
コード例 #26
0
ファイル: session.go プロジェクト: SII-Nantes/callForPaperGo
/**
 * delete draft
 * @param  {[type]} w http.ResponseWriter [description]
 * @param  {[type]} r *http.Request       [description]
 * @return {[type]}   [description]
 */
func deleteDraft(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	//Get the sessions id from the URL.
	id := mux.Vars(r)["id"]

	currentUserKey, _, _ := getCurrentUserKey(c, r)

	query := datastore.NewQuery("Session").Ancestor(currentUserKey).Filter("Draft =", true)
	// If the user is logged in fetch only their lists.
	sessions := []Session{}
	keys, err := query.GetAll(c, &sessions)
	if err != nil {
		SetError(w, r, 400, "")
		return
	}

	// Update the encoded keys and encode the lists.
	session := Session{}
	found := false
	for _, k := range keys {
		if strconv.FormatInt(k.IntID(), 10) == id {
			datastore.Delete(c, k)
			found = true
		}
	}
	if !found {
		SetError(w, r, 404, "draft not found")
		return
	}
	json.NewEncoder(w).Encode(session)
	return
}
コード例 #27
0
ファイル: record.go プロジェクト: matryer/gae-records
// Delete deletes this record.  Returns nil if successful, otherwise returns the os.Error
// that was retrned by appengime/datastore.
//   record.Delete()
//
// Raises events:
//   Model.BeforeDelete with Args(id, record)
//   Model.AfterDelete with Args(id, record)
// Note: The Record will be passed to the events.
func (r *Record) Delete() os.Error {

	// trigger the BeforeDeleteByID event
	context := r.model.BeforeDelete.Trigger(r.ID(), r)

	if !context.Cancel {

		err := datastore.Delete(GetAppEngineContext(), r.DatastoreKey())

		if err == nil {

			// clean up the record
			r.setID(NoIDValue)

			// trigger the AfterDeleteByID event
			if r.model.AfterDelete.HasCallbacks() {
				r.model.AfterDelete.TriggerWithContext(context)
			}

		}

		return err

	}

	return ErrOperationCancelledByEventCallback

}
コード例 #28
0
ファイル: datastore.go プロジェクト: huluwa/2016_Gofr
func DeleteFolder(c appengine.Context, ref FolderRef) error {
	folderKey, err := ref.key(c)
	if err != nil {
		return err
	}

	// Get a list of relevant subscriptions
	q := datastore.NewQuery("Subscription").Ancestor(folderKey).KeysOnly().Limit(defaultBatchSize)
	subscriptionKeys, err := q.GetAll(c, nil)

	if err != nil {
		return err
	}

	// Delete folder & subscriptions
	if err := datastore.Delete(c, folderKey); err != nil {
		c.Errorf("Error deleting folder: %s", err)
		return err
	}

	if subscriptionKeys == nil {
		// No subscriptions; nothing more to do
		return nil
	}

	if err := datastore.DeleteMulti(c, subscriptionKeys); err != nil {
		c.Errorf("Error deleting subscriptions: %s", err)
		return err
	}

	return nil
}
コード例 #29
0
ファイル: admin.go プロジェクト: rif/gopher-web
func accept(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	id := r.FormValue("id")
	intID, err := strconv.ParseInt(id, 10, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	pkg := &Package{}
	key := datastore.NewKey(c, "Package", "", intID, nil)
	err = datastore.Get(c, key, pkg)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	// check if the package is already present
	acceptQuery := datastore.NewQuery("Package").
		Filter("Accepted =", true).
		Filter("Repo =", pkg.Repo)

	var packages []*Package
	keys, err := acceptQuery.GetAll(c, &packages)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(packages) > 1 {
		// just print an error to let admin know
		c.Errorf("More tha one package for repo: %v", pkg.Repo)
	}

	if len(packages) > 0 {
		// update the package and delete
		oldKey := keys[0]
		oldPkg := packages[0]
		oldPkg.Name = pkg.Name
		oldPkg.Description = pkg.Description
		oldPkg.IsLibrary = pkg.IsLibrary
		oldPkg.Category = pkg.Category
		oldPkg.Updated = time.Now()
		if _, err = datastore.Put(c, oldKey, oldPkg); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		if err = datastore.Delete(c, key); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	} else {
		// accept the new package
		pkg.Accepted = true
		if _, err = datastore.Put(c, key, pkg); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}
	memcache.Delete(c, pkg.Repo)
	memcache.Delete(c, CAT)
	memcache.Delete(c, ALL_QUERY)
}
コード例 #30
0
ファイル: delete.go プロジェクト: nelsam/atomicgames
func DeleteModel(ctx appengine.Context, model models.Model) error {
	key, err := model.Key()
	if err != nil {
		return err
	}
	return datastore.Delete(ctx, key)
}