fixed bug 0009741: Not possible to change module's java package: upgrade fails
authorAsier Lostalé <asier.lostale@openbravo.com>
Wed, 01 Jul 2009 16:48:22 +0200
changeset 4086 aa14a9b5ed57
parent 4085 074897ad4b81
child 4087 137c92e9d8a7
fixed bug 0009741: Not possible to change module's java package: upgrade fails
src/org/openbravo/erpCommon/modules/ImportModule.java
src/org/openbravo/erpCommon/modules/ImportModule_data.xsql
--- a/src/org/openbravo/erpCommon/modules/ImportModule.java	Wed Jul 01 14:46:27 2009 +0530
+++ b/src/org/openbravo/erpCommon/modules/ImportModule.java	Wed Jul 01 16:48:22 2009 +0200
@@ -442,15 +442,30 @@
         }
         Utility.deleteDir(core);
       } else { // updating a module different than core
+
+        // take the info from module in db instead from modulesToUpdate because it can be
+        // different
+        ImportModuleData moduleInDB = null;
         try {
-          Zip.zip(obDir + "/modules/" + modulesToUpdate[i].getPackageName(), obDir
-              + "/backup_install/" + modulesToUpdate[i].getPackageName() + "-"
-              + modulesToUpdate[i].getVersionNo() + ".zip");
-        } catch (final Exception e) {
-          e.printStackTrace();
+          moduleInDB = ImportModuleData.getModule(pool, modulesToUpdate[i].getModuleID());
+        } catch (Exception e) {
+          log4j.error(e);
         }
-        // Delete directory to be updated
-        Utility.deleteDir(new File(obDir + "/modules/" + modulesToUpdate[i].getPackageName()));
+
+        if (moduleInDB != null) {
+          try {
+            Zip.zip(obDir + "/modules/" + moduleInDB.javapackage, obDir + "/backup_install/"
+                + moduleInDB.javapackage + "-" + moduleInDB.version + ".zip");
+            // Delete directory to be updated
+            Utility.deleteDir(new File(obDir + "/modules/" + moduleInDB.javapackage));
+          } catch (final Exception e) {
+            log4j.error(e);
+          }
+        } else {
+          log4j.error("module " + modulesToUpdate[i].getName()
+              + " not found in DB. Backup and old package skipped!");
+        }
+
       }
     }
 
--- a/src/org/openbravo/erpCommon/modules/ImportModule_data.xsql	Wed Jul 01 14:46:27 2009 +0530
+++ b/src/org/openbravo/erpCommon/modules/ImportModule_data.xsql	Wed Jul 01 16:48:22 2009 +0200
@@ -26,14 +26,14 @@
         SELECT M.AD_MODULE_ID, 
                COALESCE(MI.VERSION, M.VERSION) AS VERSION, 
                COALESCE(MI.NAME, M.NAME) AS NAME, 
-               '' AS TOTAL 
+               '' AS TOTAL, '' AS JAVAPACKAGE
          FROM AD_MODULE M LEFT JOIN AD_MODULE_INSTALL MI
                                  ON MI.AD_MODULE_ID = M.AD_MODULE_ID
         UNION
         SELECT M.AD_MODULE_ID, 
                M.VERSION, 
                M.NAME, 
-               '' AS TOTAL 
+               '' AS TOTAL, '' AS JAVAPACKAGE
          FROM AD_MODULE_INSTALL M
       </Sql>
    </SqlMethod>
@@ -265,5 +265,14 @@
          </Sql>
          <Parameter name="mouleId"/> 
      </SqlMethod>
+     
+     <SqlMethod name="getModule" type="preparedStatement" return="single">
+         <Sql>
+            SELECT JAVAPACKAGE, VERSION
+              FROM AD_MODULE
+             WHERE AD_MODULE_ID = ?
+         </Sql>
+         <Parameter name="mouleId"/> 
+     </SqlMethod>
 </SqlClass>