home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbMigrate08pre2To08pre3.js < prev    next >
Text File  |  2012-06-08  |  7KB  |  160 lines

  1. /*
  2. //
  3. // BEGIN SONGBIRD GPL
  4. //
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. //
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. //
  13. // Software distributed under the License is distributed
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
  15. // express or implied. See the GPL for the specific language
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc.,
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. //
  23. // END SONGBIRD GPL
  24. //
  25. */
  26.  
  27. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  28. Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
  29. Components.utils.import("resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
  30. Components.utils.import("resource://app/jsmodules/SBJobUtils.jsm");
  31.  
  32. const Cc = Components.classes;
  33. const Ci = Components.interfaces;
  34. const Cr = Components.results;
  35.  
  36. function LOG(s) {
  37.   dump("----++++----++++sbLibraryMigration " + 
  38.        sbLibraryMigration.versionString + ": " + 
  39.        s + 
  40.        "\n----++++----++++\n");
  41. }
  42.  
  43. function sbLibraryMigration()
  44. {
  45.   SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(this);
  46.   
  47.   this.fromVersion = 10;
  48.   this.toVersion   = 11;
  49.   this.versionString = this.fromVersion + " to " + 
  50.                        this.toVersion;
  51. }
  52.  
  53. //-----------------------------------------------------------------------------
  54. // sbLocalDatabaseMigration Implementation
  55. //-----------------------------------------------------------------------------
  56.  
  57. sbLibraryMigration.prototype = {
  58.   __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
  59.  
  60.   classDescription: 'Songbird Migration Handler, version ' + this.versionString,
  61.   classID: Components.ID("{62bb8fb0-8fd8-11dd-ad8b-0800200c9a66}"),
  62.   contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID + "10 to 11",
  63.  
  64.   _databaseLocation: null,
  65.   _databaseGUID: null,
  66.   
  67.   _mediaItems: null,
  68.   
  69.   migrate: function sbLibraryMigration_migrate(aLibrary) {
  70.     this._databaseGUID = aLibrary.databaseGuid;
  71.     this._databaseLocation = aLibrary.databaseLocation;
  72.  
  73.     var query = this._createQuery();
  74.  
  75.     query.addQuery("begin");
  76.  
  77.     // Add the new secondary sort column
  78.     query.addQuery("alter table resource_properties add obj_secondary_sortable text");
  79.  
  80.     // Rebuild a new properties index
  81.     query.addQuery("drop index idx_resource_properties_property_id_obj_sortable_media_item_id");
  82.     query.addQuery("create index idx_resource_properties_property_id_obj_sortable_obj_secondary_sortable_media_item_id " + 
  83.                    "on resource_properties (property_id, obj_sortable, obj_secondary_sortable, media_item_id);");
  84.  
  85.     // Update analyze table
  86.     query.addQuery("delete from sqlite_stat1");
  87.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('simple_media_lists','idx_simple_media_lists_media_item_id_ordinal','10003 5002 1');");
  88.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('simple_media_lists','idx_simple_media_lists_member_media_item_id','10003 2');");
  89.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('simple_media_lists','idx_simple_media_lists_media_item_id_member_media_item_id','10003 5002 1 1');");
  90.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('resource_properties','idx_resource_properties_property_id_obj_sortable_obj_secondary_sortable_media_item_id','133429 3707 6 4 1');");
  91.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('resource_properties','sqlite_autoindex_resource_properties_1','133429 14 1');");
  92.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('properties','sqlite_autoindex_properties_1','89 1');");
  93.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('library_media_item','sqlite_autoindex_library_media_item_1','1 1');");
  94.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('resource_properties_fts_all_segdir','sqlite_autoindex_resource_properties_fts_all_segdir_1','18 6 1');");
  95.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_list_types','sqlite_autoindex_media_list_types_1','3 1');");
  96.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_hidden_media_list_type_id','10009 5005 2');");
  97.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_is_list','10009 5005');");
  98.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_media_list_type_id','10009 2');");
  99.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_content_url','10009 1');");
  100.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_created','10009 12');");
  101.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','idx_media_items_hidden','10009 5005');");
  102.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('media_items','sqlite_autoindex_media_items_1','10009 1');");
  103.     query.addQuery("INSERT INTO sqlite_stat1 VALUES('library_metadata','sqlite_autoindex_library_metadata_1','2 1');");
  104.  
  105.     // Update the schema version to the destination version.
  106.     query.addQuery("update library_metadata set value = '" 
  107.                    + this.toVersion + "' where name = 'version'");
  108.     query.addQuery("commit");
  109.  
  110.     // Try to reduce db size
  111.     query.addQuery("VACUUM");
  112.  
  113.     var retval;
  114.     query.setAsyncQuery(true);
  115.     query.execute(retval);
  116.     
  117.     var sip = Cc["@mozilla.org/supports-interface-pointer;1"]
  118.                 .createInstance(Ci.nsISupportsInterfacePointer);
  119.     sip.data = this;
  120.     
  121.     this._titleText = "Library Migration Helper";
  122.     this._statusText = "Optimizing sort performance...";
  123.     this.migrationQuery = query;
  124.     
  125.     this.startNotificationTimer();
  126.     SBJobUtils.showProgressDialog(sip.data, null, 0);
  127.     this.stopNotificationTimer();
  128.     
  129.     // Raise a flag indicating that this library will need all 
  130.     // sort info to be recomputed.
  131.     // Normally we'd call propertyCache.invalidateSortData(), but 
  132.     // at this point in startup the property cache does not exist yet.
  133.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  134.                        .getService(Components.interfaces.nsIPrefBranch);
  135.     prefs.setBoolPref("songbird.propertycache." + 
  136.         this._databaseGUID + ".invalidSortData", true);
  137.     prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
  138.   },
  139.   
  140.   _createQuery: function sbLibraryMigration_createQuery() {
  141.     var query = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
  142.                   .createInstance(Ci.sbIDatabaseQuery);
  143.     query.databaseLocation = this._databaseLocation;
  144.     query.setDatabaseGUID(this._databaseGUID);
  145.     
  146.     return query;
  147.   }
  148. }
  149.  
  150.  
  151. //
  152. // Module
  153. // 
  154.  
  155. function NSGetModule(compMgr, fileSpec) {
  156.   return XPCOMUtils.generateModule([
  157.     sbLibraryMigration
  158.   ]);
  159. }
  160.