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

Revision 5311, 16.5 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2409 - Corrigido tables_update da API e dos módulos que possuem.

  • 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        $test[] = '2.2.1';
213        function workflow_upgrade2_2_1()
214        {
215                #updating the current version
216                $GLOBALS['setup_info']['workflow']['currentver'] = '2.2.6';
217        return $GLOBALS['setup_info']['workflow']['currentver'];
218        }
219        $test[] = '2.2.6';
220        function workflow_upgrade2_2_6()
221        {
222                #updating the current version
223                $GLOBALS['setup_info']['workflow']['currentver'] = '2.3.0';
224        return $GLOBALS['setup_info']['workflow']['currentver'];
225        }
226        $test[] = '2.3.0';
227        function workflow_upgrade2_3_0()
228        {
229                #updating the current version
230               
231                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('en','workflow','Reports','Reports') ");
232               
233                $GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('pt-br','workflow','Reports','Relatórios') "); 
234               
235                $workflowHostInfo = extractDatabaseParameters();
236
237                        /* connect to workflow database */
238                        $workflowDB = $GLOBALS['phpgw']->ADOdb;
239                        if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
240                        {
241                                /* creating table substitution */
242                                $workflowDB->query('CREATE SCHEMA listagem AUTHORIZATION postgres; GRANT ALL ON SCHEMA listagem TO postgres; GRANT ALL ON SCHEMA listagem TO admin_workflow;');
243               
244                        $workflowDB->query("CREATE TABLE listagem.listagem
245                                                        (
246                                                          lstoid serial NOT NULL,
247                                                          lstversao integer,
248                                                          lstidlistagem text NOT NULL,
249                                                          lstdescricao text,
250                                                          lstnome text NOT NULL,
251                                                          lsttitulo text NOT NULL,
252                                                          lstsql text,
253                                                          lstexibe_header boolean,
254                                                          lstexibe_totalizadores boolean,
255                                                          lstexibe_subtotais boolean,
256                                                          lstexibe_qtdregistros boolean,
257                                                          lstexibe_checkbox boolean,
258                                                          lstexibe_csv boolean,
259                                                          lstexibe_legendatopo boolean,
260                                                          lstexibe_legendarodape boolean,
261                                                          lstexibe_titagrupamento boolean,
262                                                          lstexibe_agrupamento_alfabetico boolean,
263                                                          lstagrupamento_campo text,
264                                                          lstagrupamento_titulo text,
265                                                          lstmsg_totalizador text DEFAULT 'TOTAL:'::text,
266                                                          lstmsg_subtotalizador text DEFAULT 'SUB-TOTAL:'::text,
267                                                          lstmsg_registrosencontrados text DEFAULT 'registro(s) encontrado(s).'::text,
268                                                          lstmsg_nenhumresultado text DEFAULT 'Nenhum resultado encontrado.'::text,
269                                                          lstexclusao timestamp without time zone,
270                                                          lstexibe_resultados boolean DEFAULT true,
271                                                          CONSTRAINT lstoid_pkey PRIMARY KEY (lstoid)
272                                                        )
273                                                        WITHOUT OIDS;
274                                                        ALTER TABLE listagem.listagem OWNER TO postgres;
275                                                        GRANT ALL ON TABLE listagem.listagem TO postgres;
276                                                        GRANT ALL ON TABLE listagem.listagem TO admin_workflow;");
277
278
279                        $workflowDB->query("CREATE TABLE listagem.listagem_coluna
280                                                        (
281                                                          lslcoid serial NOT NULL,
282                                                          lslclstoid integer NOT NULL,
283                                                          lslcidcoluna text NOT NULL,
284                                                          lslcordem integer,
285                                                          lslctipo text,
286                                                          lslctitulo text,
287                                                          lslchtml text,
288                                                          lslcalign character varying(10),
289                                                          lslcwidth character varying(10),
290                                                          lslcnowrap boolean,
291                                                          lslcvisivel boolean,
292                                                          lslcexibe_csv boolean,
293                                                          lslccalculada boolean,
294                                                          lslccheckbox boolean,
295                                                          lslclink text,
296                                                          lslclink_blank boolean,
297                                                          lslclink_condicao text DEFAULT '1'::text,
298                                                          lslctotalizador_condicao text DEFAULT '1'::text,
299                                                          lslcsubtotalizador_condicao text DEFAULT '1'::text,
300                                                          lslccheckbox_condicao text DEFAULT '1'::text,
301                                                          CONSTRAINT lslcoid_pkey PRIMARY KEY (lslcoid),
302                                                          CONSTRAINT listagem_coluna_lslclstoid_fkey FOREIGN KEY (lslclstoid)
303                                                              REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
304                                                              ON UPDATE NO ACTION ON DELETE NO ACTION
305                                                        )
306                                                        WITHOUT OIDS;
307                                                        ALTER TABLE listagem.listagem_coluna OWNER TO postgres;
308                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO postgres;
309                                                        GRANT ALL ON TABLE listagem.listagem_coluna TO admin_workflow;");
310
311                       
312                        $workflowDB->query("CREATE TABLE listagem.listagem_indicador
313                                                                (
314                                                                  lsioid serial NOT NULL,
315                                                                  lsilstoid integer NOT NULL,
316                                                                  lsiidindicador text,
317                                                                  lsitipo character(1),
318                                                                  lsiimagem text,
319                                                                  lsilegenda text,
320                                                                  lsilegenda_csv text,
321                                                                  lsicondicao text DEFAULT '1'::text,
322                                                                  CONSTRAINT lsioid_pkey PRIMARY KEY (lsioid),
323                                                                  CONSTRAINT listagem_indicador_lsilstoid_fkey FOREIGN KEY (lsilstoid)
324                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
325                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
326                                                                )
327                                                                WITHOUT OIDS;
328                                                                ALTER TABLE listagem.listagem_indicador OWNER TO postgres;
329                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO postgres;
330                                                                GRANT ALL ON TABLE listagem.listagem_indicador TO admin_workflow;");
331
332                       
333                        $workflowDB->query("CREATE TABLE listagem.listagem_parametro
334                                                                (
335                                                                  lspoid serial NOT NULL,
336                                                                  lsplstoid integer NOT NULL,
337                                                                  lspidparametro text,
338                                                                  lsptitulo text,
339                                                                  lsptipo text,
340                                                                  lspvalor_padrao text,
341                                                                  lspobrigatorio boolean,
342                                                                  CONSTRAINT lspoid_pkey PRIMARY KEY (lspoid),
343                                                                  CONSTRAINT listagem_parametro_lsplstoid_fkey FOREIGN KEY (lsplstoid)
344                                                                      REFERENCES listagem.listagem (lstoid) MATCH SIMPLE
345                                                                      ON UPDATE NO ACTION ON DELETE NO ACTION
346                                                                )
347                                                                WITHOUT OIDS;
348                                                                ALTER TABLE listagem.listagem_parametro OWNER TO postgres;
349                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO postgres;
350                                                                GRANT ALL ON TABLE listagem.listagem_parametro TO admin_workflow;");
351                                                               
352                                                               
353                                                               
354                       
355                                $workflowDB->query("CREATE SEQUENCE listagem.listagem_coluna_lslcoid_seq
356                                  INCREMENT 1
357                                  MINVALUE 1
358                                  MAXVALUE 9223372036854775807
359                                  START 1
360                                  CACHE 1;
361                                ALTER TABLE listagem.listagem_coluna_lslcoid_seq OWNER TO postgres;
362                               
363                               
364                                CREATE SEQUENCE listagem.listagem_indicador_lsioid_seq
365                                  INCREMENT 1
366                                  MINVALUE 1
367                                  MAXVALUE 9223372036854775807
368                                  START 1
369                                  CACHE 1;
370                                ALTER TABLE listagem.listagem_indicador_lsioid_seq OWNER TO postgres;
371                               
372                               
373                                CREATE SEQUENCE listagem.listagem_lstoid_seq
374                                  INCREMENT 1
375                                  MINVALUE 1
376                                  MAXVALUE 9223372036854775807
377                                  START 1
378                                  CACHE 1;
379                                ALTER TABLE listagem.listagem_lstoid_seq OWNER TO postgres;
380                               
381                               
382                                CREATE SEQUENCE listagem.listagem_parametro_lspoid_seq
383                                  INCREMENT 1
384                                  MINVALUE 1
385                                  MAXVALUE 9223372036854775807
386                                  START 1
387                                  CACHE 1;
388                                ALTER TABLE listagem.listagem_parametro_lspoid_seq OWNER TO postgres;");
389
390
391                        }
392               
393
394                $GLOBALS['setup_info']['workflow']['currentver'] = '2.4.0';
395                return $GLOBALS['setup_info']['workflow']['currentver'];
396        }
397?>
Note: See TracBrowser for help on using the repository browser.