From 8f2db63977a79c853159c37691909ff1bfc01457 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 29 Jun 2007 21:56:21 +0000 Subject: [PATCH] Monotone-Parent: fdc4bd260e9bdf3cb16b0dd44f5aaacdc7cff37f Monotone-Revision: 3f1af1b61e725eb56f00438f4516a03bcff73a5a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-06-29T21:56:21 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 +++ Main/SOGo.m | 119 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5799c2aa5..e126dd915 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-06-29 Wolfgang Sourdeau + + * Main/SOGo.m ([SOGo -run]): override method and create the + missing system tables if needed. + 2007-06-28 Wolfgang Sourdeau * UI/MailerUI/WOContext+UIxMailer.m ([WOContext diff --git a/Main/SOGo.m b/Main/SOGo.m index b6406ceb9..218c14480 100644 --- a/Main/SOGo.m +++ b/Main/SOGo.m @@ -19,11 +19,37 @@ 02111-1307, USA. */ -#include +#import +#import +#import +#import +#import +#import + +#import +#import + +#import +#import +#import +#import + +#import +#import +#import +#import + +#import + +#import +#import +#import + +#import "SOGoProductLoader.h" @interface SOGo : SoApplication { - NSMutableDictionary *localeLUT; + NSMutableDictionary *localeLUT; } - (NSDictionary *) currentLocaleConsideringLanguages:(NSArray *)_langs; @@ -31,17 +57,11 @@ @end -#include "SOGoProductLoader.h" -#include -#include -#include -#include -#include "common.h" - @implementation SOGo static unsigned int vMemSizeLimit = 0; static BOOL doCrashOnSessionCreate = NO; +static BOOL hasCheckedTables = NO; #ifdef GNUSTEP_BASE_LIBRARY static BOOL debugObjectAllocation = NO; @@ -123,6 +143,83 @@ static BOOL debugObjectAllocation = NO; [super dealloc]; } +- (void) _checkTableWithCM: (GCSChannelManager *) cm + tableURL: (NSString *) url + andType: (NSString *) tableType +{ + NSString *tableName, *descFile; + EOAdaptorChannel *tc; + NGBundleManager *bm; + NSBundle *bundle; + unsigned int length; + + bm = [NGBundleManager defaultBundleManager]; + + tc = [cm acquireOpenChannelForURL: [NSURL URLWithString: url]]; + + tableName = [url lastPathComponent]; + if ([tc evaluateExpressionX: + [NSString stringWithFormat: @"SELECT count(*) FROM %@", tableName]]) + { + bundle = [bm bundleWithName: @"MainUI" type: @"SOGo"]; + length = [tableType length] - 3; + descFile = [bundle pathForResource: [tableType substringToIndex: length] + ofType: @"sql"]; + if (![tc evaluateExpressionX: + [NSString stringWithContentsOfFile: descFile]]) + [self logWithFormat: @"table '%@' successfully created!", tableName]; + } + else + NSLog (@"YES"); + + [cm releaseChannel: tc]; + +// [self terminate]; +// NSLog (@"not yet"); +} + +- (BOOL) _checkMandatoryTables +{ + GCSChannelManager *cm; + NSString *urlStrings[] = {@"AgenorProfileURL", @"OCSFolderInfoURL", nil}; + NSString **urlString; + NSString *value; + NSUserDefaults *ud; + BOOL ok; + + ud = [NSUserDefaults standardUserDefaults]; + ok = YES; + cm = [GCSChannelManager defaultChannelManager]; + + urlString = urlStrings; + while (ok && *urlString) + { + value = [ud stringForKey: *urlString]; + if (value) + { + [self _checkTableWithCM: cm tableURL: value andType: *urlString]; + urlString++; + } + else + { + NSLog (@"No value specified for '%@'", *urlString); + ok = NO; + } + } + + return ok; +} + +- (void) run +{ + if (!hasCheckedTables) + { + hasCheckedTables = YES; + [self _checkMandatoryTables]; + } + [super run]; +} + /* authenticator */ - (id) authenticatorInContext: (id) _ctx @@ -145,8 +242,8 @@ static BOOL debugObjectAllocation = NO; } - (id)lookupUser:(NSString *)_key inContext:(id)_ctx { - return [[[$(@"SOGoUserFolder") alloc] - initWithName:_key inContainer:self] autorelease]; + return [$(@"SOGoUserFolder") objectWithName:_key + inContainer: self]; } - (void) _setupLocaleInContext: (WOContext *) _ctx