Changeset 3990


Ignore:
Timestamp:
01/18/13 11:49:05 (19 months ago)
Author:
koke
Message:

On sync, change only pages that are synced

Location:
trunk/Classes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Classes/Blog.m

    r3989 r3990  
    898898    NSMutableArray *pagesToKeep = [NSMutableArray array]; 
    899899    for (NSDictionary *pageInfo in newPages) { 
    900         Page *newPage = [Page createOrReplaceFromDictionary:pageInfo forBlog:self]; 
    901         if (newPage != nil) { 
    902             [pagesToKeep addObject:newPage]; 
    903         } else { 
    904             WPFLog(@"-[Page createOrReplaceFromDictionary:forBlog:] returned a nil page: %@", pageInfo); 
    905         } 
     900        NSNumber *pageID = [[pageInfo objectForKey:@"postid"] numericValue]; 
     901        Page *newPage = [Page findOrCreateWithBlog:self andPageID:pageID]; 
     902        if (newPage.remoteStatus == AbstractPostRemoteStatusSync) { 
     903            [newPage updateFromDictionary:pageInfo]; 
     904        } 
     905        [pagesToKeep addObject:newPage]; 
    906906    } 
    907907 
  • trunk/Classes/Page.h

    r3633 r3990  
    1616 
    1717#pragma mark Class Methods 
    18 // Creates an empty local post associated with blog 
     18/** 
     19 Creates an empty local page associated with blog 
     20 */ 
    1921+ (Page *)newDraftForBlog:(Blog *)blog; 
    20 + (Page *)findWithBlog:(Blog *)blog andPostID:(NSNumber *)postID; 
    21 // Takes the NSDictionary from a XMLRPC call and creates or updates a post 
    22 + (Page *)createOrReplaceFromDictionary:(NSDictionary *)postInfo forBlog:(Blog *)blog; 
     22 
     23/** 
     24 Retrieves the page with the specified `pageID` for a given blog 
     25 
     26 @returns the specified page. Returns nil if there is no page with that id on the blog 
     27 */ 
     28+ (Page *)findWithBlog:(Blog *)blog andPageID:(NSNumber *)pageID; 
     29 
     30/** 
     31 Retrieves the page with the specified `pageID` for a given blog. If the specified page doesn't exist, a new empty one is created 
     32 
     33 @returns the specified page. 
     34 */ 
     35+ (Page *)findOrCreateWithBlog:(Blog *)blog andPageID:(NSNumber *)pageID; 
     36 
     37/** 
     38 Updates the page properties with the results of a XML-RPC call 
     39 
     40 @param pageInfo a dictionary with values returned from wp.getPages 
     41 */ 
     42- (void)updateFromDictionary:(NSDictionary *)pageInfo; 
    2343 
    2444@end 
  • trunk/Classes/Page.m

    r3714 r3990  
    5050} 
    5151 
    52 + (Page *)findWithBlog:(Blog *)blog andPostID:(NSNumber *)postID { 
    53     NSSet *results = [blog.posts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"postID == %@",postID]]; 
     52+ (Page *)findWithBlog:(Blog *)blog andPageID:(NSNumber *)pageID { 
     53    NSSet *results = [blog.posts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"postID == %@", pageID]]; 
    5454     
    5555    if (results && (results.count > 0)) { 
     
    5959} 
    6060 
    61 + (Page *)createOrReplaceFromDictionary:(NSDictionary *)postInfo forBlog:(Blog *)blog { 
    62     Page *page = [self findWithBlog:blog andPostID:[postInfo objectForKey:@"page_id"]]; 
    63      
     61+ (Page *)findOrCreateWithBlog:(Blog *)blog andPageID:(NSNumber *)pageID { 
     62    Page *page = [self findWithBlog:blog andPageID:pageID]; 
     63 
    6464    if (page == nil) { 
    65         page = [Page newPageForBlog:blog]; 
    66     } 
    67          
    68         [page updateFromDictionary:postInfo]; 
     65        page = [Page newDraftForBlog:blog]; 
     66        page.postID = pageID; 
     67    } 
    6968    return page; 
    7069} 
Note: See TracChangeset for help on using the changeset viewer.