details:   https://code.openbravo.com/erp/devel/pi/rev/2f1eca1d8609
changeset: 16677:2f1eca1d8609
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Mon May 28 17:31:44 2012 +0200
summary:   Fixed issue 20591. Fixed issue 20592. Several changes have been made:
> - The table creation commands are now considered 'critical'. This means that 
> the process will fail automatically, with an specific message, if one of 
> these commands fails.
> - The create fks and triggers methods now return whether there were errors or 
> not during the execution.
> - This new boolean is now used by update.database to make the process fail in 
> the end, if some trigger or foreign key was not correctly enabled. This 
> failure is a normal exception which will be detected by the rebuild window as 
> an error in the process.
> - Additionally (and unrelated to these issues actually) a new convenient 
> method to load a basic database model which includes only tables has been 
> included.

details:   https://code.openbravo.com/erp/devel/pi/rev/237ce7d9967e
changeset: 16678:237ce7d9967e
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Mon May 28 17:37:06 2012 +0200
summary:   Fixed issue 20624. When installing/updating modules, the check for 
local changes will be done.
This check will from now on be done early, before installing anything, to 
prevent a situation in which the user installs modules, but then the rebuild 
fails with local changes. If these changes are detected early, then the user 
can more easily fix them by just exporting his changes before proceeding with 
the installation.

diffstat:

 src-db/database/lib/dbsourcemanager.jar                                 |    0 
 src-db/database/sourcedata/AD_MESSAGE.xml                               |   17 
+
 src-db/database/sourcedata/AD_TEXTINTERFACES.xml                        |   22 
+
 src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java              |   89 
+++++
 src/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.html |  154 
++++++++++
 src/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.xml  |   27 
+
 6 files changed, 309 insertions(+), 0 deletions(-)

diffs (truncated from 404 to 300 lines):

diff -r 661e839cd9ab -r 237ce7d9967e src-db/database/lib/dbsourcemanager.jar
Binary file src-db/database/lib/dbsourcemanager.jar has changed
diff -r 661e839cd9ab -r 237ce7d9967e src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Mon May 28 16:57:22 2012 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Mon May 28 17:37:06 2012 +0200
@@ -20456,6 +20456,23 @@
 <!--F6E3C4F8AAD64A07A3BC1937B053689E-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--F6E3C4F8AAD64A07A3BC1937B053689E--></AD_MESSAGE>
 
+<!--F6E64CAFA7E44E88A350335CDCA9F318--><AD_MESSAGE>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  
<AD_MESSAGE_ID><![CDATA[F6E64CAFA7E44E88A350335CDCA9F318]]></AD_MESSAGE_ID>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  
<VALUE><![CDATA[ErrorLocalChanges]]></VALUE>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  <MSGTEXT><![CDATA[Local changes have 
been found in your database. This probably means that you have created or 
changed some elements in the Application Dictionary (such as windows, fields, 
menu entries, or messages), and that you have not exported them. If you don't 
export them before updating your environment or installing modules, your 
changes will be replaced.
+
+Please use the following command to export your changes:
+
+<i>ant export.database</i>
+
+To find out more about this command, and why you should use it, you can read 
<a href=http://wiki.openbravo.com/wiki/Update_Tips target=blank_>this</a> page 
in the Openbravo wiki.]]></MSGTEXT>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--F6E64CAFA7E44E88A350335CDCA9F318-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F6E64CAFA7E44E88A350335CDCA9F318--></AD_MESSAGE>
+
 <!--F6FCD10C8D0349F48C4F7EF4BF591996--><AD_MESSAGE>
 <!--F6FCD10C8D0349F48C4F7EF4BF591996-->  
<AD_MESSAGE_ID><![CDATA[F6FCD10C8D0349F48C4F7EF4BF591996]]></AD_MESSAGE_ID>
 <!--F6FCD10C8D0349F48C4F7EF4BF591996-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 661e839cd9ab -r 237ce7d9967e 
src-db/database/sourcedata/AD_TEXTINTERFACES.xml
--- a/src-db/database/sourcedata/AD_TEXTINTERFACES.xml  Mon May 28 16:57:22 
2012 +0200
+++ b/src-db/database/sourcedata/AD_TEXTINTERFACES.xml  Mon May 28 17:37:06 
2012 +0200
@@ -18937,6 +18937,17 @@
 <!--982644405A4C4BC6AD687D6014C11878-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--982644405A4C4BC6AD687D6014C11878--></AD_TEXTINTERFACES>
 
+<!--9893CDF907C9415B977B68F8AF5202B9--><AD_TEXTINTERFACES>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  
<AD_TEXTINTERFACES_ID><![CDATA[9893CDF907C9415B977B68F8AF5202B9]]></AD_TEXTINTERFACES_ID>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  <TEXT><![CDATA[Local changes 
found]]></TEXT>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  
<FILENAME><![CDATA[/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.html]]></FILENAME>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--9893CDF907C9415B977B68F8AF5202B9-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--9893CDF907C9415B977B68F8AF5202B9--></AD_TEXTINTERFACES>
+
 <!--99A697728AAA426DBBBC95474D01E93D--><AD_TEXTINTERFACES>
 <!--99A697728AAA426DBBBC95474D01E93D-->  
