|
|
|
|
@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.migrations |
|
|
|
|
import android.content.Context |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.PokerAnalyticsApplication |
|
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
@ -17,7 +18,9 @@ class Patcher { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
fun patchAll(context: Context) { |
|
|
|
|
fun patchAll(application: PokerAnalyticsApplication) { |
|
|
|
|
|
|
|
|
|
val context = application.applicationContext |
|
|
|
|
|
|
|
|
|
// NOTE: it's more than possible that at one point many patches become redundant |
|
|
|
|
// with each other |
|
|
|
|
@ -54,18 +57,8 @@ class Patcher { |
|
|
|
|
patchZeroTable() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
patchPerformances(application) |
|
|
|
|
|
|
|
|
|
private fun patchZeroTable() { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val zero = 0 |
|
|
|
|
val sessions = realm.where<Session>().equalTo("numberOfTables", zero).findAll() |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
sessions.forEach { s -> |
|
|
|
|
s.numberOfTables = 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun patchMissingTransactionTypes(context: Context) { |
|
|
|
|
@ -195,6 +188,29 @@ class Patcher { |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun patchPerformances(application: PokerAnalyticsApplication) { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val sessionCount = realm.where<Session>().findAll().size |
|
|
|
|
val performanceCount = realm.where<Performance>().findAll().size |
|
|
|
|
|
|
|
|
|
if (sessionCount > 1 && performanceCount == 0) { |
|
|
|
|
application.reportWhistleBlower?.launchReportTask() |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun patchZeroTable() { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val zero = 0 |
|
|
|
|
val sessions = realm.where<Session>().equalTo("numberOfTables", zero).findAll() |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
sessions.forEach { s -> |
|
|
|
|
s.numberOfTables = 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |