stmt,err:=s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE refid=?")
deferstreamutil.Close(stmt)
iferr!=nil{
err=errors.Wrap(err,fmt.Sprintf("unable to prepare select for org %s",id))
return
}
err=stmt.Get(&org,id)
iferr!=nil{
err=errors.Wrap(err,fmt.Sprintf("unable to get org %s",id))
return
}
return
}
// GetOrganizationByDomain returns the organization matching a given URL subdomain.
// only return an organization when running normally
ifs.Runtime.Flags.SiteMode!=env.SiteModeNormal{
err=errors.New("database not in normal mode so cannot fetch meta for "+subdomain)
return
}
varstmt*sqlx.Stmt
stmt,err=s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain=? AND active=1")
deferstreamutil.Close(stmt)
iferr!=nil{
err=errors.Wrap(err,fmt.Sprintf("unable to prepare select for subdomain %s",subdomain))
return
}
err=stmt.Get(&o,subdomain)
iferr==nil{
return
}
// we try to match on empty domain as last resort
stmt,err=s.Runtime.Db.Preparex("SELECT id, refid, company, title, message, url, domain, service as conversionendpoint, email, serial, active, allowanonymousaccess, authprovider, coalesce(authconfig,JSON_UNQUOTE('{}')) as authconfig, created, revised FROM organization WHERE domain='' AND active=1")
deferstreamutil.Close(stmt)
iferr!=nil{
err=errors.Wrap(err,"unable to prepare select for empty subdomain")
return
}
err=stmt.Get(&o)
iferr!=nil&&err!=sql.ErrNoRows{
err=errors.Wrap(err,"unable to execute select for empty subdomain")
stmt,err:=ctx.Transaction.PrepareNamed("UPDATE organization SET allowanonymousaccess=:allowanonymousaccess, authprovider=:authprovider, authconfig=:authconfig, revised=:revised WHERE refid=:refid")