Bug 477793 - Make sure preventive maintenance cannot act on roots, r=sdwilsh a=blocking191

This commit is contained in:
Marco Bonardo 2009-02-11 11:53:35 +01:00
parent 0a3c623098
commit 10063403f7
2 changed files with 36 additions and 11 deletions

View File

@ -282,7 +282,9 @@ nsPlacesDBUtils.prototype = {
// D.1 remove items without a valid place
// if fk IS NULL we fix them in D.7
let deleteNoPlaceItems = this._dbConn.createStatement(
"DELETE FROM moz_bookmarks WHERE id IN (" +
"DELETE FROM moz_bookmarks WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN (" +
"SELECT b.id FROM moz_bookmarks b " +
"WHERE fk NOT NULL AND b.type = :bookmark_type " +
"AND NOT EXISTS (SELECT url FROM moz_places_temp WHERE id = b.fk LIMIT 1) " +
@ -293,7 +295,9 @@ nsPlacesDBUtils.prototype = {
// D.2 remove items that are not uri bookmarks from tag containers
let deleteBogusTagChildren = this._dbConn.createStatement(
"DELETE FROM moz_bookmarks WHERE id IN (" +
"DELETE FROM moz_bookmarks WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN (" +
"SELECT b.id FROM moz_bookmarks b " +
"WHERE b.parent IN " +
"(SELECT id FROM moz_bookmarks WHERE parent = :tags_folder) " +
@ -305,7 +309,9 @@ nsPlacesDBUtils.prototype = {
// D.3 remove empty tags
let deleteEmptyTags = this._dbConn.createStatement(
"DELETE FROM moz_bookmarks WHERE id IN (" +
"DELETE FROM moz_bookmarks WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN (" +
"SELECT b.id FROM moz_bookmarks b " +
"WHERE b.id IN " +
"(SELECT id FROM moz_bookmarks WHERE parent = :tags_folder) " +
@ -317,9 +323,11 @@ nsPlacesDBUtils.prototype = {
// D.4 move orphan items to unsorted folder
let fixOrphanItems = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET parent = :unsorted_folder WHERE id IN (" +
"UPDATE moz_bookmarks SET parent = :unsorted_folder WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN (" +
"SELECT b.id FROM moz_bookmarks b " +
"WHERE b.parent <> 0 " + // exclude root
"WHERE b.parent <> 0 " + // exclude Places root
"AND NOT EXISTS " +
"(SELECT id FROM moz_bookmarks WHERE id = b.parent LIMIT 1) " +
")");
@ -328,7 +336,9 @@ nsPlacesDBUtils.prototype = {
// D.5 fix wrong keywords
let fixInvalidKeywords = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET keyword_id = NULL WHERE id IN ( " +
"UPDATE moz_bookmarks SET keyword_id = NULL WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN ( " +
"SELECT id FROM moz_bookmarks b " +
"WHERE keyword_id NOT NULL " +
"AND NOT EXISTS " +
@ -341,7 +351,9 @@ nsPlacesDBUtils.prototype = {
// If they have a valid fk convert them to bookmarks. Later in D.9 we
// will move eventual children to unsorted bookmarks.
let fixBookmarksAsFolders = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET type = :bookmark_type WHERE id IN ( " +
"UPDATE moz_bookmarks SET type = :bookmark_type WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN ( " +
"SELECT id FROM moz_bookmarks b " +
"WHERE type IN (:folder_type, :separator_type, :dynamic_type) " +
"AND fk NOTNULL " +
@ -356,7 +368,9 @@ nsPlacesDBUtils.prototype = {
// Bookmarks should have an fk, if they don't have any, convert them to
// folders.
let fixFoldersAsBookmarks = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET type = :folder_type WHERE id IN ( " +
"UPDATE moz_bookmarks SET type = :folder_type WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN ( " +
"SELECT id FROM moz_bookmarks b " +
"WHERE type = :bookmark_type " +
"AND fk IS NULL " +
@ -369,7 +383,9 @@ nsPlacesDBUtils.prototype = {
// Dynamic containers should have a folder_type, if they don't have any
// convert them to folders.
let fixFoldersAsDynamic = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET type = :folder_type WHERE id IN ( " +
"UPDATE moz_bookmarks SET type = :folder_type WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN ( " +
"SELECT id FROM moz_bookmarks b " +
"WHERE type = :dynamic_type " +
"AND folder_type IS NULL " +
@ -382,7 +398,9 @@ nsPlacesDBUtils.prototype = {
// Items cannot have dynamic containers, separators or other bookmarks
// as parent, if they have bad parent move them to unsorted bookmarks.
let fixInvalidParents = this._dbConn.createStatement(
"UPDATE moz_bookmarks SET parent = :unsorted_folder WHERE id IN ( " +
"UPDATE moz_bookmarks SET parent = :unsorted_folder WHERE id NOT IN ( " +
"SELECT folder_id FROM moz_bookmarks_roots " + // skip roots
") AND id IN ( " +
"SELECT id FROM moz_bookmarks b " +
"WHERE EXISTS " +
"(SELECT id FROM moz_bookmarks WHERE id = b.parent " +
@ -430,9 +448,10 @@ nsPlacesDBUtils.prototype = {
// status items bookmarks inside it. We should remove them.
// Note: This does not need to query the temp table.
let removeLivemarkStaticItems = this._dbConn.createStatement(
"DELETE FROM moz_bookmarks WHERE fk IN ( " +
"DELETE FROM moz_bookmarks WHERE type = :bookmark_type AND fk IN ( " +
"SELECT id FROM moz_places WHERE url = :lmloading OR url = :lmfailed " +
")");
removeLivemarkStaticItems.params["bookmark_type"] = this._bms.TYPE_BOOKMARK;
removeLivemarkStaticItems.params["lmloading"] = "about:livemark-loading";
removeLivemarkStaticItems.params["lmfailed"] = "about:livemark-failed";
cleanupStatements.push(removeLivemarkStaticItems);

View File

@ -1103,6 +1103,12 @@ let observer = {
}
else {
os.removeObserver(this, FINISHED_MAINTANANCE_NOTIFICATION_TOPIC);
// Sanity check: all roots should be intact
do_check_eq(bs.getFolderIdForItem(bs.placesRoot), 0);
do_check_eq(bs.getFolderIdForItem(bs.bookmarksMenuFolder), bs.placesRoot);
do_check_eq(bs.getFolderIdForItem(bs.tagsFolder), bs.placesRoot);
do_check_eq(bs.getFolderIdForItem(bs.unfiledBookmarksFolder), bs.placesRoot);
do_check_eq(bs.getFolderIdForItem(bs.toolbarFolder), bs.placesRoot);
do_test_finished();
}
}