(e *CollectionEvent)
| 798 | } |
| 799 | |
| 800 | func onCollectionSave(e *CollectionEvent) error { |
| 801 | if e.Collection.Type == "" { |
| 802 | e.Collection.Type = CollectionTypeBase |
| 803 | } |
| 804 | |
| 805 | if e.Collection.IsNew() { |
| 806 | e.Collection.initDefaultId() |
| 807 | e.Collection.Created = types.NowDateTime() |
| 808 | } |
| 809 | |
| 810 | e.Collection.Updated = types.NowDateTime() |
| 811 | |
| 812 | // recreate the fields list to ensure that all normalizations |
| 813 | // like default field id are applied |
| 814 | e.Collection.Fields = NewFieldsList(e.Collection.Fields...) |
| 815 | |
| 816 | e.Collection.initDefaultFields() |
| 817 | |
| 818 | if e.Collection.IsAuth() { |
| 819 | e.Collection.unsetMissingOAuth2MappedFields() |
| 820 | } |
| 821 | |
| 822 | e.Collection.updateGeneratedIdIfExists(e.App) |
| 823 | |
| 824 | // normalize indexes table name |
| 825 | for i, raw := range e.Collection.Indexes { |
| 826 | parsed := dbutils.ParseIndex(raw) |
| 827 | |
| 828 | // no need to normalize |
| 829 | if parsed.TableName == e.Collection.Name { |
| 830 | continue |
| 831 | } |
| 832 | |
| 833 | parsed.TableName = e.Collection.Name |
| 834 | |
| 835 | normalized := parsed.Build() |
| 836 | if normalized == "" { |
| 837 | continue // leave to the model validator to decide whether to return an error |
| 838 | } |
| 839 | |
| 840 | e.Collection.Indexes[i] = normalized |
| 841 | } |
| 842 | |
| 843 | return e.Next() |
| 844 | } |
| 845 | |
| 846 | func onCollectionSaveExecute(e *CollectionEvent) error { |
| 847 | defer func() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…