@@ -58,7 +58,7 @@ + (NSString *)databasePath;
58
58
59
59
// The current database version number
60
60
static NSInteger const VNAMinimumSupportedDatabaseVersion = 12 ;
61
- static NSInteger const VNACurrentDatabaseVersion = 23 ;
61
+ static NSInteger const VNACurrentDatabaseVersion = 24 ;
62
62
63
63
@implementation Database
64
64
@@ -459,26 +459,6 @@ -(void)createInitialSmartFolder:(NSString *)folderName withCriteria:(Criteria *)
459
459
}
460
460
}
461
461
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
-
482
462
/* countOfUnread
483
463
* Return the total number of unread articles in the database.
484
464
*/
@@ -1536,7 +1516,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
1536
1516
1537
1517
// use the given publication date if it is contained in the feed, or the earliest date available
1538
1518
NSDate * publicationDate = article.publicationDate ;
1539
- if (!publicationDate) {
1519
+ if (!publicationDate || [publicationDate timeIntervalSince1970 ] == 0 ) {
1540
1520
publicationDate = article.lastUpdate && [article.lastUpdate isLessThan: currentDate]
1541
1521
? article.lastUpdate
1542
1522
: currentDate;
@@ -1545,7 +1525,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
1545
1525
1546
1526
// if a last update date is not provided, use our publication date
1547
1527
NSDate * lastUpdate = article.lastUpdate ;
1548
- if (!lastUpdate) {
1528
+ if (!lastUpdate || [lastUpdate timeIntervalSince1970 ] == 0 ) {
1549
1529
lastUpdate = publicationDate;
1550
1530
article.lastUpdate = lastUpdate;
1551
1531
}
@@ -1605,7 +1585,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
1605
1585
* article was updated or NO if we couldn't update the article for
1606
1586
* some reason.
1607
1587
*/
1608
- -(BOOL )updateArticle: (Article *)existingArticle ofFolder: (NSInteger )folderID withArticle: (Article *)article
1588
+ -(BOOL )updateArticle: (Article *)existingArticle ofFolder: (NSInteger )folderID withArticle: (Article *)articleUpdate
1609
1589
{
1610
1590
// Exit now if we're read-only
1611
1591
if (self.readOnly ) {
@@ -1615,23 +1595,26 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
1615
1595
FMDatabaseQueue *queue = self.databaseQueue ;
1616
1596
1617
1597
// 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 ;
1625
1605
1626
1606
// 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
+ }
1630
1611
1631
1612
// we never change the publication date, unless the date provided in the feed is prior to it
1632
1613
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 ;
1635
1618
}
1636
1619
1637
1620
// Dates are stored as time intervals
@@ -1705,6 +1688,8 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
1705
1688
existingArticle.parentId = parentId;
1706
1689
existingArticle.author = userName;
1707
1690
existingArticle.link = articleLink;
1691
+ existingArticle.lastUpdate = lastUpdate;
1692
+ existingArticle.publicationDate = publicationDate;
1708
1693
return YES ;
1709
1694
}
1710
1695
} else {
0 commit comments