@@ -90,14 +90,20 @@ func (i *Plugin) upload(ctx context.Context, p *pluginpack.Package, sid id.Scene
9090 }
9191 }()
9292
93+ var oldPManifest * manifest.Manifest
9394 newpid := p .Manifest .Plugin .ID ()
9495 oldpid := s .Plugins ().PluginByName (newpid .Name ()).PluginRef ()
95- var oldp * plugin.Plugin
9696 if oldpid != nil {
97- oldp , err = i .pluginRepo .FindByID (ctx , * oldpid , []id.SceneID {sid })
97+ oldPlugin , err : = i .pluginRepo .FindByID (ctx , * oldpid , []id.SceneID {sid })
9898 if err != nil {
9999 return nil , nil , err
100100 }
101+
102+ oldPManifest2 , err := i .pluginManifestFromPlugin (ctx , oldPlugin )
103+ if err != nil {
104+ return nil , nil , err
105+ }
106+ oldPManifest = & oldPManifest2
101107 }
102108
103109 // new (oldpid == nil): upload files, save plugin and properties -> install
@@ -136,19 +142,19 @@ func (i *Plugin) upload(ctx context.Context, p *pluginpack.Package, sid id.Scene
136142 return nil , nil , err
137143 }
138144
139- if oldpid == nil {
145+ if oldPManifest == nil {
140146 // new: install plugin
141147 if err := i .installScenePlugin (ctx , p , s ); err != nil {
142148 return nil , nil , err
143149 }
144150 } else {
145151 // same, diff: migrate
146- if err := i .migrateScenePlugin (ctx , p , s , oldp ); err != nil {
152+ if err := i .migrateScenePlugin (ctx , * oldPManifest , p , s ); err != nil {
147153 return nil , nil , err
148154 }
149155 }
150156
151- if oldpid != nil && ! oldpid .Equal (newpid ) {
157+ if oldpid != nil && oldPManifest != nil && ! oldpid .Equal (newpid ) {
152158 // diff only: delete old files
153159 if err := i .file .RemovePlugin (ctx , * oldpid ); err != nil {
154160 return nil , nil , err
@@ -159,7 +165,7 @@ func (i *Plugin) upload(ctx context.Context, p *pluginpack.Package, sid id.Scene
159165 if err := i .pluginRepo .Remove (ctx , * oldpid ); err != nil {
160166 return nil , nil , err
161167 }
162- if ps := oldp .PropertySchemas (); len (ps ) > 0 {
168+ if ps := oldPManifest . Plugin .PropertySchemas (); len (ps ) > 0 {
163169 if err := i .propertySchemaRepo .RemoveAll (ctx , ps ); err != nil {
164170 return nil , nil , err
165171 }
@@ -195,17 +201,12 @@ func (i *Plugin) installScenePlugin(ctx context.Context, p *pluginpack.Package,
195201 return nil
196202}
197203
198- func (i * Plugin ) migrateScenePlugin (ctx context.Context , p * pluginpack.Package , s * scene.Scene , oldp * plugin. Plugin ) (err error ) {
199- if oldp == nil || p .Manifest == nil {
204+ func (i * Plugin ) migrateScenePlugin (ctx context.Context , oldm manifest. Manifest , p * pluginpack.Package , s * scene.Scene ) (err error ) {
205+ if oldm . Plugin == nil || p .Manifest == nil {
200206 return nil
201207 }
202208
203- oldPManifest , err := i .pluginManifestFromPlugin (ctx , oldp )
204- if err != nil {
205- return err
206- }
207-
208- diff := manifest .DiffFrom (oldPManifest , * p .Manifest )
209+ diff := manifest .DiffFrom (oldm , * p .Manifest )
209210 updatedProperties := property.List {}
210211
211212 // update scene
@@ -220,18 +221,14 @@ func (i *Plugin) migrateScenePlugin(ctx context.Context, p *pluginpack.Package,
220221 updatedProperties = append (updatedProperties , p )
221222 }
222223
223- sp := s .Plugins ().Plugin (diff .From )
224- if sp != nil && sp .Property () != nil && diff .PropertySchemaDeleted {
224+ if sp := s .Plugins ().Plugin (diff .From ); sp != nil && sp .Property () != nil && diff .PropertySchemaDeleted {
225225 // plugin property should be removed
226226 if err := i .propertyRepo .Remove (ctx , * sp .Property ()); err != nil {
227227 return err
228228 }
229229 }
230230
231231 s .Plugins ().Upgrade (diff .From , diff .To , spp , diff .PropertySchemaDeleted )
232- if err := i .sceneRepo .Save (ctx , s ); err != nil {
233- return err
234- }
235232
236233 // delete layers, blocks and widgets
237234 for _ , e := range diff .DeletedExtensions {
@@ -255,6 +252,10 @@ func (i *Plugin) migrateScenePlugin(ctx context.Context, p *pluginpack.Package,
255252 }
256253 }
257254
255+ if err := i .sceneRepo .Save (ctx , s ); err != nil {
256+ return err
257+ }
258+
258259 // migrate layers
259260 if err := i .layerRepo .UpdatePlugin (ctx , diff .From , diff .To , []id.SceneID {s .ID ()}); err != nil {
260261 return err
0 commit comments