@@ -31,89 +31,6 @@ type ShareOrLink struct {
31
31
Link * model.PublicLink
32
32
}
33
33
34
- func RunMigration (username , password , host , name , gatewaysvc , token string , port int ) {
35
- config := map [string ]interface {}{
36
- "engine" : "mysql" ,
37
- "db_username" : username ,
38
- "db_password" : password ,
39
- "db_host" : host ,
40
- "db_port" : port ,
41
- "db_name" : name ,
42
- "gatewaysvc" : gatewaysvc ,
43
- "dry_run" : false ,
44
- }
45
- tokenlessCtx , cancel := context .WithCancel (context .Background ())
46
- ctx := appctx .ContextSetToken (tokenlessCtx , token )
47
- ctx = metadata .AppendToOutgoingContext (ctx , appctx .TokenHeader , token )
48
- defer cancel ()
49
-
50
- shareManager , err := NewShareManager (ctx , config )
51
- if err != nil {
52
- fmt .Println ("Failed to create shareManager: " + err .Error ())
53
- os .Exit (1 )
54
- }
55
- sharemgr := shareManager .(* shareMgr )
56
- oldDb , err := sql .Open ("mysql" , fmt .Sprintf ("%s:%s@tcp(%s:%d)/%s" , username , password , host , port , name ))
57
- if err != nil {
58
- fmt .Println ("Failed to create db: " + err .Error ())
59
- os .Exit (1 )
60
- }
61
- migrator := Migrator {
62
- OldDb : oldDb ,
63
- NewDb : sharemgr .db ,
64
- ShareMgr : sharemgr ,
65
- }
66
-
67
- ch := make (chan * ShareOrLink , 100 )
68
- go getAllShares (ctx , migrator , ch )
69
- for share := range ch {
70
- // TODO error handling
71
- if share .IsShare {
72
- fmt .Printf ("Creating share %d\n " , share .Share .ID )
73
- migrator .NewDb .Create (& share .Share )
74
- } else {
75
- fmt .Printf ("Creating share %d\n " , share .Link .ID )
76
- migrator .NewDb .Create (& share .Link )
77
- }
78
- }
79
-
80
- }
81
-
82
- func getAllShares (ctx context.Context , migrator Migrator , ch chan * ShareOrLink ) {
83
- // First we find out what the highest ID is
84
- count , err := getCount (migrator )
85
- if err != nil {
86
- fmt .Println ("Error getting highest id: " + err .Error ())
87
- close (ch )
88
- return
89
- }
90
- fmt .Printf ("Migrating %d shares\n " , count )
91
-
92
- query := "select id, coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, lower(coalesce(share_with, '')) as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, coalesce(item_type, '') as item_type, stime, permissions, share_type, orphan FROM oc_share order by id desc" // AND id=?"
93
- params := []interface {}{}
94
-
95
- res , err := migrator .OldDb .Query (query , params ... )
96
-
97
- if err != nil {
98
- fmt .Printf ("Fatal error: %s" , err .Error ())
99
- close (ch )
100
- return
101
- }
102
-
103
- for res .Next () {
104
- var s OldShareEntry
105
- res .Scan (& s .ID , & s .UIDOwner , & s .UIDInitiator , & s .ShareWith , & s .Prefix , & s .ItemSource , & s .ItemType , & s .STime , & s .Permissions , & s .ShareType , & s .Orphan )
106
- newShare , err := oldShareToNewShare (ctx , migrator , s )
107
- if err == nil {
108
- ch <- newShare
109
- } else {
110
- fmt .Printf ("Error occured for share %s: %s\n " , s .ID , err .Error ())
111
- }
112
- }
113
-
114
- close (ch )
115
- }
116
-
117
34
type OldShareEntry struct {
118
35
ID int
119
36
UIDOwner string
@@ -168,12 +85,20 @@ func RunMigration(username, password, host, name, gatewaysvc, token string, port
168
85
defer cancel ()
169
86
170
87
// Set up migrator
171
- shareManager , err := New (ctx , config )
88
+ shareManager , err := NewShareManager (ctx , config )
172
89
if err != nil {
173
90
fmt .Println ("Failed to create shareManager: " + err .Error ())
174
91
os .Exit (1 )
175
92
}
176
- sharemgr := shareManager .(* mgr )
93
+ sharemgr := shareManager .(* shareMgr )
94
+
95
+ linkManager , err := NewPublicShareManager (ctx , config )
96
+ if err != nil {
97
+ fmt .Println ("Failed to create shareManager: " + err .Error ())
98
+ os .Exit (1 )
99
+ }
100
+ linkmgr := linkManager .(* publicShareMgr )
101
+
177
102
oldDb , err := sql .Open ("mysql" , fmt .Sprintf ("%s:%s@tcp(%s:%d)/%s?parseTime=true" , username , password , host , port , name ))
178
103
if err != nil {
179
104
fmt .Println ("Failed to create db: " + err .Error ())
@@ -183,6 +108,7 @@ func RunMigration(username, password, host, name, gatewaysvc, token string, port
183
108
OldDb : oldDb ,
184
109
NewDb : sharemgr .db ,
185
110
ShareMgr : sharemgr ,
111
+ LinkMgr : linkmgr ,
186
112
}
187
113
188
114
if dryRun {
@@ -371,10 +297,9 @@ func oldShareToNewShare(ctx context.Context, migrator Migrator, s *OldShareEntry
371
297
} else if errors .Is (err , errtypes .NotFound (protoShare .Inode )) {
372
298
fmt .Printf ("Marked share %d as an orphan (%s, %s)\n " , s .ID , protoShare .Instance , protoShare .Inode )
373
299
protoShare .Orphan = true
374
- } else {
375
- // We do not set, because of a general error
376
- // fmt.Printf("An error occured for share %d while statting (%s, %s): %s\n", s.ID, protoShare.Instance, protoShare.Inode, err.Error())
377
- }
300
+ } // else {
301
+ // We do not set, because of a general error
302
+ // }
378
303
}
379
304
380
305
// ShareTypeUser = 0
0 commit comments