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

Revision 5307, 16.1 KB checked in by pereira.jair, 12 years ago (diff)

Ticket #2416 - Inclusao da nova ferramenta de relatorios do workflow.

  • 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        // Since Expresso 1.2 using Workflow 1.8.04.000
43        $test[] = '1.8.04.000';
44        function workflow_upgrade1_8_04_000()
45        {
46                /* Create index for table egw_wf_workitems  */
47                if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
48                {
49                        $GLOBALS['phpgw']->ADOdb->query('CREATE INDEX egw_wf_workitems_wf_instance_id_idx ON egw_wf_workitems(wf_instance_id)');
50                }
51
52                #updating the current version
53                $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.05.000';
54                return $GLOBALS['setup_info']['workflow']['currentver'];
55        }
56
57        $test[] = '1.8.05.000';
58        function workflow_upgrade1_8_05_000()
59        {
60                /* Alter tables of orgchart */
61                if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
62                {
63                        $workflowHostInfo = extractDatabaseParameters();
64
65                        /* connect to workflow database */
66                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
67                        if ($workflowDB->connect($workflowHostInfo['host'].":".$workflowHostInfo['port'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
68                        {
69                                /* add the new columns */
70                                $workflowDB->query('ALTER TABLE public.funcionario ADD COLUMN titulo CHARACTER VARYING(30)');
71                                $workflowDB->query('ALTER TABLE public.organizacao ADD COLUMN sitio CHARACTER VARYING(100)');
72                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN empresa CHARACTER VARYING(100)');
73                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN endereco CHARACTER VARYING(100)');
74                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN complemento CHARACTER VARYING(50)');
75                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cep CHARACTER VARYING(9)');
76                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN bairro CHARACTER VARYING(30)');
77                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cidade CHARACTER VARYING(50)');
78                                $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN uf CHARACTER(2)');
79
80                                /* create table telefone */
81                                $workflowDB->query('CREATE TABLE public.telefone (telefone_id serial NOT NULL, descricao character varying(50) NOT NULL, numero character varying(50) NOT NULL, organizacao_id integer NOT NULL)');
82                                $workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT telefone_pkey PRIMARY KEY (telefone_id)');
83                                $workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
84                                $workflowDB->query("GRANT ALL ON TABLE public.telefone TO admin_workflow");
85                                $workflowDB->query("GRANT ALL ON TABLE public.telefone TO postgres");
86                                $workflowDB->query("GRANT SELECT ON TABLE public.telefone TO public");
87                                $workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO admin_workflow");
88                                $workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO postgres");
89                                $workflowDB->query("GRANT SELECT ON TABLE public.telefone_telefone_id_seq TO public");
90                        }
91
92                        /* reconnect to the previous database */
93                        $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'].":".$workflowHostInfo['port'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
94                }
95                #updating the current version
96                $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.06.000';
97                return $GLOBALS['setup_info']['workflow']['currentver'];
98        }
99
100        $test[] = '1.8.06.000';
101        function workflow_upgrade1_8_06_000()
102        {
103                #updating the current version
104                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.000';
105                return $GLOBALS['setup_info']['workflow']['currentver'];
106        }
107        $test[] = '2.0.000';
108        function workflow_upgrade2_0_000()
109        {
110                #updating the current version
111                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.001';
112                return $GLOBALS['setup_info']['workflow']['currentver'];
113        }
114        $test[] = '2.0.001';
115        function workflow_upgrade2_0_001()
116        {
117                #updating the current version
118                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.002';
119                return $GLOBALS['setup_info']['workflow']['currentver'];
120        }
121        $test[] = '2.0.002';
122        function workflow_upgrade2_0_002()
123        {
124                #updating the current version
125                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.003';
126                return $GLOBALS['setup_info']['workflow']['currentver'];
127        }
128        $test[] = '2.0.003';
129        function workflow_upgrade2_0_003()
130        {
131                #updating the current version
132                $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.004';
133                return $GLOBALS['setup_info']['workflow']['currentver'];
134        }
135        $test[] = '2.0.004';
136        function workflow_upgrade2_0_004()
137        {
138                #updating the current version
139                $GLOBALS['setup_info']['workflow']['currentver'] = '2.1.000';
140                return $GLOBALS['setup_info']['workflow']['currentver'];
141        }
142        $test[] = '2.1.000';
143        function workflow_upgrade2_1_000()
144        {
145                if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
146                {
147                        /* updating log level */
148                        $values = array('0', 'workflow', 'log_level');
149                        $GLOBALS['phpgw']->ADOdb->query('UPDATE phpgw_config SET config_value=? WHERE config_app=? AND config_name=?', $values);
150
151                        $workflowHostInfo = extractDatabaseParameters();
152
153                        /* connect to workflow database */
154                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
155                        if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
156                        {
157                                /* creating table substitution */
158                                $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)');
159
160                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT substituicao_pkey PRIMARY KEY (substituicao_id)');
161                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT "$1" FOREIGN KEY (area_id) REFERENCES area(area_id)');
162                                $workflowDB->query('ALTER TABLE ONLY public.substituicao ADD CONSTRAINT "$2" FOREIGN KEY (funcionario_id) REFERENCES funcionario(funcionario_id)');
163
164                                /* granting privilegies */
165                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao TO admin_workflow");
166                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao TO postgres");
167                                $workflowDB->query("GRANT SELECT ON TABLE public.substituicao TO public");
168                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao_substituicao_id_seq TO admin_workflow");
169                                $workflowDB->query("GRANT ALL ON TABLE public.substituicao_substituicao_id_seq TO postgres");
170                                $workflowDB->query("GRANT SELECT ON TABLE public.substituicao_substituicao_id_seq TO public");
171
172                                /* migrating records */
173                                $result = $workflowDB->query('SELECT area_id, substituto_funcionario_id FROM area WHERE substituto_funcionario_id IS NOT NULL');
174                                if ($result)
175                                        while ($row = $result->fetchRow()) {
176                                                $values = array($row['area_id'], $row['substituto_funcionario_id']);
177                                                $workflowDB->query('INSERT INTO substituicao (area_id, funcionario_id, data_inicio, data_fim) VALUES (?, ?, CURRENT_DATE, CURRENT_DATE+integer \'7\')', $values);
178                                        }
179
180
181                                /* erasing old atributes */
182                                $workflowDB->query("ALTER TABLE area DROP COLUMN substituto_funcionario_id");
183                        }
184
185                        /* reconnect to the previous database */
186                        $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
187
188                        /* removing primary key of egw_wf_interinstance_relations */
189                        $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations DROP CONSTRAINT egw_wf_interinstance_relations_pkey');
190
191                        /* removing wf_parent_activity_id column from egw_wf_interinstance_relations table */
192                        $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations DROP COLUMN wf_parent_activity_id');
193
194                        /* adding primary key without the column removed */
195                        $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)');
196                       
197                        /* Update the organogram level of administration off all users from 0 to 1. */
198                        $GLOBALS['phpgw']->ADOdb->query('UPDATE egw_wf_admin_access set nivel = 1 WHERE tipo = \'ORG\' and nivel = 0');
199                }
200
201                #updating the current version
202                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.000';
203                return $GLOBALS['setup_info']['workflow']['currentver'];
204        }
205        $test[] = '2.2.000';
206        function workflow_upgrade2_2_000()
207        {
208                #updating the current version
209                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.1';
210                return $GLOBALS['setup_info']['workflow']['currentver'];
211        }
212       
213        $test[] = '2.4.000';
214        function workflow_upgrade2_4_000()
215        {
216                #updating the current version
217               
218                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('en','workflow','Reports','Reports') ");
219               
220                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('pt-br','workflow','Reports','Relatórios') "); 
221               
222                $workflowHostInfo = extractDatabaseParameters();
223
224                        /* connect to workflow database */
225                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
226                        if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
227                        {
228                                /* creating table substitution */
229                                $workflowDB->query('CREATE SCHEMA listagem AUTHORIZATION postgres; GRANT ALL ON SCHEMA listagem TO postgres; GRANT ALL ON SCHEMA listagem TO admin_workflow;');
230               
231                        $workflowDB->query("CREATE TABLE listagem.listagem
232                                                        (
233                                                          lstoid serial NOT NULL,
234                                                          lstversao integer,
235                                                          lstidlistagem text NOT NULL,
236                                                          lstdescricao text,
237                                                          lstnome text NOT NULL,
238                                                          lsttitulo text NOT NULL,
239                                                          lstsql text,
240                                                          lstexibe_header boolean,
241                                                          lstexibe_totalizadores boolean,
242                                                          lstexibe_subtotais boolean,
243                                                          lstexibe_qtdregistros boolean,
244                                                          lstexibe_checkbox boolean,
245                                                          lstexibe_csv boolean,
246                                                          lstexibe_legendatopo boolean,
247                                                          lstexibe_legendarodape boolean,
248                                                          lstexibe_titagrupamento boolean,
249                                                          lstexibe_agrupamento_alfabetico boolean,
250                                                          lstagrupamento_campo text,
251                                                          lstagrupamento_titulo text,
252                                                          lstmsg_totalizador text DEFAULT 'TOTAL:'::text,
253                                                          lstmsg_subtotalizador text DEFAULT 'SUB-TOTAL:'::text,
254                                                          lstmsg_registrosencontrados text DEFAULT 'registro(s) encontrado(s).'::text,
255                                                          lstmsg_nenhumresultado text DEFAULT 'Nenhum resultado encontrado.'::text,
256                                                          lstexclusao timestamp without time zone,
257                                                          lstexibe_resultados boolean DEFAULT true,
258                                                          CONSTRAINT lstoid_pkey PRIMARY KEY (lstoid)
259                                                        )
260                                                        WITHOUT OIDS;
261                                                        ALTER TABLE listagem.listagem OWNER TO postgres;
262                                                        GRANT ALL ON TABLE listagem.listagem TO postgres;
263                                                        GRANT ALL ON TABLE listagem.listagem TO admin_workflow;");
264
265
266                        $workflowDB->query("CREATE TABLE listagem.listagem_coluna
267                                                        (
268                                                          lslcoid serial NOT NULL,
269                                                          lslclstoid integer NOT NULL,
270                                                          lslcidcoluna text NOT NULL,
271                                                          lslcordem integer,
272                                                          lslctipo text,
273                                                          lslctitulo text,
274                                                          lslchtml text,
275                                                          lslcalign character varying(10),
276                                                          lslcwidth character varying(10),
277                                                          lslcnowrap boolean,
278                                                          lslcvisivel boolean,
279                                                          lslcexibe_csv boolean,
280                                                          lslccalculada boolean,
281                                                          lslccheckbox boolean,
282                                                          lslclink text,
283                                                          lslclink_blank boolean,
284                                                          lslclink_condicao text DEFAULT '1'::text,
285                                                          lslctotalizador_condicao text DEFAULT '1'::text,
286                                                          lslcsubtotalizador_condicao text DEFAULT '1'::text,
287                                                          lslccheckbox_condicao text DEFAULT '1'::text,
288                                                          CONSTRAINT lslcoid_pkey PRIMARY KEY (lslcoid),
289                                                          CONSTRAINT listagem_coluna_lslclstoid_fkey FOREIGN KEY (lslclstoid)
290                                                              REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
291                                                              ON UPDATE NO ACTION ON DELETE NO ACTION
292                                                        )
293                                                        WITHOUT OIDS;
294                                                        ALTER TABLE listagem.listagem_coluna OWNER TO postgres;
295                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO postgres;
296                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO admin_workflow;");
297
298                       
299                        $workflowDB->query("CREATE TABLE listagem.listagem_indicador
300                                                                (
301                                                                  lsioid serial NOT NULL,
302                                                                  lsilstoid integer NOT NULL,
303                                                                  lsiidindicador text,
304                                                                  lsitipo character(1),
305                                                                  lsiimagem text,
306                                                                  lsilegenda text,
307                                                                  lsilegenda_csv text,
308                                                                  lsicondicao text DEFAULT '1'::text,
309                                                                  CONSTRAINT lsioid_pkey PRIMARY KEY (lsioid),
310                                                                  CONSTRAINT listagem_indicador_lsilstoid_fkey FOREIGN KEY (lsilstoid)
311                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
312                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
313                                                                )
314                                                                WITHOUT OIDS;
315                                                                ALTER TABLE listagem.listagem_indicador OWNER TO postgres;
316                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO postgres;
317                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO admin_workflow;");
318
319                       
320                        $workflowDB->query("CREATE TABLE listagem.listagem_parametro
321                                                                (
322                                                                  lspoid serial NOT NULL,
323                                                                  lsplstoid integer NOT NULL,
324                                                                  lspidparametro text,
325                                                                  lsptitulo text,
326                                                                  lsptipo text,
327                                                                  lspvalor_padrao text,
328                                                                  lspobrigatorio boolean,
329                                                                  CONSTRAINT lspoid_pkey PRIMARY KEY (lspoid),
330                                                                  CONSTRAINT listagem_parametro_lsplstoid_fkey FOREIGN KEY (lsplstoid)
331                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
332                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
333                                                                )
334                                                                WITHOUT OIDS;
335                                                                ALTER TABLE listagem.listagem_parametro OWNER TO postgres;
336                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO postgres;
337                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO admin_workflow;");
338                                                               
339                                                               
340                                                               
341                       
342                                $workflowDB->query("CREATE SEQUENCE listagem.listagem_coluna_lslcoid_seq
343                                  INCREMENT 1
344                                  MINVALUE 1
345                                  MAXVALUE 9223372036854775807
346                                  START 1
347                                  CACHE 1;
348                                ALTER TABLE listagem.listagem_coluna_lslcoid_seq OWNER TO postgres;
349                               
350                               
351                                CREATE SEQUENCE listagem.listagem_indicador_lsioid_seq
352                                  INCREMENT 1
353                                  MINVALUE 1
354                                  MAXVALUE 9223372036854775807
355                                  START 1
356                                  CACHE 1;
357                                ALTER TABLE listagem.listagem_indicador_lsioid_seq OWNER TO postgres;
358                               
359                               
360                                CREATE SEQUENCE listagem.listagem_lstoid_seq
361                                  INCREMENT 1
362                                  MINVALUE 1
363                                  MAXVALUE 9223372036854775807
364                                  START 1
365                                  CACHE 1;
366                                ALTER TABLE listagem.listagem_lstoid_seq OWNER TO postgres;
367                               
368                               
369                                CREATE SEQUENCE listagem.listagem_parametro_lspoid_seq
370                                  INCREMENT 1
371                                  MINVALUE 1
372                                  MAXVALUE 9223372036854775807
373                                  START 1
374                                  CACHE 1;
375                                ALTER TABLE listagem.listagem_parametro_lspoid_seq OWNER TO postgres;");
376
377
378                        }
379               
380
381                $GLOBALS['setup_info']['workflow']['currentver'] = '2.4.0';
382                return $GLOBALS['setup_info']['workflow']['currentver'];
383        }
384       
385       
386?>
Note: See TracBrowser for help on using the repository browser.