source: trunk/workflow/setup/tables_update.inc.php @ 6548

Revision 6548, 14.1 KB checked in by leticiabohnert, 12 years ago (diff)

Ticket #2851 - Correção do tables_update e default.

  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare - Setup                                                       *
4        * http://www.egroupware.org                                                *
5        * --------------------------------------------                             *
6        *  This program is free software; you can redistribute it and/or modify it *
7        *  under the terms of the GNU General Public License as published by the   *
8        *  Free Software Foundation; either version 2 of the License, or (at your  *
9        *  option) any later version.                                              *
10        \**************************************************************************/
11
12        function extractDatabaseParameters()
13        {
14                /* extract the database connection parameters */
15
16                $workflowHostInfo = array();
17                if (!empty($GLOBALS['phpgw']->ADOdb->database))
18                {
19                        $workflowHostInfo = array(
20                                'dbname' => $GLOBALS['phpgw']->ADOdb->database,
21                                'host' => $GLOBALS['phpgw']->ADOdb->host,
22                                'port' => $GLOBALS['phpgw']->ADOdb->port,
23                                'user' => $GLOBALS['phpgw']->ADOdb->user,
24                                'password' => $GLOBALS['phpgw']->ADOdb->password);
25                }
26                else
27                {
28                        $hostInfo = "dbname= host= password= port= user= " . $GLOBALS['phpgw']->ADOdb->host;
29                        $hostInfo = explode(' ', $hostInfo);
30                        foreach ($hostInfo as $parameter)
31                        {
32                                $currentParameter = explode('=', $parameter);
33                                $workflowHostInfo[$currentParameter[0]] = isset($currentParameter[1]) ? $currentParameter[1] : "";
34                        }
35                }
36                if (($workflowHostInfo['password']{0} == "'") && ($workflowHostInfo['password']{strlen($workflowHostInfo['password'])-1} == "'"))
37                        $workflowHostInfo['password'] = substr($workflowHostInfo['password'], 1, strlen($workflowHostInfo['password']) - 2);
38
39                return $workflowHostInfo;
40        }
41
42        $test[] = '2.0.000';
43        function workflow_upgrade2_0_000()
44        {
45                #updating the current version
46                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.001';
47                return $GLOBALS['setup_info']['workflow']['currentver'];
48        }
49        $test[] = '2.0.001';
50        function workflow_upgrade2_0_001()
51        {
52                #updating the current version
53                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.002';
54                return $GLOBALS['setup_info']['workflow']['currentver'];
55        }
56        $test[] = '2.0.002';
57        function workflow_upgrade2_0_002()
58        {
59                #updating the current version
60                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.003';
61                return $GLOBALS['setup_info']['workflow']['currentver'];
62        }
63        $test[] = '2.0.003';
64        function workflow_upgrade2_0_003()
65        {
66                #updating the current version
67                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.004';
68                return $GLOBALS['setup_info']['workflow']['currentver'];
69        }
70        $test[] = '2.0.004';
71        function workflow_upgrade2_0_004()
72        {
73                #updating the current version
74                $GLOBALS['setup_info']['workflow']['currentver'] = '2.1.000';
75                return $GLOBALS['setup_info']['workflow']['currentver'];
76        }
77        $test[] = '2.1.000';
78        function workflow_upgrade2_1_000()
79        {
80                if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
81                {
82                        /* updating log level */
83                        $values = array('0', 'workflow', 'log_level');
84                        $GLOBALS['phpgw']->ADOdb->query('UPDATE phpgw_config SET config_value=? WHERE config_app=? AND config_name=?', $values);
85
86                        $workflowHostInfo = extractDatabaseParameters();
87
88                        /* connect to workflow database */
89                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
90                        if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
91                        {
92                                /* creating table substitution */
93                                $workflowDB->query('CREATE TABLE substituicao (substituicao_id serial NOT NULL, area_id integer NOT NULL, funcionario_id integer NOT NULL, data_inicio date NOT NULL, data_fim date NOT NULL)');
94
95                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT substituicao_pkey PRIMARY KEY (substituicao_id)');
96                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT "$1" FOREIGN KEY (area_id) REFERENCES area(area_id)');
97                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT "$2" FOREIGN KEY (funcionario_id) REFERENCES funcionario(funcionario_id)');
98
99                                /* granting privilegies */
100                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao TO admin_workflow");
101                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao TO postgres");
102                                $workflowDB->query("GRANT SELECT ON TABLE public.substituicao TO public");
103                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao_substituicao_id_seq TO admin_workflow");
104                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao_substituicao_id_seq TO postgres");
105                                $workflowDB->query("GRANT SELECT ON TABLE public.substituicao_substituicao_id_seq TO public");
106
107                                /* migrating records */
108                                $result = $workflowDB->query('SELECT area_id, substituto_funcionario_id FROM area WHERE substituto_funcionario_id IS NOT NULL');
109                                if ($result)
110                                        while ($row = $result->fetchRow()) {
111                                                $values = array($row['area_id'], $row['substituto_funcionario_id']);
112                                                $workflowDB->query('INSERT INTO substituicao (area_id, funcionario_id, data_inicio, data_fim) VALUES (?, ?, CURRENT_DATE, CURRENT_DATE+integer \'7\')', $values);
113                                        }
114
115
116                                /* erasing old atributes */
117                                $workflowDB->query("ALTER TABLE area DROP COLUMN substituto_funcionario_id");
118                        }
119
120                        /* reconnect to the previous database */
121                        $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
122
123                        /* removing primary key of egw_wf_interinstance_relations */
124                        $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations DROP CONSTRAINT egw_wf_interinstance_relations_pkey');
125
126                        /* removing wf_parent_activity_id column from egw_wf_interinstance_relations table */
127                        $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations DROP COLUMN wf_parent_activity_id');
128
129                        /* adding primary key without the column removed */
130                        $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations ADD CONSTRAINT egw_wf_interinstance_relations_pkey PRIMARY KEY (wf_parent_instance_id, wf_child_instance_id)');
131
132                        /* Update the organogram level of administration off all users from 0 to 1. */
133                        $GLOBALS['phpgw']->ADOdb->query('UPDATE egw_wf_admin_access set nivel = 1 WHERE tipo = \'ORG\' and nivel = 0');
134                }
135
136                #updating the current version
137                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.000';
138                return $GLOBALS['setup_info']['workflow']['currentver'];
139        }
140        $test[] = '2.2.000';
141        function workflow_upgrade2_2_000()
142        {
143                #updating the current version
144                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.1';
145                return $GLOBALS['setup_info']['workflow']['currentver'];
146        }
147        $test[] = '2.2.1';
148        function workflow_upgrade2_2_1()
149        {
150                #updating the current version
151                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.6';
152        return $GLOBALS['setup_info']['workflow']['currentver'];
153        }
154        $test[] = '2.2.6';
155        function workflow_upgrade2_2_6()
156        {
157                #updating the current version
158                $GLOBALS['setup_info']['workflow']['currentver'] = '2.3.0';
159        return $GLOBALS['setup_info']['workflow']['currentver'];
160        }
161        $test[] = '2.3.0';
162        function workflow_upgrade2_3_0()
163        {
164                #updating the current version
165
166                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('en','workflow','Reports','Reports') ");
167
168                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('pt-br','workflow','Reports','Relatórios') ");
169
170                $workflowHostInfo = extractDatabaseParameters();
171
172                        /* connect to workflow database */
173                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
174                        if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
175                        {
176                                /* creating table substitution */
177                                $workflowDB->query('CREATE SCHEMA listagem AUTHORIZATION postgres; GRANT ALL ON SCHEMA listagem TO postgres; GRANT ALL ON SCHEMA listagem TO admin_workflow;');
178
179                        $workflowDB->query("CREATE TABLE listagem.listagem
180                                                        (
181                                                          lstoid serial NOT NULL,
182                                                          lstversao integer,
183                                                          lstidlistagem text NOT NULL,
184                                                          lstdescricao text,
185                                                          lstnome text NOT NULL,
186                                                          lsttitulo text NOT NULL,
187                                                          lstsql text,
188                                                          lstexibe_header boolean,
189                                                          lstexibe_totalizadores boolean,
190                                                          lstexibe_subtotais boolean,
191                                                          lstexibe_qtdregistros boolean,
192                                                          lstexibe_checkbox boolean,
193                                                          lstexibe_csv boolean,
194                                                          lstexibe_legendatopo boolean,
195                                                          lstexibe_legendarodape boolean,
196                                                          lstexibe_titagrupamento boolean,
197                                                          lstexibe_agrupamento_alfabetico boolean,
198                                                          lstagrupamento_campo text,
199                                                          lstagrupamento_titulo text,
200                                                          lstmsg_totalizador text DEFAULT 'TOTAL:'::text,
201                                                          lstmsg_subtotalizador text DEFAULT 'SUB-TOTAL:'::text,
202                                                          lstmsg_registrosencontrados text DEFAULT 'registro(s) encontrado(s).'::text,
203                                                          lstmsg_nenhumresultado text DEFAULT 'Nenhum resultado encontrado.'::text,
204                                                          lstexclusao timestamp without time zone,
205                                                          lstexibe_resultados boolean DEFAULT true,
206                                                          CONSTRAINT lstoid_pkey PRIMARY KEY (lstoid)
207                                                        )
208                                                        WITHOUT OIDS;
209                                                        ALTER TABLE listagem.listagem OWNER TO postgres;
210                                                        GRANT ALL ON TABLE listagem.listagem TO postgres;
211                                                        GRANT ALL ON TABLE listagem.listagem TO admin_workflow;");
212
213
214                        $workflowDB->query("CREATE TABLE listagem.listagem_coluna
215                                                        (
216                                                          lslcoid serial NOT NULL,
217                                                          lslclstoid integer NOT NULL,
218                                                          lslcidcoluna text NOT NULL,
219                                                          lslcordem integer,
220                                                          lslctipo text,
221                                                          lslctitulo text,
222                                                          lslchtml text,
223                                                          lslcalign character varying(10),
224                                                          lslcwidth character varying(10),
225                                                          lslcnowrap boolean,
226                                                          lslcvisivel boolean,
227                                                          lslcexibe_csv boolean,
228                                                          lslccalculada boolean,
229                                                          lslccheckbox boolean,
230                                                          lslclink text,
231                                                          lslclink_blank boolean,
232                                                          lslclink_condicao text DEFAULT '1'::text,
233                                                          lslctotalizador_condicao text DEFAULT '1'::text,
234                                                          lslcsubtotalizador_condicao text DEFAULT '1'::text,
235                                                          lslccheckbox_condicao text DEFAULT '1'::text,
236                                                          CONSTRAINT lslcoid_pkey PRIMARY KEY (lslcoid),
237                                                          CONSTRAINT listagem_coluna_lslclstoid_fkey FOREIGN KEY (lslclstoid)
238                                                              REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
239                                                              ON UPDATE NO ACTION ON DELETE NO ACTION
240                                                        )
241                                                        WITHOUT OIDS;
242                                                        ALTER TABLE listagem.listagem_coluna OWNER TO postgres;
243                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO postgres;
244                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO admin_workflow;");
245
246
247                        $workflowDB->query("CREATE TABLE listagem.listagem_indicador
248                                                                (
249                                                                  lsioid serial NOT NULL,
250                                                                  lsilstoid integer NOT NULL,
251                                                                  lsiidindicador text,
252                                                                  lsitipo character(1),
253                                                                  lsiimagem text,
254                                                                  lsilegenda text,
255                                                                  lsilegenda_csv text,
256                                                                  lsicondicao text DEFAULT '1'::text,
257                                                                  CONSTRAINT lsioid_pkey PRIMARY KEY (lsioid),
258                                                                  CONSTRAINT listagem_indicador_lsilstoid_fkey FOREIGN KEY (lsilstoid)
259                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
260                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
261                                                                )
262                                                                WITHOUT OIDS;
263                                                                ALTER TABLE listagem.listagem_indicador OWNER TO postgres;
264                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO postgres;
265                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO admin_workflow;");
266
267
268                        $workflowDB->query("CREATE TABLE listagem.listagem_parametro
269                                                                (
270                                                                  lspoid serial NOT NULL,
271                                                                  lsplstoid integer NOT NULL,
272                                                                  lspidparametro text,
273                                                                  lsptitulo text,
274                                                                  lsptipo text,
275                                                                  lspvalor_padrao text,
276                                                                  lspobrigatorio boolean,
277                                                                  CONSTRAINT lspoid_pkey PRIMARY KEY (lspoid),
278                                                                  CONSTRAINT listagem_parametro_lsplstoid_fkey FOREIGN KEY (lsplstoid)
279                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
280                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
281                                                                )
282                                                                WITHOUT OIDS;
283                                                                ALTER TABLE listagem.listagem_parametro OWNER TO postgres;
284                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO postgres;
285                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO admin_workflow;");
286
287
288
289
290                        $workflowDB->query("CREATE SEQUENCE listagem.listagem_coluna_lslcoid_seq
291                                  INCREMENT 1
292                                  MINVALUE 1
293                                  MAXVALUE 9223372036854775807
294                                  START 1
295                                  CACHE 1;
296                                ALTER TABLE listagem.listagem_coluna_lslcoid_seq OWNER TO postgres;
297
298
299                                CREATE SEQUENCE listagem.listagem_indicador_lsioid_seq
300                                  INCREMENT 1
301                                  MINVALUE 1
302                                  MAXVALUE 9223372036854775807
303                                  START 1
304                                  CACHE 1;
305                                ALTER TABLE listagem.listagem_indicador_lsioid_seq OWNER TO postgres;
306
307
308                                CREATE SEQUENCE listagem.listagem_lstoid_seq
309                                  INCREMENT 1
310                                  MINVALUE 1
311                                  MAXVALUE 9223372036854775807
312                                  START 1
313                                  CACHE 1;
314                                ALTER TABLE listagem.listagem_lstoid_seq OWNER TO postgres;
315
316
317                                CREATE SEQUENCE listagem.listagem_parametro_lspoid_seq
318                                  INCREMENT 1
319                                  MINVALUE 1
320                                  MAXVALUE 9223372036854775807
321                                  START 1
322                                  CACHE 1;
323                                ALTER TABLE listagem.listagem_parametro_lspoid_seq OWNER TO postgres;");
324
325
326                        }
327
328                /* reconnect to the previous database */
329                $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
330                $GLOBALS['setup_info']['workflow']['currentver'] = '2.4.0';
331                return $GLOBALS['setup_info']['workflow']['currentver'];
332        }
333       
334        $test[] = '2.4.0';     
335        function workflow_upgrade2_4_0()
336        {
337       
338                $workflowHostInfo = extractDatabaseParameters();
339
340                /* connect to workflow database */
341                $workflowDB = $GLOBALS['phpgw']->ADOdb;
342                if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
343                {
344                        $workflowDB->query('ALTER TABLE ONLY public.funcionario ADD COLUMN funcao CHARACTER VARYING(200)');
345                        $workflowDB->query('ALTER TABLE ONLY public.funcionario ADD COLUMN data_admissao DATE');
346                        $workflowDB->query('ALTER TABLE ONLY public.funcionario ADD COLUMN apelido CHARACTER VARYING(20)');
347                }
348
349                /* reconnect to the previous database */
350                $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
351                $GLOBALS['setup_info']['workflow']['currentver'] = '2.4.1';
352                return $GLOBALS['setup_info']['workflow']['currentver'];
353        }
354?>
Note: See TracBrowser for help on using the repository browser.