Skip to content

Commit 86a8973

Browse files
authored
Merge pull request #383 from Scriptbash/fix-duplicate
Fix creating duplicate journal in cloud when issn is empty
2 parents 8699dc8 + 7ffaecc commit 86a8973

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/services/sync_service.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,29 @@ class SyncManager {
143143
.map((i) => i.get<String>('issn'))
144144
.toSet();
145145

146+
bool isMatch = false;
146147
// If an issn match I merge them to avoid duplicates
147148
if (localIssnSet.intersection(cloudIssnSet).isNotEmpty) {
149+
isMatch = true;
150+
} else if (localIssnSet.isEmpty || cloudIssnSet.isEmpty) {
151+
String localPub = (potentialMatch['publisher'] ?? '')
152+
.toString()
153+
.toLowerCase()
154+
.trim();
155+
String cloudPub =
156+
r.get<String>('publisher', '').toLowerCase().trim();
157+
158+
if (localPub.isEmpty ||
159+
cloudPub.isEmpty ||
160+
localPub.contains(cloudPub) ||
161+
cloudPub.contains(localPub)) {
162+
isMatch = true;
163+
}
164+
}
165+
166+
if (isMatch) {
148167
logger.info(
149-
"Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId via ISSN match.");
168+
"Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId.");
150169
await db.update('journals', {'sync_id': cloudSyncId},
151170
where: 'journal_id = ?', whereArgs: [localId]);
152171

0 commit comments

Comments
 (0)