chore(sogo-ealarms-notify): properly close all DB channels

This prevent MySQL from logging an error (Aborted connection to db).
pull/301/head
Francis Lachapelle 2021-08-12 15:39:12 -04:00
parent 7d07ddaffd
commit cf40a23b43
4 changed files with 39 additions and 6 deletions

View File

@ -51,6 +51,7 @@
- (void)releaseChannel:(EOAdaptorChannel *)_channel;
- (void)releaseChannel:(EOAdaptorChannel *)_channel
immediately:(BOOL)_immediately;
- (void) releaseAllChannels;
/* checking for tables */

View File

@ -399,6 +399,27 @@ static NSTimeInterval ChannelCollectionTimer = 5 * 60;
}
}
- (void) releaseAllChannels
{
EOAdaptorChannel *channel;
GCSChannelHandle *handle;
NSEnumerator *e;
e = [busyChannels objectEnumerator];
while ((handle = [e nextObject]))
{
[handle retain];
ASSIGN (handle->lastReleaseTime, [NSCalendarDate date]);
[busyChannels removeObject: handle];
channel = [handle channel];
if (debugPools)
[self logWithFormat: @"releaseAllChannels: freeing old channel (age %ds, %p) ", (int)[handle age], channel];
if ([channel isOpen])
[channel closeChannel];
[handle release];
}
}
/* checking for tables */
- (BOOL) canConnect: (NSURL *) _url

View File

@ -77,12 +77,12 @@
{
iCalCalendar *calendar;
GCSFolder *folder;
GCSFolderManager *fm;
NSDictionary *eventRecord;
folder = [[GCSFolderManager defaultFolderManager]
folderAtPath: [record objectForKey: @"c_path"]];
eventRecord = [folder
recordOfEntryWithName: [record objectForKey: @"c_name"]];
fm = [GCSFolderManager defaultFolderManager];
folder = [fm folderAtPath: [record objectForKey: @"c_path"]];
eventRecord = [folder recordOfEntryWithName: [record objectForKey: @"c_name"]];
calendar = [iCalCalendar parseSingleFromSource:
[eventRecord objectForKey: @"c_content"]];
@ -203,6 +203,7 @@
SOGoAppointmentFolder *container;
iCalEntityObject *entity;
GCSAlarmsFolder *af;
GCSFolderManager *fm;
iCalAlarm *alarm;
NSMutableArray *alarms;
NSDictionary *record;
@ -210,7 +211,8 @@
int count, max;
NSString *owner;
af = [[GCSFolderManager defaultFolderManager] alarmsFolder];
fm = [GCSFolderManager defaultFolderManager];
af = [fm alarmsFolder];
records = [af recordsForEntriesFromDate: fromDate toDate: toDate];
max = [records count];
alarms = [NSMutableArray arrayWithCapacity: max];

View File

@ -53,6 +53,9 @@
#import <Appointments/SOGoAptMailReminder.h>
#import <WEExtensions/WEResourceManager.h>
#import <GDLContentStore/GCSChannelManager.h>
#import <GDLContentStore/GCSFolderManager.h>
#import "SOGoEAlarmsNotifier.h"
@implementation SOGoEAlarmsNotifier
@ -225,6 +228,8 @@
- (BOOL) run
{
GCSChannelManager *cm;
GCSFolderManager *fm;
NSArray *arguments, *alarms;
NSCalendarDate *startDate, *toDate;
NSDictionary *d;
@ -270,7 +275,7 @@
hour: 0 minute: -5
second: 0]
toDate: toDate
withMetadata: metadata];
withMetadata: metadata];
max = [alarms count];
for (count = 0; count < max; count++)
@ -292,6 +297,10 @@
nameInContainer: [[d objectForKey: @"record"] objectForKey: @"c_name"]];
}
// GCSFolder has opened a channel; close it before ending the process
fm = [GCSFolderManager defaultFolderManager];
cm = [fm channelManager];
[cm releaseAllChannels];
return YES;
}