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

Revision 4180, 10.0 KB checked in by niltonneto, 10 years ago (diff)

Ticket #1804 - Corrigido numeração das versões de acordo com o novo modelo.

  • 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?>
Note: See TracBrowser for help on using the repository browser.