home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbMigrate061to070.js < prev    next >
Text File  |  2012-06-08  |  7KB  |  210 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("----++++----++++\nsbLocalDatabaseMigrate061to070 ---> " + 
  38. //       s + 
  39. //       "\n----++++----++++\n");
  40. }
  41.  
  42. function sbLocalDatabaseMigrate061to070()
  43. {
  44.   SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(this);
  45.   
  46.   this.fromVersion = 5;
  47.   this.toVersion   = 6;
  48.   
  49.   this._propertyNames = {};
  50.   this._resourceProperties = [];
  51.   
  52.   this._propertyManager = Cc["@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
  53.                             .getService(Ci.sbIPropertyManager);
  54. }
  55.  
  56. //-----------------------------------------------------------------------------
  57. // sbLocalDatabaseMigration Implementation
  58. //-----------------------------------------------------------------------------
  59.  
  60. sbLocalDatabaseMigrate061to070.prototype = {
  61.   __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
  62.  
  63.   classDescription: 'Songbird Migration Handler for 0.6.1 to 0.7.0',
  64.   classID: Components.ID("{54A1D507-D085-4bfe-B729-1FFA13291C24}"),
  65.   contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID + "0.6.1 to 0.7.0",
  66.   
  67.   _databaseLocation: null,
  68.   _databaseGUID: null,
  69.   
  70.   _propertyNames: null,
  71.   _resourceProperties: null,
  72.   
  73.   _propertyManager: null,
  74.   
  75.   migrate: function sbLDBM061to070_migrate(aLibrary) {
  76.     this._databaseGUID = aLibrary.databaseGuid;
  77.     this._databaseLocation = aLibrary.databaseLocation;
  78.     
  79.     this._getPropertyNames();
  80.     this._getResourceProperties();
  81.  
  82.     var query = this._createQuery();
  83.     query.addQuery("begin");
  84.  
  85.     // Update all resource_properties entries that are text properties.
  86.     // Regenerate all sortable values for these properties.    
  87.     for(let i = 0; i < this._resourceProperties.length; ++i) {
  88.       let propertyId = this._propertyNames[this._resourceProperties[i].propId];
  89.       let mediaItemId = this._resourceProperties[i].itemId;
  90.       let value = this._resourceProperties[i].o;
  91.       
  92.       if(this._propertyManager.hasProperty(propertyId)) {
  93.         let propertyInfo = this._propertyManager.getPropertyInfo(propertyId);
  94.         if(propertyInfo.type == "text") {
  95.           let str = "update resource_properties set obj_sortable = ? where media_item_id = ? and property_id = ?";
  96.           
  97.           query.addQuery(str);
  98.           
  99.           let sortableValue = propertyInfo.makeSortable(value);
  100.           
  101.           query.bindStringParameter(0, sortableValue);
  102.           query.bindStringParameter(1, mediaItemId);
  103.           query.bindStringParameter(2, this._resourceProperties[i].propId);
  104.           
  105.           LOG("update resource_properties set obj_sortable = " + 
  106.               sortableValue + 
  107.               " where media_item_id = " + 
  108.               mediaItemId + 
  109.               " and property_id = " + this._resourceProperties[i].propId);
  110.         }
  111.       }
  112.     }
  113.     
  114.     // Update the FTS table with the new values. Sadly this means we have to 
  115.     // regenerate the _entire_ FTS table :(
  116.  
  117.     // First, drop the table.
  118.     query.addQuery("drop table resource_properties_fts_all");
  119.     
  120.     // Second, create the table anew.
  121.     query.addQuery("create virtual table resource_properties_fts_all using FTS3 ( alldata )");
  122.     
  123.     // Third, load the data in.
  124.     var ftsDataSub = "select media_item_id, group_concat(obj_sortable) from resource_properties group by media_item_id";
  125.     var ftsLoadData = "insert into resource_properties_fts_all (rowid, alldata) " + ftsDataSub;
  126.     
  127.     query.addQuery(ftsLoadData);
  128.     
  129.     // Finally, we updated the schema version to the destination version.
  130.     query.addQuery("update library_metadata set value = '6' where name = 'version'");
  131.     
  132.     // Our queries are all generated. Time to execute the migration.
  133.     query.addQuery("commit");
  134.  
  135.     var retval;
  136.     query.setAsyncQuery(true);
  137.     query.execute(retval);
  138.     
  139.     var sip = Cc["@mozilla.org/supports-interface-pointer;1"]
  140.                 .createInstance(Ci.nsISupportsInterfacePointer);
  141.     sip.data = this;
  142.     
  143.     this._titleText = "Library Migration Helper";
  144.     this._statusText = "Migrating 0.6.1 database to 0.7.0 database...";
  145.     this.migrationQuery = query;
  146.     
  147.     this.startNotificationTimer();
  148.     SBJobUtils.showProgressDialog(sip.data, null, 0);
  149.     this.stopNotificationTimer();
  150.   },
  151.   
  152.   _createQuery: function sbLDBM061to070_createQuery() {
  153.     var query = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
  154.                   .createInstance(Ci.sbIDatabaseQuery);
  155.     query.databaseLocation = this._databaseLocation;
  156.     query.setDatabaseGUID(this._databaseGUID);
  157.     
  158.     return query;
  159.   },  
  160.   
  161.   _getPropertyNames: function sbLDBM061to070_getPropertyNames() {
  162.     var query = this._createQuery();
  163.     var str = "select property_id, property_name from properties";
  164.     query.addQuery(str);
  165.     
  166.     var retval;
  167.     query.execute(retval);
  168.     
  169.     var resultSet = query.getResultObject();
  170.     
  171.     var rowCount = resultSet.getRowCount();
  172.     for(let currentRow = 0; currentRow < rowCount; ++currentRow) {
  173.       let propertyId = resultSet.getRowCell(currentRow, 0);
  174.       this._propertyNames[propertyId] = resultSet.getRowCell(currentRow, 1);
  175.     }
  176.   },
  177.   
  178.   _getResourceProperties: function sbLDBM061to070_getResourceProperties() {
  179.     var query = this._createQuery();
  180.     var str = "select media_item_id, property_id, obj from resource_properties";
  181.     query.addQuery(str);
  182.     
  183.     var retval;
  184.     query.execute(retval);
  185.     
  186.     var resultSet = query.getResultObject();
  187.     
  188.     var rowCount = resultSet.getRowCount();
  189.     for(let currentRow = 0; currentRow < rowCount; ++currentRow) {
  190.       let mediaItemId = resultSet.getRowCell(currentRow, 0);
  191.       let propertyId = resultSet.getRowCell(currentRow, 1);
  192.       let obj = resultSet.getRowCell(currentRow, 2);
  193.       
  194.       var entry = {itemId: mediaItemId, propId: propertyId, o: obj };
  195.       this._resourceProperties.push(entry);
  196.     }
  197.   }
  198. }
  199.  
  200.  
  201. //
  202. // Module
  203. // 
  204.  
  205. function NSGetModule(compMgr, fileSpec) {
  206.   return XPCOMUtils.generateModule([
  207.     sbLocalDatabaseMigrate061to070
  208.   ]);
  209. }
  210.