Add check for has_cover cache consistency to check db integrity

This commit is contained in:
Kovid Goyal 2010-11-23 12:30:27 -07:00
parent 1080fdab8f
commit f7c49d1609
2 changed files with 12 additions and 3 deletions

View File

@ -132,9 +132,9 @@ class CheckIntegrity(QProgressDialog):
titles = [self.db.title(x, index_is_id=True) for x in bad]
det_msg = '\n'.join(titles)
warning_dialog(self, _('Some inconsistencies found'),
_('The following books had formats listed in the '
_('The following books had formats or covers listed in the '
'database that are not actually available. '
'The entries for the formats have been removed. '
'The entries for the formats/covers have been removed. '
'You should check them manually. This can '
'happen if you manipulate the files in the '
'library folder directly.'), det_msg=det_msg, show=True)

View File

@ -2509,11 +2509,20 @@ books_series_link feeds
if id not in bad:
bad[id] = []
bad[id].append(fmt)
has_cover = self.data.get(id, self.FIELD_MAP['cover'],
row_is_id=True)
if has_cover and self.cover(id, index_is_id=True, as_path=True) is None:
if id not in bad:
bad[id] = []
bad[id].append('COVER')
callback(0.1+0.9*(1+i)/total, _('Checked id') + ' %d'%id)
for id in bad:
for fmt in bad[id]:
self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, fmt.upper()))
if fmt != 'COVER':
self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, fmt.upper()))
else:
self.conn.execute('UPDATE books SET has_cover=0 WHERE id=?', (id,))
self.conn.commit()
self.refresh_ids(list(bad.keys()))