modules/org.openbravo.client.application/src-db/database/model/functions/OBUIAPP_SYNCHRONIZE.xml
author RM packaging bot <staff.rm@openbravo.com>
Tue, 28 Mar 2017 14:43:12 +0000
changeset 31747 b8f24f04c24b
parent 9903 97416e8e0db3
permissions -rw-r--r--
CI: update AD_MODULE to version 31744
gorkaion@9903
     1
<?xml version="1.0"?>
gorkaion@9903
     2
  <database name="FUNCTION OBUIAPP_SYNCHRONIZE">
gorkaion@9903
     3
    <function name="OBUIAPP_SYNCHRONIZE" type="NULL">
gorkaion@9903
     4
      <parameter name="ep_instance_id" type="VARCHAR" mode="in">
gorkaion@9903
     5
        <default/>
gorkaion@9903
     6
      </parameter>
gorkaion@9903
     7
      <body><![CDATA[/*************************************************************************
gorkaion@9903
     8
* The contents of this file are subject to the Openbravo  Public  License
gorkaion@9903
     9
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
gorkaion@9903
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
gorkaion@9903
    11
* file except in compliance with the License. You  may  obtain  a copy of
gorkaion@9903
    12
* the License at http://www.openbravo.com/legal/license.html
gorkaion@9903
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
gorkaion@9903
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
gorkaion@9903
    15
* License for the specific  language  governing  rights  and  limitations
gorkaion@9903
    16
* under the License.
gorkaion@9903
    17
* The Original Code is Openbravo ERP.
gorkaion@9903
    18
* The Initial Developer of the Original Code is Openbravo SLU
gorkaion@9903
    19
* All portions are Copyright (C) 2011 Openbravo SLU
gorkaion@9903
    20
* All Rights Reserved.
gorkaion@9903
    21
* Contributor(s):  ______________________________________.
gorkaion@9903
    22
************************************************************************/
gorkaion@9903
    23
  v_TemplateInDev CHAR(1);
gorkaion@9903
    24
  TYPE RECORD IS REF CURSOR;
gorkaion@9903
    25
  Cur_Parameter RECORD;
gorkaion@9903
    26
gorkaion@9903
    27
gorkaion@9903
    28
BEGIN 
gorkaion@9903
    29
  SELECT CASE count(*) WHEN 0 THEN 'N' ELSE 'Y' END INTO v_templateindev
gorkaion@9903
    30
  FROM ad_module 
gorkaion@9903
    31
  WHERE type = 'T'
gorkaion@9903
    32
    AND isindevelopment = 'Y';
gorkaion@9903
    33
gorkaion@9903
    34
  -- insert new elements
gorkaion@9903
    35
  FOR cur_parameter IN (
gorkaion@9903
    36
      SELECT param.obuiapp_parameter_id, param.columnname, param.name, param.help, param.description, param.ad_module_id
gorkaion@9903
    37
      FROM obuiapp_parameter param INNER JOIN ad_module m ON param.ad_module_id = m.ad_module_id
gorkaion@9903
    38
                                                             AND m.isindevelopment = 'Y'
gorkaion@9903
    39
      WHERE param.ad_element_id IS NULL
gorkaion@9903
    40
        AND param.iscentrallymaintained = 'Y'
gorkaion@9903
    41
        AND NOT EXISTS
gorkaion@9903
    42
          (SELECT 1 FROM ad_element e
gorkaion@9903
    43
            WHERE UPPER(param.columnname)=UPPER(e.columnname)
gorkaion@9903
    44
             AND AD_Module_Dependent(e.ad_module_id, param.ad_module_id)='Y')
gorkaion@9903
    45
    ) LOOP
gorkaion@9903
    46
    INSERT INTO ad_element (
gorkaion@9903
    47
        ad_element_id, ad_client_id, ad_org_id, isactive,
gorkaion@9903
    48
        created, createdby, updated, updatedby,
gorkaion@9903
    49
        columnname, name, printname, description,
gorkaion@9903
    50
        help, ad_module_id
gorkaion@9903
    51
    ) VALUES (
gorkaion@9903
    52
        get_uuid(), '0', '0', 'Y',
gorkaion@9903
    53
        now(), '0', now(), '0',
gorkaion@9903
    54
        cur_parameter.columnname, cur_parameter.name, cur_parameter.name, cur_parameter.description,
gorkaion@9903
    55
        cur_parameter.help, cur_parameter.ad_module_id);
gorkaion@9903
    56
    DBMS_OUTPUT.PUT_LINE('  added ' || cur_parameter.columnname);
gorkaion@9903
    57
  END LOOP;
gorkaion@9903
    58
gorkaion@9903
    59
  DBMS_OUTPUT.PUT_LINE('Adding missing Element Translations') ;
gorkaion@9903
    60
  INSERT INTO ad_element_trl
gorkaion@9903
    61
    (
gorkaion@9903
    62
      ad_element_trl_id, ad_element_id, ad_language, ad_client_id, ad_org_id,
gorkaion@9903
    63
      isactive, created, createdby, updated,
gorkaion@9903
    64
      updatedby, name, printname, description,
gorkaion@9903
    65
      help, istranslated
gorkaion@9903
    66
    )
gorkaion@9903
    67
  SELECT get_uuid(), e.ad_element_id, l.ad_language, e.ad_client_id, e.ad_org_id, e.isactive,
gorkaion@9903
    68
      e.created, e.createdby, e.updated, e.updatedby, e.name, e.printname, e.description, e.help, 'N'
gorkaion@9903
    69
  FROM ad_element e, ad_language l, ad_module
gorkaion@9903
    70
  WHERE l.isactive = 'Y'
gorkaion@9903
    71
    AND l.issystemlanguage = 'Y'
gorkaion@9903
    72
    AND ad_module.ad_module_id = e.ad_module_id
gorkaion@9903
    73
    AND ad_module.isindevelopment = 'Y'
gorkaion@9903
    74
    AND l.ad_language != ad_module.ad_language
gorkaion@9903
    75
    AND NOT EXISTS (SELECT 1 
gorkaion@9903
    76
                    FROM ad_element_trl 
gorkaion@9903
    77
                    WHERE ad_element_id = e.ad_element_id
gorkaion@9903
    78
                      AND ad_language = l.ad_language);
gorkaion@9903
    79
gorkaion@9903
    80
  -- Set missing ad_element_id to parameters
gorkaion@9903
    81
  UPDATE obuiapp_parameter
gorkaion@9903
    82
    SET ad_element_id=(SELECT MAX(ad_element_id)
gorkaion@9903
    83
                       FROM ad_element e
gorkaion@9903
    84
                       WHERE UPPER(obuiapp_parameter.columnname)=UPPER(e.columnname)
gorkaion@9903
    85
                         AND AD_Module_Dependent(e.ad_module_id, obuiapp_parameter.ad_module_id)='Y')
gorkaion@9903
    86
    WHERE ad_element_id IS NULL
gorkaion@9903
    87
      AND iscentrallymaintained = 'Y'
gorkaion@9903
    88
      AND EXISTS (SELECT 1 FROM ad_module m
gorkaion@9903
    89
                  WHERE (m.ad_module_id = obuiapp_parameter.ad_module_id
gorkaion@9903
    90
                         AND m.isindevelopment='Y')
gorkaion@9903
    91
                        OR v_templateindev ='Y');
gorkaion@9903
    92
gorkaion@9903
    93
  -- synchronize parameter
gorkaion@9903
    94
  UPDATE obuiapp_parameter
gorkaion@9903
    95
    SET name = 
gorkaion@9903
    96
            (SELECT COALESCE (etrl.name, e.name)
gorkaion@9903
    97
             FROM ad_element e INNER JOIN ad_module parammod ON 1=1
gorkaion@9903
    98
                               LEFT JOIN ad_element_trl etrl ON e.ad_element_id = etrl.ad_element_id
gorkaion@9903
    99
                                                                AND parammod.ad_language = etrl.ad_language
gorkaion@9903
   100
             WHERE parammod.ad_module_id = obuiapp_parameter.ad_module_id
gorkaion@9903
   101
               AND e.ad_element_id = obuiapp_parameter.ad_element_id),
gorkaion@9903
   102
        Description =
gorkaion@9903
   103
            (SELECT COALESCE (etrl.description, e.description)
gorkaion@9903
   104
             FROM ad_element e INNER JOIN ad_module parammod ON 1=1
gorkaion@9903
   105
                               LEFT JOIN ad_element_trl etrl ON e.ad_element_id = etrl.ad_element_id
gorkaion@9903
   106
                                                                AND parammod.ad_language = etrl.ad_language
gorkaion@9903
   107
             WHERE parammod.ad_module_id = obuiapp_parameter.ad_module_id
gorkaion@9903
   108
               AND e.ad_element_id = obuiapp_parameter.ad_element_id),
gorkaion@9903
   109
        Help =
gorkaion@9903
   110
            (SELECT COALESCE (etrl.Help, e.Help)
gorkaion@9903
   111
             FROM ad_element e INNER JOIN ad_module parammod ON 1=1
gorkaion@9903
   112
                               LEFT JOIN ad_element_trl etrl ON e.ad_element_id = etrl.ad_element_id
gorkaion@9903
   113
                                                                AND parammod.ad_language = etrl.ad_language
gorkaion@9903
   114
             WHERE parammod.ad_module_id = obuiapp_parameter.ad_module_id
gorkaion@9903
   115
               AND e.ad_element_id = obuiapp_parameter.ad_element_id),
gorkaion@9903
   116
        Updated=now()
gorkaion@9903
   117
    WHERE obuiapp_parameter.iscentrallymaintained = 'Y'
gorkaion@9903
   118
      AND obuiapp_parameter.isactive = 'Y'
gorkaion@9903
   119
      AND obuiapp_parameter.ad_element_id IS NOT NULL
gorkaion@9903
   120
      AND EXISTS
gorkaion@9903
   121
        (SELECT 1
gorkaion@9903
   122
         FROM ad_element e INNER JOIN ad_module parammod ON 1=1
gorkaion@9903
   123
                               LEFT JOIN ad_element_trl etrl ON e.ad_element_id = etrl.ad_element_id
gorkaion@9903
   124
                                                            AND parammod.ad_language = etrl.ad_language
gorkaion@9903
   125
         WHERE obuiapp_parameter.ad_module_id = parammod.ad_module_id
gorkaion@9903
   126
           AND e.ad_element_id = obuiapp_parameter.ad_element_id
gorkaion@9903
   127
           AND (parammod.isindevelopment = 'Y' OR v_templateindev = 'Y')
gorkaion@9903
   128
           AND (obuiapp_parameter.NAME != COALESCE(etrl.name, e.name)
gorkaion@9903
   129
                OR COALESCE(TO_CHAR(obuiapp_parameter.description), ' ')<>COALESCE(TO_CHAR(etrl.description), TO_CHAR(e.description), ' ')
gorkaion@9903
   130
                OR COALESCE(TO_CHAR(obuiapp_parameter.help), ' ')<>COALESCE(TO_CHAR(etrl.help), TO_CHAR(e.help), ' ')));
gorkaion@9903
   131
gorkaion@9903
   132
    DBMS_OUTPUT.PUT_LINE('Synchronize Field Translations');
gorkaion@9903
   133
    -- Translation managed on 2 steps. Step 1: update taken translations from ad_element_trl table:
gorkaion@9903
   134
    UPDATE obuiapp_parameter_trl
gorkaion@9903
   135
      SET name =
gorkaion@9903
   136
              (SELECT etrl.name
gorkaion@9903
   137
               FROM obuiapp_parameter param INNER JOIN ad_element_trl etrl ON param.ad_element_id = etrl.ad_element_id
gorkaion@9903
   138
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   139
                 AND etrl.ad_language = obuiapp_parameter_trl.ad_language),
gorkaion@9903
   140
          description =
gorkaion@9903
   141
              (SELECT etrl.description
gorkaion@9903
   142
               FROM obuiapp_parameter param INNER JOIN ad_element_trl etrl ON param.ad_element_id = etrl.ad_element_id
gorkaion@9903
   143
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   144
                 AND etrl.ad_language = obuiapp_parameter_trl.ad_language),
gorkaion@9903
   145
          help =
gorkaion@9903
   146
              (SELECT etrl.help
gorkaion@9903
   147
               FROM obuiapp_parameter param INNER JOIN ad_element_trl etrl ON param.ad_element_id = etrl.ad_element_id
gorkaion@9903
   148
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   149
                 AND etrl.ad_language = obuiapp_parameter_trl.ad_language),
gorkaion@9903
   150
          istranslated =
gorkaion@9903
   151
              (SELECT etrl.istranslated
gorkaion@9903
   152
               FROM obuiapp_parameter param INNER JOIN ad_element_trl etrl ON param.ad_element_id = etrl.ad_element_id
gorkaion@9903
   153
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   154
                 AND etrl.ad_language = obuiapp_parameter_trl.ad_language),
gorkaion@9903
   155
          updated=now()
gorkaion@9903
   156
    WHERE EXISTS
gorkaion@9903
   157
      (SELECT 1
gorkaion@9903
   158
       FROM obuiapp_parameter param INNER JOIN ad_element_trl etrl ON param.ad_element_id = etrl.ad_element_id
gorkaion@9903
   159
                                    INNER JOIN ad_module m ON param.ad_module_id = param.ad_module_id
gorkaion@9903
   160
       WHERE param.obuiapp_parameter_id = obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   161
         AND param.iscentrallymaintained = 'Y'
gorkaion@9903
   162
         AND param.isactive = 'Y'
gorkaion@9903
   163
         AND etrl.ad_language = obuiapp_parameter_trl.ad_language
gorkaion@9903
   164
         AND (m.isindevelopment = 'Y' OR v_templateindev ='Y')
gorkaion@9903
   165
         AND (obuiapp_parameter_trl.name <> etrl.name
gorkaion@9903
   166
              OR COALESCE(TO_CHAR(obuiapp_parameter_trl.description), ' ') <> COALESCE(TO_CHAR(etrl.description), ' ')
gorkaion@9903
   167
              OR COALESCE(TO_CHAR(obuiapp_parameter_trl.help), ' ') <> COALESCE(TO_CHAR(etrl.help), ' ')));
gorkaion@9903
   168
gorkaion@9903
   169
    -- Step 2: Take translations from ad_element table.
gorkaion@9903
   170
    UPDATE obuiapp_parameter_trl
gorkaion@9903
   171
      SET name =
gorkaion@9903
   172
              (SELECT e.name
gorkaion@9903
   173
               FROM ad_element e INNER JOIN obuiapp_parameter param ON e.ad_element_id = param.ad_element_id
gorkaion@9903
   174
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id),
gorkaion@9903
   175
          description =
gorkaion@9903
   176
              (SELECT e.name
gorkaion@9903
   177
               FROM ad_element e INNER JOIN obuiapp_parameter param ON e.ad_element_id = param.ad_element_id
gorkaion@9903
   178
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id),
gorkaion@9903
   179
          help =
gorkaion@9903
   180
              (SELECT e.name
gorkaion@9903
   181
               FROM ad_element e INNER JOIN obuiapp_parameter param ON e.ad_element_id = param.ad_element_id
gorkaion@9903
   182
               WHERE param.obuiapp_parameter_id=obuiapp_parameter_trl.obuiapp_parameter_id),
gorkaion@9903
   183
          istranslated = 'Y',
gorkaion@9903
   184
          updated = now()
gorkaion@9903
   185
      WHERE EXISTS
gorkaion@9903
   186
        (SELECT 1
gorkaion@9903
   187
         FROM obuiapp_parameter param INNER JOIN ad_element e ON e.ad_element_id = param.ad_element_id
gorkaion@9903
   188
                                      INNER JOIN ad_module m ON e.ad_module_id = m.ad_module_id
gorkaion@9903
   189
         WHERE param.obuiapp_parameter_id = obuiapp_parameter_trl.obuiapp_parameter_id
gorkaion@9903
   190
           AND param.iscentrallymaintained = 'Y' 
gorkaion@9903
   191
           AND param.isactive='Y'
gorkaion@9903
   192
           AND m.ad_language = obuiapp_parameter_trl.ad_language
gorkaion@9903
   193
           AND (m.isindevelopment='Y' or v_templateindev ='Y')
gorkaion@9903
   194
           AND (obuiapp_parameter_trl.name <> e.name
gorkaion@9903
   195
                OR COALESCE(TO_CHAR(obuiapp_parameter_trl.description), ' ') <> COALESCE(TO_CHAR(e.description), ' ')
gorkaion@9903
   196
                OR COALESCE(TO_CHAR(obuiapp_parameter_trl.help), ' ') <> COALESCE(TO_CHAR(e.help), ' ')));
gorkaion@9903
   197
END OBUIAPP_SYNCHRONIZE
gorkaion@9903
   198
]]></body>
gorkaion@9903
   199
    </function>
gorkaion@9903
   200
  </database>