<AD_TEXTINTERFACES_ID><![CDATA[99A697728AAA426DBBBC95474D01E93D]]></AD_TEXTINTERFACES_ID>
 <!--99A697728AAA426DBBBC95474D01E93D-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -20202,6 +20213,17 @@
 <!--CF98EF23891A4DD5917787CA3E7C34B7-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--CF98EF23891A4DD5917787CA3E7C34B7--></AD_TEXTINTERFACES>
 
+<!--D07ED53714914E0696C37AC75E8572D3--><AD_TEXTINTERFACES>
+<!--D07ED53714914E0696C37AC75E8572D3-->  
<AD_TEXTINTERFACES_ID><![CDATA[D07ED53714914E0696C37AC75E8572D3]]></AD_TEXTINTERFACES_ID>
+<!--D07ED53714914E0696C37AC75E8572D3-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D07ED53714914E0696C37AC75E8572D3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D07ED53714914E0696C37AC75E8572D3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D07ED53714914E0696C37AC75E8572D3-->  <TEXT><![CDATA[Decline]]></TEXT>
+<!--D07ED53714914E0696C37AC75E8572D3-->  
<FILENAME><![CDATA[/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.html]]></FILENAME>
+<!--D07ED53714914E0696C37AC75E8572D3-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--D07ED53714914E0696C37AC75E8572D3-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--D07ED53714914E0696C37AC75E8572D3--></AD_TEXTINTERFACES>
+
 <!--D149927F9A4A44A5A4E3818F97B3D460--><AD_TEXTINTERFACES>
 <!--D149927F9A4A44A5A4E3818F97B3D460-->  
<AD_TEXTINTERFACES_ID><![CDATA[D149927F9A4A44A5A4E3818F97B3D460]]></AD_TEXTINTERFACES_ID>
 <!--D149927F9A4A44A5A4E3818F97B3D460-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 661e839cd9ab -r 237ce7d9967e 
src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java
--- a/src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java        Mon May 
28 16:57:22 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/ModuleManagement.java        Mon May 
28 17:37:06 2012 +0200
@@ -19,22 +19,31 @@
 
 package org.openbravo.erpCommon.ad_forms;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.URL;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.commons.fileupload.FileItem;
+import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.PlatformFactory;
+import org.apache.ddlutils.model.Database;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -43,12 +52,16 @@
 import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.core.OBInterceptor;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
+import org.openbravo.ddlutils.task.DatabaseUtils;
+import org.openbravo.ddlutils.util.DBSMOBUtil;
+import org.openbravo.ddlutils.util.OBDataset;
 import org.openbravo.erpCommon.ad_process.HeartbeatProcess;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.modules.ImportModule;
@@ -78,6 +91,7 @@
 import org.openbravo.services.webservice.SimpleModule;
 import org.openbravo.services.webservice.WebService3Impl;
 import org.openbravo.services.webservice.WebService3ImplServiceLocator;
+import org.openbravo.utils.Replace;
 import org.openbravo.xmlEngine.XmlDocument;
 
 /**
@@ -1083,6 +1097,23 @@
       return;
     }
 
+    boolean localChanges = verifyLocalChanges();
+    if (localChanges) {
+      final PrintWriter out = response.getWriter();
+      final String discardlc[] = {};
+      final XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
+          "org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges", 
discardlc)
+          .createXmlDocument();
+      xmlDocument.setParameter("directory", "var baseDirectory = \"" + 
strReplaceWith + "/\";\n");
+      xmlDocument.setParameter("language", "defaultLang=\"" + 
vars.getLanguage() + "\";");
+      xmlDocument.setParameter("theme", vars.getTheme());
+      xmlDocument.setParameter("welcome", Replace.replace(
+          Utility.messageBD(this, "ErrorLocalChanges", vars.getLanguage()), 
"\\n", "<br/>"));
+      out.println(xmlDocument.print());
+      out.close();
+      return;
+    }
+
     if (upgradeIM != null) {
       for (Module mod : upgradeIM.getModulesToUpdate()) {
         if (mod.getModuleID().equals(ModuleUtiltiy.TEMPLATE_30)) {
@@ -2570,4 +2601,62 @@
     vars.setMessage("ModuleManagement|message", err);
     OBDal.getInstance().rollbackAndClose();
   }
+
+  /**
+   * Checks if there are local changes in the application
+   */
+  private boolean verifyLocalChanges() {
+    long t1 = System.currentTimeMillis();
+    Connection connection = OBDal.getInstance().getConnection();
+    PreparedStatement ps = null;
+    try {
+      ps = connection.prepareStatement("SELECT ad_db_modified('N') FROM DUAL");
+      ps.execute();
+      ResultSet rs = ps.getResultSet();
+      rs.next();
+      String answer = rs.getString(1);
+      if (answer.equalsIgnoreCase("Y")) {
+        return true;
+      }
+    } catch (Exception e) {
+      log4j.error("Couldn't verify local changes");
+    } finally {
+      try {
+        ps.close();
+      } catch (SQLException e) {
+        // won't happen
+      }
+    }
+    List<File> modelFiles = new ArrayList<File>();
+    String sourcePath = 
OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("source.path");
+    File sources = new File(sourcePath);
+    File model = new File(sources, "src-db/database/model/tables");
+    if (model.exists()) {
+      modelFiles.add(model);
+    }
+    for (File moduleFile : (new File(sources, "modules").listFiles())) {
+      File mmodel = new File(moduleFile, "src-db/database/model/tables");
+      if (mmodel.exists()) {
+        modelFiles.add(mmodel);
+      }
+    }
+    Database db = DatabaseUtils.readDatabase(modelFiles.toArray(new File[1]));
+
+    Properties obProp = 
OBPropertiesProvider.getInstance().getOpenbravoProperties();
+    String driver = obProp.getProperty("bbdd.driver");
+    String url = obProp.getProperty("bbdd.rdbms").equals("POSTGRE") ? obProp
+        .getProperty("bbdd.url") + "/" + obProp.getProperty("bbdd.sid") : 
obProp
+        .getProperty("bbdd.url");
+    String user = obProp.getProperty("bbdd.user");
+    String password = obProp.getProperty("bbdd.password");
+    BasicDataSource datasource = DBSMOBUtil.getDataSource(driver, url, user, 
password);
+    final Platform platform = 
PlatformFactory.createNewPlatformInstance(datasource);
+
+    OBDataset ad = new OBDataset(platform, db, "AD");
+    boolean datachange = ad.hasChanged(connection, log4j);
+    return datachange;
+
+  }
+
 }
