Skip to content

Commit dd995ef

Browse files
authored
Merge pull request #1836 from TAKeanice/zero-article-dates
Correct feeds with creation date of 1.1.1970
2 parents a108bb2 + dc458c4 commit dd995ef

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

Vienna/Sources/Database/Database+Migration.m

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ + (void)migrateDatabase:(FMDatabase *)database
250250
database.userVersion = (uint32_t)23;
251251
NSLog(@"Updated database schema to version 23.");
252252
}
253+
case 24: {
254+
//correct articles that were saved with updatedDate is 1.1.1970 00:00
255+
[database executeStatements:@"UPDATE messages SET date = createddate WHERE date = 0"];
256+
257+
database.userVersion = (uint32_t)24;
258+
NSLog(@"Updated database schema to version 24.");
259+
}
253260
}
254261
}
255262

Vienna/Sources/Database/Database.h

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ extern NSNotificationName const VNADatabaseDidDeleteFolderNotification;
4646

4747
// General database functions
4848
- (instancetype)initWithDatabaseAtPath:(NSString *)dbPath /*NS_DESIGNATED_INITIALIZER*/;
49-
-(void)syncLastUpdate;
5049
-(void)compactDatabase;
5150
-(void)reindexDatabase;
5251
@property (nonatomic, readonly) NSInteger countOfUnread;

Vienna/Sources/Database/Database.m

+21-36
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ + (NSString *)databasePath;
5858

5959
// The current database version number
6060
static NSInteger const VNAMinimumSupportedDatabaseVersion = 12;
61-
static NSInteger const VNACurrentDatabaseVersion = 23;
61+
static NSInteger const VNACurrentDatabaseVersion = 24;
6262

6363
@implementation Database
6464

@@ -459,26 +459,6 @@ -(void)createInitialSmartFolder:(NSString *)folderName withCriteria:(Criteria *)
459459
}
460460
}
461461

462-
/* syncLastUpdate
463-
* Call this function to update the field in the info table which contains the last_updated
464-
* date. This is basically auditing data and is only called when the database is first opened
465-
* in this session.
466-
*/
467-
-(void)syncLastUpdate
468-
{
469-
__block BOOL success;
470-
471-
[self.databaseQueue inDatabase:^(FMDatabase *db) {
472-
success = [db executeUpdate:@"UPDATE info SET last_opened=?", [NSDate date]];
473-
474-
}];
475-
if (success) {
476-
self.readOnly = NO;
477-
} else {
478-
self.readOnly = YES;
479-
}
480-
}
481-
482462
/* countOfUnread
483463
* Return the total number of unread articles in the database.
484464
*/
@@ -1536,7 +1516,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
15361516

15371517
// use the given publication date if it is contained in the feed, or the earliest date available
15381518
NSDate * publicationDate = article.publicationDate;
1539-
if (!publicationDate) {
1519+
if (!publicationDate || [publicationDate timeIntervalSince1970] == 0) {
15401520
publicationDate = article.lastUpdate && [article.lastUpdate isLessThan:currentDate]
15411521
? article.lastUpdate
15421522
: currentDate;
@@ -1545,7 +1525,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
15451525

15461526
// if a last update date is not provided, use our publication date
15471527
NSDate * lastUpdate = article.lastUpdate;
1548-
if (!lastUpdate) {
1528+
if (!lastUpdate || [lastUpdate timeIntervalSince1970] == 0) {
15491529
lastUpdate = publicationDate;
15501530
article.lastUpdate = lastUpdate;
15511531
}
@@ -1605,7 +1585,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
16051585
* article was updated or NO if we couldn't update the article for
16061586
* some reason.
16071587
*/
1608-
-(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID withArticle:(Article *)article
1588+
-(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID withArticle:(Article *)articleUpdate
16091589
{
16101590
// Exit now if we're read-only
16111591
if (self.readOnly) {
@@ -1615,23 +1595,26 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16151595
FMDatabaseQueue *queue = self.databaseQueue;
16161596

16171597
// Extract the data from the new state of article
1618-
NSString * articleBody = article.body;
1619-
NSString * articleTitle = article.title;
1620-
NSString * articleLink = article.link.vna_trimmed;
1621-
NSString * userName = article.author.vna_trimmed;
1622-
NSString * articleGuid = article.guid;
1623-
NSInteger parentId = article.parentId;
1624-
BOOL revised_flag = article.revised;
1598+
NSString * articleBody = articleUpdate.body;
1599+
NSString * articleTitle = articleUpdate.title;
1600+
NSString * articleLink = articleUpdate.link.vna_trimmed;
1601+
NSString * userName = articleUpdate.author.vna_trimmed;
1602+
NSString * articleGuid = articleUpdate.guid;
1603+
NSInteger parentId = articleUpdate.parentId;
1604+
BOOL revised_flag = articleUpdate.revised;
16251605

16261606
// keep last update date the same if not set in the current version of the article
1627-
NSDate * lastUpdate = article.lastUpdate && [article.lastUpdate isGreaterThan:existingArticle.lastUpdate]
1628-
? article.lastUpdate
1629-
: existingArticle.lastUpdate;
1607+
NSDate * lastUpdate = existingArticle.lastUpdate;
1608+
if (articleUpdate.lastUpdate && [articleUpdate.lastUpdate isGreaterThan:lastUpdate]) {
1609+
lastUpdate = articleUpdate.lastUpdate;
1610+
}
16301611

16311612
// we never change the publication date, unless the date provided in the feed is prior to it
16321613
NSDate * publicationDate = existingArticle.publicationDate;
1633-
if (article.publicationDate && [article.publicationDate isLessThan:existingArticle.publicationDate]) {
1634-
publicationDate = article.publicationDate;
1614+
if (articleUpdate.publicationDate
1615+
&& [articleUpdate.publicationDate timeIntervalSince1970] > 0
1616+
&& [articleUpdate.publicationDate isLessThan:publicationDate]) {
1617+
publicationDate = articleUpdate.publicationDate;
16351618
}
16361619

16371620
// Dates are stored as time intervals
@@ -1705,6 +1688,8 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
17051688
existingArticle.parentId = parentId;
17061689
existingArticle.author = userName;
17071690
existingArticle.link = articleLink;
1691+
existingArticle.lastUpdate = lastUpdate;
1692+
existingArticle.publicationDate = publicationDate;
17081693
return YES;
17091694
}
17101695
} else {

0 commit comments

Comments
 (0)