@@ -14,7 +14,6 @@ package mysql
14
14
import (
15
15
"bytes"
16
16
"database/sql"
17
- "fmt"
18
17
19
18
"github.com/documize/community/core/env"
20
19
"github.com/documize/community/core/streamutil"
@@ -27,7 +26,7 @@ type Scope struct {
27
26
}
28
27
29
28
// Get fetches a configuration JSON element from the config table.
30
- func (s Scope ) Get (area , path string ) (value string ) {
29
+ func (s Scope ) Get (area , path string ) (value string , err error ) {
31
30
if path != "" {
32
31
path = "." + path
33
32
}
@@ -37,24 +36,22 @@ func (s Scope) Get(area, path string) (value string) {
37
36
defer streamutil .Close (stmt )
38
37
39
38
if err != nil {
40
- s .Runtime .Log .Error (fmt .Sprintf ("setting.Get %s %s" , area , path ), err )
41
- return ""
39
+ return "" , err
42
40
}
43
41
44
42
var item = make ([]uint8 , 0 )
45
43
46
44
err = stmt .Get (& item )
47
45
if err != nil {
48
- s .Runtime .Log .Error (fmt .Sprintf ("setting.Get %s %s" , area , path ), err )
49
- return ""
46
+ return "" , err
50
47
}
51
48
52
49
if len (item ) > 1 {
53
50
q := []byte (`"` )
54
51
value = string (bytes .TrimPrefix (bytes .TrimSuffix (item , q ), q ))
55
52
}
56
53
57
- return value
54
+ return value , nil
58
55
}
59
56
60
57
// Set writes a configuration JSON element to the config table.
@@ -81,7 +78,7 @@ func (s Scope) Set(area, json string) error {
81
78
82
79
// GetUser fetches a configuration JSON element from the userconfig table for a given orgid/userid combination.
83
80
// Errors return the empty string. A blank path returns the whole JSON object, as JSON.
84
- func (s Scope ) GetUser (orgID , userID , area , path string ) (value string ) {
81
+ func (s Scope ) GetUser (orgID , userID , area , path string ) (value string , err error ) {
85
82
if path != "" {
86
83
path = "." + path
87
84
}
@@ -93,23 +90,22 @@ func (s Scope) GetUser(orgID, userID, area, path string) (value string) {
93
90
defer streamutil .Close (stmt )
94
91
95
92
if err != nil {
96
- return ""
93
+ return "" , err
97
94
}
98
95
99
96
var item = make ([]uint8 , 0 )
100
97
101
98
err = stmt .Get (& item )
102
99
if err != nil && err != sql .ErrNoRows {
103
- s .Runtime .Log .Error (fmt .Sprintf ("setting.GetUser for user %s %s %s" , userID , area , path ), err )
104
- return ""
100
+ return "" , err
105
101
}
106
102
107
103
if len (item ) > 1 {
108
104
q := []byte (`"` )
109
105
value = string (bytes .TrimPrefix (bytes .TrimSuffix (item , q ), q ))
110
106
}
111
107
112
- return value
108
+ return value , nil
113
109
}
114
110
115
111
// SetUser writes a configuration JSON element to the userconfig table for the current user.
0 commit comments