mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Use AfterLoad instead of AfterSet on Structs (#2628)
* use AfterLoad instead of AfterSet on Structs * fix the comments on AfterLoad * fix the comments on action AfterLoad
This commit is contained in:
		
							
								
								
									
										40
									
								
								vendor/github.com/go-xorm/xorm/processors.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										40
									
								
								vendor/github.com/go-xorm/xorm/processors.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -29,13 +29,6 @@ type AfterSetProcessor interface { | ||||
| 	AfterSet(string, Cell) | ||||
| } | ||||
|  | ||||
| // !nashtsai! TODO enable BeforeValidateProcessor when xorm start to support validations | ||||
| //// Executed before an object is validated | ||||
| //type BeforeValidateProcessor interface { | ||||
| //    BeforeValidate() | ||||
| //} | ||||
| // -- | ||||
|  | ||||
| // AfterInsertProcessor executed after an object is persisted to the database | ||||
| type AfterInsertProcessor interface { | ||||
| 	AfterInsert() | ||||
| @@ -50,3 +43,36 @@ type AfterUpdateProcessor interface { | ||||
| type AfterDeleteProcessor interface { | ||||
| 	AfterDelete() | ||||
| } | ||||
|  | ||||
| // AfterLoadProcessor executed after an ojbect has been loaded from database | ||||
| type AfterLoadProcessor interface { | ||||
| 	AfterLoad() | ||||
| } | ||||
|  | ||||
| // AfterLoadSessionProcessor executed after an ojbect has been loaded from database with session parameter | ||||
| type AfterLoadSessionProcessor interface { | ||||
| 	AfterLoad(*Session) | ||||
| } | ||||
|  | ||||
| type executedProcessorFunc func(*Session, interface{}) error | ||||
|  | ||||
| type executedProcessor struct { | ||||
| 	fun     executedProcessorFunc | ||||
| 	session *Session | ||||
| 	bean    interface{} | ||||
| } | ||||
|  | ||||
| func (executor *executedProcessor) execute() error { | ||||
| 	return executor.fun(executor.session, executor.bean) | ||||
| } | ||||
|  | ||||
| func (session *Session) executeProcessors() error { | ||||
| 	processors := session.afterProcessors | ||||
| 	session.afterProcessors = make([]executedProcessor, 0) | ||||
| 	for _, processor := range processors { | ||||
| 		if err := processor.execute(); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user