From e52328c9e5b8bd5eecfc4adca7894e361a21bb03 Mon Sep 17 00:00:00 2001 From: "mozilla.mano@sent.com" Date: Wed, 11 Jul 2007 15:38:13 -0700 Subject: [PATCH] Bug 385828 - Insertion, removal and move operations of items should update the last-modified field of their containing folder. r=dietrich. --- .../src/nsPlacesImportExportService.cpp | 11 +++++- .../components/places/src/nsNavBookmarks.cpp | 38 +++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/browser/components/places/src/nsPlacesImportExportService.cpp b/browser/components/places/src/nsPlacesImportExportService.cpp index da7f9db6d556..9b1b676809d5 100644 --- a/browser/components/places/src/nsPlacesImportExportService.cpp +++ b/browser/components/places/src/nsPlacesImportExportService.cpp @@ -650,8 +650,17 @@ BookmarkContentSink::HandleContainerEnd() BookmarkImportFrame& frame = CurFrame(); if (frame.mContainerNesting > 0) frame.mContainerNesting --; - if (mFrames.Length() > 1 && frame.mContainerNesting == 0) + if (mFrames.Length() > 1 && frame.mContainerNesting == 0) { + // we also need to re-set the imported last-modified date here. Otherwise + // the addition of items will override the imported field. + BookmarkImportFrame& prevFrame = PreviousFrame(); + if (prevFrame.mPreviousLastModifiedDate > 0) { + nsresult rv = mBookmarksService->SetItemLastModified(frame.mContainerID, + prevFrame.mPreviousLastModifiedDate); + NS_ASSERTION(NS_SUCCEEDED(rv), "SetItemLastModified failed"); + } PopFrame(); + } } diff --git a/toolkit/components/places/src/nsNavBookmarks.cpp b/toolkit/components/places/src/nsNavBookmarks.cpp index d57497ad75bb..7d31a82c4e5f 100644 --- a/toolkit/components/places/src/nsNavBookmarks.cpp +++ b/toolkit/components/places/src/nsNavBookmarks.cpp @@ -939,6 +939,9 @@ nsNavBookmarks::InsertBookmark(PRInt64 aFolder, nsIURI *aItem, PRInt32 aIndex, NS_ENSURE_SUCCESS(rv, rv); *aNewBookmarkId = rowId; + rv = SetItemLastModified(aFolder, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -993,6 +996,9 @@ nsNavBookmarks::RemoveItem(PRInt64 aItemId) NS_ENSURE_SUCCESS(rv, rv); } + rv = SetItemLastModified(folderId, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -1076,7 +1082,10 @@ nsNavBookmarks::CreateFolderWithID(PRInt64 aFolder, PRInt64 aParent, PRInt64 id; rv = dbConn->GetLastInsertRowID(&id); NS_ENSURE_SUCCESS(rv, rv); - + + rv = SetItemLastModified(aParent, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -1168,6 +1177,9 @@ nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex, NS_ENSURE_SUCCESS(rv, rv); *aNewItemId = rowId; + rv = SetItemLastModified(aParent, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -1304,6 +1316,9 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFolder) rv = AdjustIndices(parent, index + 1, PR_INT32_MAX, -1); NS_ENSURE_SUCCESS(rv, rv); + rv = SetItemLastModified(parent, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -1530,6 +1545,12 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex) rv = dbConn->ExecuteSimpleSQL(buffer); NS_ENSURE_SUCCESS(rv, rv); + PRTime now = PR_Now(); + rv = SetItemLastModified(oldParent, now); + NS_ENSURE_SUCCESS(rv, rv); + rv = SetItemLastModified(aNewParent, now); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -1695,10 +1716,10 @@ nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsAString &aTitle) rv = statement->Execute(); NS_ENSURE_SUCCESS(rv, rv); - rv = transaction.Commit(); + rv = SetItemLastModified(aItemId, PR_Now()); NS_ENSURE_SUCCESS(rv, rv); - rv = SetItemLastModified(aItemId, PR_Now()); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver, @@ -2066,6 +2087,9 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI *aNewURI) rv = statement->Execute(); NS_ENSURE_SUCCESS(rv, rv); + rv = SetItemLastModified(aBookmarkId, PR_Now()); + NS_ENSURE_SUCCESS(rv, rv); + rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); @@ -2073,9 +2097,6 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI *aNewURI) rv = aNewURI->GetSpec(spec); NS_ENSURE_SUCCESS(rv, rv); - rv = SetItemLastModified(aBookmarkId, PR_Now()); - NS_ENSURE_SUCCESS(rv, rv); - // Pass the new URI to OnItemChanged. ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver, OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("uri"), PR_FALSE, spec)) @@ -2271,11 +2292,12 @@ nsNavBookmarks::SetKeywordForBookmark(PRInt64 aBookmarkId, const nsAString& aKey NS_ENSURE_SUCCESS(rv, rv); rv = updateKeywordStmnt->Execute(); NS_ENSURE_SUCCESS(rv, rv); - transaction.Commit(); - + rv = SetItemLastModified(aBookmarkId, PR_Now()); NS_ENSURE_SUCCESS(rv, rv); + transaction.Commit(); + // Pass the new keyword to OnItemChanged. ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver, OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("keyword"),