Adatbázis és szinkronizációs hibajavítások
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -482,7 +483,10 @@ class AppDatabase {
|
||||
Future<int> insertTrack(Track track) async {
|
||||
final db = await database;
|
||||
final map = _withSyncColumns(track.toMap());
|
||||
map['device_id'] ??= DeviceIdentityService.to.deviceId;
|
||||
map['device_id'] ??= Get.isRegistered<DeviceIdentityService>() &&
|
||||
DeviceIdentityService.to.isReady
|
||||
? DeviceIdentityService.to.appInstanceId
|
||||
: null;
|
||||
return db.insert('tracks', map);
|
||||
}
|
||||
|
||||
@@ -859,7 +863,10 @@ class AppDatabase {
|
||||
Future<int> insertMeasuredPoint(MeasuredPoint point) async {
|
||||
final db = await database;
|
||||
final map = _withSyncColumns(point.toMap());
|
||||
map['device_id'] ??= DeviceIdentityService.to.deviceId;
|
||||
map['device_id'] ??= Get.isRegistered<DeviceIdentityService>() &&
|
||||
DeviceIdentityService.to.isReady
|
||||
? DeviceIdentityService.to.appInstanceId
|
||||
: null;
|
||||
return db.insert('measured_points', map);
|
||||
}
|
||||
|
||||
@@ -951,7 +958,11 @@ class AppDatabase {
|
||||
Future<int> insertStakeoutPoint(StakeoutPoint p) async {
|
||||
final db = await database;
|
||||
final map = p.toMap();
|
||||
map['device_id'] ??= DeviceIdentityService.to.deviceId;
|
||||
map['device_id'] ??= Get.isRegistered<DeviceIdentityService>() &&
|
||||
DeviceIdentityService.to.isReady
|
||||
? DeviceIdentityService.to.appInstanceId
|
||||
: null;
|
||||
;
|
||||
return db.insert('stakeout_points', map);
|
||||
}
|
||||
|
||||
@@ -971,7 +982,10 @@ class AppDatabase {
|
||||
limit: 1);
|
||||
if (dup.isNotEmpty) continue;
|
||||
final map = p.toMap();
|
||||
map['device_id'] ??= DeviceIdentityService.to.deviceId;
|
||||
map['device_id'] ??= Get.isRegistered<DeviceIdentityService>() &&
|
||||
DeviceIdentityService.to.isReady
|
||||
? DeviceIdentityService.to.appInstanceId
|
||||
: null;
|
||||
await txn.insert('stakeout_points', map);
|
||||
inserted++;
|
||||
}
|
||||
@@ -1249,4 +1263,18 @@ class AppDatabase {
|
||||
await db.insert('imported_layers', map,
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
|
||||
/// Egyszeri javítás: a korábban ANDROID_ID-vel (vagy üresen) beírt
|
||||
/// device_id-k cseréje az appInstanceId-re. A sorok ezen az eszközön
|
||||
/// keletkeztek, így a csere helyes; a sync_status visszaáll pending-re,
|
||||
/// hogy a helyes érték felmenjen.
|
||||
Future<void> repairDeviceIds(String correctId) async {
|
||||
final db = await database;
|
||||
for (final t in ['measured_points', 'tracks', 'stakeout_points']) {
|
||||
await db.rawUpdate(
|
||||
"UPDATE $t SET device_id = ?, sync_status = 'pending' "
|
||||
"WHERE device_id IS NOT NULL AND length(device_id) <> 36",
|
||||
[correctId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user