get pages from file if no longer in item.info

This commit is contained in:
j 2016-01-19 09:48:33 +05:30
parent 9f3374a7dc
commit 200c6df686
2 changed files with 24 additions and 1 deletions

View file

@ -101,4 +101,4 @@ USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
DEBUG_HTTP = server.get('debug_http', False) DEBUG_HTTP = server.get('debug_http', False)
DB_VERSION = 2 DB_VERSION = 3

View file

@ -299,6 +299,8 @@ class Update(Thread):
db_version = migrate_1() db_version = migrate_1()
if db_version < 2: if db_version < 2:
db_version = migrate_2() db_version = migrate_2()
if db_version < 3:
db_version = migrate_3()
settings.server['db_version'] = settings.DB_VERSION settings.server['db_version'] = settings.DB_VERSION
def run(self): def run(self):
@ -332,3 +334,24 @@ def migrate_2():
s.item.update_sort() s.item.update_sort()
session.commit() session.commit()
return 2 return 2
def migrate_3():
with db.session():
import item.models
for i in item.models.Item.find({
'query': {
'conditions': [{
'key':'mediastate',
'value':'available',
'operator': '=='
}]
}
}):
if not i.files.all():
i.remove_file()
else:
f = i.files.all()[0]
if not 'pages' in i.info and 'pages' in f.info:
i.info['pages'] = f.info['pages']
i.save()
return 3