(app *App, c *SubmittedCollection, alias string)
| 914 | } |
| 915 | |
| 916 | func (db *datastore) UpdateCollection(app *App, c *SubmittedCollection, alias string) error { |
| 917 | // Truncate fields correctly, so we don't get "Data too long for column" errors in MySQL (writefreely#600) |
| 918 | if c.Title != nil { |
| 919 | *c.Title = parse.Truncate(*c.Title, collMaxLengthTitle) |
| 920 | } |
| 921 | if c.Description != nil { |
| 922 | *c.Description = parse.Truncate(*c.Description, collMaxLengthDescription) |
| 923 | } |
| 924 | |
| 925 | q := query.NewUpdate(). |
| 926 | SetStringPtr(c.Title, "title"). |
| 927 | SetStringPtr(c.Description, "description"). |
| 928 | SetStringPtr(c.StyleSheet, "style_sheet"). |
| 929 | SetStringPtr(c.Script, "script"). |
| 930 | SetStringPtr(c.Signature, "post_signature") |
| 931 | |
| 932 | if c.Format != nil { |
| 933 | cf := &CollectionFormat{Format: c.Format.String} |
| 934 | if cf.Valid() { |
| 935 | q.SetNullString(c.Format, "format") |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | var updatePass bool |
| 940 | if c.Visibility != nil && (collVisibility(*c.Visibility)&CollProtected == 0 || c.Pass != "") { |
| 941 | q.SetIntPtr(c.Visibility, "privacy") |
| 942 | if c.Pass != "" { |
| 943 | updatePass = true |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | // WHERE values |
| 948 | q.Where("alias = ? AND owner_id = ?", alias, c.OwnerID) |
| 949 | |
| 950 | if q.Updates == "" && c.Monetization == nil { |
| 951 | return ErrPostNoUpdatableVals |
| 952 | } |
| 953 | |
| 954 | // Find any current domain |
| 955 | var collID int64 |
| 956 | var rowsAffected int64 |
| 957 | var changed bool |
| 958 | var res sql.Result |
| 959 | err := db.QueryRow("SELECT id FROM collections WHERE alias = ?", alias).Scan(&collID) |
| 960 | if err != nil { |
| 961 | log.Error("Failed selecting from collections: %v. Some things won't work.", err) |
| 962 | } |
| 963 | |
| 964 | // Update MathJax value |
| 965 | if c.MathJax { |
| 966 | if db.driverName == driverSQLite { |
| 967 | _, err = db.Exec("INSERT OR REPLACE INTO collectionattributes (collection_id, attribute, value) VALUES (?, ?, ?)", collID, "render_mathjax", "1") |
| 968 | } else { |
| 969 | _, err = db.Exec("INSERT INTO collectionattributes (collection_id, attribute, value) VALUES (?, ?, ?) "+db.upsert("collection_id", "attribute")+" value = ?", collID, "render_mathjax", "1", "1") |
| 970 | } |
| 971 | if err != nil { |
| 972 | log.Error("Unable to insert render_mathjax value: %v", err) |
| 973 | return err |
nothing calls this directly
no test coverage detected