1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

GO-1367: migration for fixing imported notion pages

This commit is contained in:
AnastasiaShemyakinskaya 2023-04-25 18:17:59 +02:00 committed by Mikhail Iudin
parent 1a124282e8
commit 0ac77145ae
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
2 changed files with 39 additions and 12 deletions

View file

@ -14,8 +14,8 @@ import (
"github.com/anytypeio/go-anytype-middleware/core/block/editor/table"
"github.com/anytypeio/go-anytype-middleware/core/block/editor/template"
"github.com/anytypeio/go-anytype-middleware/core/block/migration"
"github.com/anytypeio/go-anytype-middleware/core/files"
"github.com/anytypeio/go-anytype-middleware/core/relation"
"github.com/anytypeio/go-anytype-middleware/core/block/simple"
relation2 "github.com/anytypeio/go-anytype-middleware/core/relation"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/bundle"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/core"
"github.com/anytypeio/go-anytype-middleware/pkg/lib/localstore/objectstore"
@ -39,23 +39,22 @@ type Page struct {
}
func NewPage(
sb smartblock.SmartBlock,
objectStore objectstore.ObjectStore,
anytype core.Service,
fileBlockService file.BlockService,
bookmarkBlockService bookmark.BlockService,
bookmarkService bookmark.BookmarkService,
relationService relation.Service,
relationService relation2.Service,
tempDirProvider core.TempDirProvider,
sbtProvider typeprovider.SmartBlockTypeProvider,
layoutConverter converter.LayoutConverter,
fileService files.Service,
) *Page {
sb := smartblock.New()
f := file.NewFile(
sb,
fileBlockService,
anytype,
tempDirProvider,
fileService,
)
return &Page{
SmartBlock: sb,
@ -69,9 +68,9 @@ func NewPage(
Clipboard: clipboard.NewClipboard(
sb,
f,
anytype,
tempDirProvider,
relationService,
fileService,
),
Bookmark: bookmark.NewBookmark(
sb,
@ -166,7 +165,35 @@ func (p *Page) CreationStateMigration(ctx *smartblock.InitContext) migration.Mig
}
func (p *Page) StateMigrations() migration.Migrations {
return migration.MakeMigrations(nil)
blockMigration := cleanupEmptyBlockMigration()
return migration.MakeMigrations([]migration.Migration{blockMigration})
}
// cleanupEmptyBlockMigration is fixing existing pages, imported from Notion
func cleanupEmptyBlockMigration() migration.Migration {
return migration.Migration{
Version: 2,
Proc: func(s *state.State) {
if s.Exists(s.RootId()) {
block := s.Get(s.RootId())
if isBlockEmpty(block) {
newBlock := block.Copy()
newBlock.Model().Content = &model.BlockContentOfSmartblock{
Smartblock: &model.BlockContentSmartblock{},
}
s.Set(newBlock)
}
}
},
}
}
func isBlockEmpty(block simple.Block) bool {
if block.Model().Content == nil {
return true
}
smartBlock := block.Model().Content.(*model.BlockContentOfSmartblock)
return smartBlock == nil || smartBlock.Smartblock == nil
}
func GetDefaultViewRelations(rels []*model.Relation) []*model.BlockContentDataviewRelation {

View file

@ -559,14 +559,14 @@ func (s *State) apply(fast, one, withLayouts bool) (msgs []simple.EventMessage,
s.fillChanges(msgs)
// apply to parent
for _, id := range toRemove {
if s.parent != nil {
if s.parent != nil {
for _, id := range toRemove {
action.Remove = append(action.Remove, s.PickOrigin(id).Copy())
delete(s.parent.blocks, id)
}
}
for _, b := range s.blocks {
if s.parent != nil {
if s.parent != nil {
for _, b := range s.blocks {
id := b.Model().Id
if _, ok := inUse[id]; ok {
s.parent.blocks[id] = b