diff -r 661e839cd9ab -r 237ce7d9967e 
src/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.html
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/ModuleManagement_LocalChanges.html   
Mon May 28 17:37:06 2012 +0200
@@ -0,0 +1,154 @@
+<!--
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2012 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>Local changes found</title>
+  <link rel="shortcut icon" href="../../../../../web/images/favicon.ico" 
type="image/x-icon" />
+  <link rel="stylesheet" type="text/css" 
href="../../../../../web/skins/Default/Openbravo_ERP_250.css" 
id="paramCSS"></link>
+  <script language="JavaScript" type="text/javascript" id="paramDirectory">var 
baseDirectory = "../../../../../web/";</script>
+  <script language="JavaScript" type="text/javascript" id="paramLanguage">var 
defaultLang = "en_US";</script>
+  <script language="JavaScript" src="../../../../../web/js/shortcuts.js" 
type="text/javascript"></script> 
+  <script language="JavaScript" src="../../../../../web/js/utils.js" 
type="text/javascript"></script>
+  <script language="JavaScript" src="../../../../../web/js/windowKeyboard.js" 
type="text/javascript"></script>
+  <script language="JavaScript" src="../../../../../web/js/appStatus.js" 
type="text/javascript"></script>
+  <script language="JavaScript" src="../../../../../web/js/ajax.js" 
type="text/javascript"></script>
+  <script language="JavaScript" type="text/javascript">
+  function openRegistration() {
+    if (!isWindowInMDIContext) {
+      var w = window.opener;
+      if(w) {
+        w.setTimeout("openRegistration();",100);
+      }
+    } else {
+      
getFrame('LayoutMDI').OB.Layout.ClassicOBCompatibility.Popup.openRegistration();
+    }
+    return true;
+  }
+  </script>
+  <script language="JavaScript" type="text/javascript" id="paramCMD">var cmd = 
'CONFIGURE';</script>
+
+  <script language="JavaScript" type="text/javascript">
+  function onLoadDo(){
+    this.windowTables = new Array(
+      new windowTableId('client', 'buttonContinue')
+    );
+    setWindowTableParentElement();
+    enableShortcuts('popup');
+    setBrowserAutoComplete(false);
+    setWindowElementFocus('firstElement');
+  }
+
+  function onResizeDo(){
+  }
+  </script>
+
+</head>
+<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" 
onload="onLoadDo();" onresize="onResizeDo();">
+
+
+<form method="post" action="ModuleManagement_LocalChanges" name="frmMain" 
style="position: relative;">
+<input type="hidden" name="Command" />
+<input type="hidden" name="IsPopUpCall" value="1" />
+<input type="hidden" id="paramRecordId" name="inpcRecordId" value="xx" />
+<input type="hidden" id="version" name="version" value="xx" />
+<input type="hidden" id="paramRegistration" name="showRegistration" value="N" 
/>
+
+
+<table cellspacing="0" cellpadding="0" width="100%">
+  <tr>
+    <td>
+      <table cellspacing="0" cellpadding="0" class="Popup_ContentPane_NavBar">
+        <tr class="Popup_NavBar_bg"><td></td>
+          <td class="Popup_NavBar_separator_cell"></td>
+          <td class="Popup_NavBar_bg_logo_left"></td>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to