Migrate legacy db stored logging preferences to NSUserDefaults
This is part of making sure we can log *before* the DB is initialized. // FREEBIE
This commit is contained in:
parent
2355c74173
commit
907e122d62
|
@ -28,6 +28,7 @@
|
|||
452ECA4D1E087E7200E2F016 /* MessageFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */; };
|
||||
452ECA4E1E087E7200E2F016 /* MessageFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */; };
|
||||
4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */; };
|
||||
45387B041E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */; };
|
||||
453D28B71D32BA5F00D523F0 /* OWSDisplayedMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B61D32BA5F00D523F0 /* OWSDisplayedMessage.m */; };
|
||||
453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||
453D28BB1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||
|
@ -572,6 +573,8 @@
|
|||
452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MessageFetcherJob.swift; path = Jobs/MessageFetcherJob.swift; sourceTree = "<group>"; };
|
||||
4531C9C21DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSQMessagesCollectionViewCell+OWS.h"; sourceTree = "<group>"; };
|
||||
4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMessagesCollectionViewCell+OWS.m"; sourceTree = "<group>"; };
|
||||
45387B021E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWS102MoveLoggingPreferenceToUserDefaults.h; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.h; sourceTree = "<group>"; };
|
||||
45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS102MoveLoggingPreferenceToUserDefaults.m; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.m; sourceTree = "<group>"; };
|
||||
453CC0361D08E1A60040EBA3 /* sn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sn; path = translations/sn.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
453D28B51D32BA5F00D523F0 /* OWSDisplayedMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDisplayedMessage.h; sourceTree = "<group>"; };
|
||||
453D28B61D32BA5F00D523F0 /* OWSDisplayedMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDisplayedMessage.m; sourceTree = "<group>"; };
|
||||
|
@ -1222,14 +1225,16 @@
|
|||
45666F731D9BFDB9008FE134 /* Migrations */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
45666F741D9BFE00008FE134 /* OWS100RemoveTSRecipientsMigration.h */,
|
||||
45666F751D9BFE00008FE134 /* OWS100RemoveTSRecipientsMigration.m */,
|
||||
45666F791D9C0533008FE134 /* OWSDatabaseMigration.h */,
|
||||
45666F7A1D9C0533008FE134 /* OWSDatabaseMigration.m */,
|
||||
45666F7C1D9C0814008FE134 /* OWSDatabaseMigrationRunner.h */,
|
||||
45666F7D1D9C0814008FE134 /* OWSDatabaseMigrationRunner.m */,
|
||||
45666F741D9BFE00008FE134 /* OWS100RemoveTSRecipientsMigration.h */,
|
||||
45666F751D9BFE00008FE134 /* OWS100RemoveTSRecipientsMigration.m */,
|
||||
4516E3FD1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.h */,
|
||||
4516E3FE1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.m */,
|
||||
45387B021E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.h */,
|
||||
45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */,
|
||||
);
|
||||
name = Migrations;
|
||||
sourceTree = "<group>";
|
||||
|
@ -2869,6 +2874,7 @@
|
|||
4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */,
|
||||
4516E3FF1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.m in Sources */,
|
||||
76EB05A818170B33006006FC /* RtpSocket.m in Sources */,
|
||||
45387B041E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */,
|
||||
E197B61818BBEC1A00F073E5 /* RemoteIOAudio.m in Sources */,
|
||||
B67ADDC41989FF8700E1A773 /* RPServerRequestsManager.m in Sources */,
|
||||
EF764C351DB67CC5000D9A87 /* UIViewController+CameraPermissions.m in Sources */,
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// Copyright © 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSDatabaseMigration.h"
|
||||
|
||||
@interface OWS102MoveLoggingPreferenceToUserDefaults : OWSDatabaseMigration
|
||||
|
||||
@end
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// Copyright © 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
|
||||
#import "DebugLogger.h"
|
||||
#import "Environment.h"
|
||||
#import "PropertyListPreferences.h"
|
||||
|
||||
// Increment a similar constant for every future DBMigration
|
||||
static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"102";
|
||||
|
||||
@implementation OWS102MoveLoggingPreferenceToUserDefaults
|
||||
|
||||
+ (NSString *)migrationId
|
||||
{
|
||||
return OWS102MoveLoggingPreferenceToUserDefaultsMigrationId;
|
||||
}
|
||||
|
||||
- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
DDLogWarn(@"[OWS102MoveLoggingPreferenceToUserDefaultsMigrationId] copying existing logging preference to "
|
||||
@"NSUserDefaults");
|
||||
|
||||
NSNumber *existingValue = [self.storageManager objectForKey:PropertyListPreferencesKeyEnableDebugLog
|
||||
inCollection:PropertyListPreferencesSignalDatabaseCollection];
|
||||
|
||||
if (existingValue) {
|
||||
DDLogInfo(@"%@ assigning existing value: %@", self.tag, existingValue);
|
||||
[[Environment preferences] setLoggingEnabled:[existingValue boolValue]];
|
||||
|
||||
if (![existingValue boolValue]) {
|
||||
DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.tag);
|
||||
// Since we're migrating, we didn't have the appropriate value on startup, and incorrectly started logging.
|
||||
[DebugLogger.sharedLogger disableFileLogging];
|
||||
} else {
|
||||
DDLogInfo(@"%@ Continuing to log after one-time log settings migration.", self.tag);
|
||||
}
|
||||
} else {
|
||||
DDLogInfo(@"%@ not assigning any value, since no previous value was stored.", self.tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
{
|
||||
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||
}
|
||||
|
||||
- (NSString *)tag
|
||||
{
|
||||
return self.class.tag;
|
||||
}
|
||||
|
||||
@end
|
|
@ -4,6 +4,7 @@
|
|||
#import "OWSDatabaseMigrationRunner.h"
|
||||
#import "OWS100RemoveTSRecipientsMigration.h"
|
||||
#import "OWS101ExistingUsersBlockOnIdentityChange.h"
|
||||
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -25,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
{
|
||||
return @[
|
||||
[[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:self.storageManager],
|
||||
[[OWS101ExistingUsersBlockOnIdentityChange alloc] initWithStorageManager:self.storageManager]
|
||||
[[OWS101ExistingUsersBlockOnIdentityChange alloc] initWithStorageManager:self.storageManager],
|
||||
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:self.storageManager]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ typedef NS_ENUM(NSUInteger, TSImageQuality) {
|
|||
TSImageQualityLow = 4
|
||||
};
|
||||
|
||||
// Used when migrating logging to NSUserDefaults.
|
||||
extern NSString *const PropertyListPreferencesSignalDatabaseCollection;
|
||||
extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
|
||||
|
||||
@interface PropertyListPreferences : NSObject
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
|
Loading…
Reference in New Issue