NCManageDatabase.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // NCManageDatabase.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 05/05/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. #import "NCManageDatabase.h"
  9. @implementation NCManageDatabase
  10. + (NCManageDatabase *)sharedManageDatabase {
  11. static NCManageDatabase *sharedManageDatabase;
  12. @synchronized(self)
  13. {
  14. if (!sharedManageDatabase) {
  15. sharedManageDatabase = [NCManageDatabase new];
  16. }
  17. return sharedManageDatabase;
  18. }
  19. }
  20. - (id)init
  21. {
  22. self = [super init];
  23. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  24. RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
  25. config.fileURL = [dirGroup URLByAppendingPathComponent:[appDatabaseNextcloud stringByAppendingPathComponent:k_databaseDefault]];
  26. // Set this as the configuration used for the default Realm
  27. [RLMRealmConfiguration setDefaultConfiguration:config];
  28. return self;
  29. }
  30. - (void)addActivityServer:(OCActivity *)activity account:(NSString *)account
  31. {
  32. DBActivity *dbActivity = [DBActivity new];
  33. dbActivity.account = account;
  34. dbActivity.action = @"Activity";
  35. dbActivity.date = activity.date;
  36. dbActivity.file = activity.file;
  37. dbActivity.idActivity = activity.idActivity;
  38. dbActivity.link = activity.link;
  39. dbActivity.note = activity.subject;
  40. dbActivity.type = k_activityTypeInfo;
  41. dbActivity.verbose = k_activityVerboseDefault;
  42. RLMRealm *realm = [RLMRealm defaultRealm];
  43. [realm beginWriteTransaction];
  44. [realm addObject:dbActivity];
  45. [realm commitWriteTransaction];
  46. }
  47. @end