diff --git a/migration/i8.2/oracle/202111191531_IDEMPIERE-4858.sql b/migration/i8.2/oracle/202111191531_IDEMPIERE-4858.sql new file mode 100644 index 0000000000..f7aac722ce --- /dev/null +++ b/migration/i8.2/oracle/202111191531_IDEMPIERE-4858.sql @@ -0,0 +1,11 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-4858 Helper process "Make Table a Document" +-- Nov 19, 2021, 3:18:02 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','Table Index records have been added on the Translation table - do not forget to execute ''Index Validate'' process after you run ''Sync Column''',0,0,'Y',TO_DATE('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,200721,'TrlCreatedSyncColumnValidateIndex','D','81b87d52-17c3-46cd-bfdf-e08cdfc11851') +; + +SELECT register_migration_script('202111191531_IDEMPIERE-4858.sql') FROM dual +; + diff --git a/migration/i8.2/postgresql/202111191531_IDEMPIERE-4858.sql b/migration/i8.2/postgresql/202111191531_IDEMPIERE-4858.sql new file mode 100644 index 0000000000..60e08c6b51 --- /dev/null +++ b/migration/i8.2/postgresql/202111191531_IDEMPIERE-4858.sql @@ -0,0 +1,8 @@ +-- IDEMPIERE-4858 Helper process "Make Table a Document" +-- Nov 19, 2021, 3:18:02 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','Table Index records have been added on the Translation table - do not forget to execute ''Index Validate'' process after you run ''Sync Column''',0,0,'Y',TO_TIMESTAMP('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,200721,'TrlCreatedSyncColumnValidateIndex','D','81b87d52-17c3-46cd-bfdf-e08cdfc11851') +; + +SELECT register_migration_script('202111191531_IDEMPIERE-4858.sql') FROM dual +; + diff --git a/org.adempiere.base.process/src/org/idempiere/process/CreateTable.java b/org.adempiere.base.process/src/org/idempiere/process/CreateTable.java index 75f5d87138..01f14f7d64 100644 --- a/org.adempiere.base.process/src/org/idempiere/process/CreateTable.java +++ b/org.adempiere.base.process/src/org/idempiere/process/CreateTable.java @@ -45,8 +45,10 @@ import java.util.logging.Level; import org.adempiere.exceptions.AdempiereException; import org.compiere.acct.Doc; import org.compiere.model.MColumn; +import org.compiere.model.MIndexColumn; import org.compiere.model.MProcess; import org.compiere.model.MTable; +import org.compiere.model.MTableIndex; import org.compiere.model.M_Element; import org.compiere.model.Query; import org.compiere.model.X_AD_WF_Node; @@ -55,6 +57,7 @@ import org.compiere.process.DocAction; import org.compiere.process.ProcessInfoParameter; import org.compiere.process.SvrProcess; import org.compiere.util.DisplayType; +import org.compiere.util.Msg; import org.compiere.util.Util; import org.compiere.wf.MWFNode; import org.compiere.wf.MWFNodeNext; @@ -312,8 +315,9 @@ public class CreateTable extends SvrProcess { if (p_isCreateTranslationTable) { MTable tableTrl = createTable(true); + int colElementID = 0; if (elementID != null) - createColumn(tableTrl, elementID.getColumnName()); // _ID (ID of parent table) + colElementID = createColumn(tableTrl, elementID.getColumnName()); // _ID (ID of parent table) M_Element elementTrlUU = M_Element.get(getCtx(), tableTrl.getTableName() + "_UU"); if (elementTrlUU == null) { @@ -322,9 +326,14 @@ public class CreateTable extends SvrProcess { } createColumn(tableTrl, elementTrlUU.getColumnName()); // _Trl_UU - createColumn(tableTrl, "AD_Language"); + int colLanguageID = createColumn(tableTrl, "AD_Language"); createColumn(tableTrl, "IsTranslated"); + for (MColumn column : MTable.get(getCtx(), p_tableName).getColumns(false)) { + if (column.isTranslated()) + createColumn(tableTrl, column.getColumnName()); + } + if (p_isCreateColName) createColumn(tableTrl, "Name"); if (p_isCreateColDescription) @@ -332,6 +341,19 @@ public class CreateTable extends SvrProcess { if (p_isCreateColHelp) createColumn(tableTrl, "Help"); + // Index + MTableIndex ti = new MTableIndex(tableTrl, tableTrl.getTableName() + "_pkey"); + ti.setIsCreateConstraint(true); + ti.setIsUnique(true); + ti.setIsKey(true); + ti.saveEx(); + + MIndexColumn ic = new MIndexColumn(ti, new MColumn(getCtx(), colLanguageID, get_TrxName()), 1); + ic.saveEx(); + ic = new MIndexColumn(ti, new MColumn(getCtx(), colElementID, get_TrxName()), 2); + ic.saveEx(); + + addLog(Msg.getMsg(getCtx(), "TrlCreatedSyncColumnValidateIndex")); } return "@ProcessOK@"; @@ -405,9 +427,20 @@ public class CreateTable extends SvrProcess { * @param table * @param columnName */ - private void createColumn(MTable table, String columnName) { - if (getColumn(table, columnName) != null) - return; + private int createColumn(MTable table, String columnName) { + MColumn columnThatExists = getColumn(table, columnName); + if (columnThatExists != null) { + if ( p_isCreateTranslationTable + && !columnThatExists.isTranslated() + && !table.getTableName().toUpperCase().endsWith("_TRL") + && ( (p_isCreateColName && columnName.equals("Name")) + || (p_isCreateColHelp && columnName.equals("Help")) + || (p_isCreateColDescription && columnName.equals("Description")))) { + columnThatExists.setIsTranslated(true); + columnThatExists.saveEx(); + } + return -1; + } MColumn column = new MColumn(table); @@ -571,9 +604,11 @@ public class CreateTable extends SvrProcess { column.setAD_Reference_ID(DisplayType.Search); column.setIsParent(true); column.setIsMandatory(true); + column.setFKConstraintType(MColumn.FKCONSTRAINTTYPE_Cascade); } column.saveEx(); + return column.getAD_Column_ID(); } /** diff --git a/org.adempiere.base/src/org/compiere/model/MIndexColumn.java b/org.adempiere.base/src/org/compiere/model/MIndexColumn.java index cbc64eb0c3..eda29d3803 100644 --- a/org.adempiere.base/src/org/compiere/model/MIndexColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MIndexColumn.java @@ -62,6 +62,7 @@ public class MIndexColumn extends X_AD_IndexColumn { setAD_TableIndex_ID(parent.getAD_TableIndex_ID()); setAD_Column_ID(column.getAD_Column_ID()); setSeqNo(seqNo); + setEntityType(parent.getEntityType()); } /**