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 | 'user' => $GLOBALS['phpgw']->ADOdb->user, |
---|
23 | 'password' => $GLOBALS['phpgw']->ADOdb->password); |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | $hostInfo = "dbname= host= password= port= user= " . $GLOBALS['phpgw']->ADOdb->host; |
---|
28 | $hostInfo = explode(' ', $hostInfo); |
---|
29 | foreach ($hostInfo as $parameter) |
---|
30 | { |
---|
31 | $currentParameter = explode('=', $parameter); |
---|
32 | $workflowHostInfo[$currentParameter[0]] = isset($currentParameter[1]) ? $currentParameter[1] : ""; |
---|
33 | } |
---|
34 | } |
---|
35 | if (($workflowHostInfo['password']{0} == "'") && ($workflowHostInfo['password']{strlen($workflowHostInfo['password'])-1} == "'")) |
---|
36 | $workflowHostInfo['password'] = substr($workflowHostInfo['password'], 1, strlen($workflowHostInfo['password']) - 2); |
---|
37 | |
---|
38 | return $workflowHostInfo; |
---|
39 | } |
---|
40 | |
---|
41 | $test[] = '1.0.1'; |
---|
42 | function workflow_upgrade1_0_1() |
---|
43 | { |
---|
44 | # add an instance_supplements table |
---|
45 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_instance_supplements', |
---|
46 | array( |
---|
47 | 'fd' => array( |
---|
48 | 'wf_supplement_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
49 | 'wf_supplement_type' => array('type' => 'varchar', 'precision' => '50', 'nullable' => True), |
---|
50 | 'wf_supplement_name' => array('type' => 'varchar', 'precision' => '100', 'nullable' => True), |
---|
51 | 'wf_supplement_value' => array('type' => 'text', 'nullable' => True), |
---|
52 | 'wf_workitem_id' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
53 | 'wf_supplement_blob' => array('type' => 'blob', 'nullable' => True) |
---|
54 | ), |
---|
55 | 'pk' => array('wf_supplement_id'), |
---|
56 | 'fk' => array(), |
---|
57 | 'ix' => array(), |
---|
58 | 'uc' => array() |
---|
59 | ) |
---|
60 | ); |
---|
61 | |
---|
62 | #Add in activities table is_reassign_box, is_report, default_user and default group |
---|
63 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_is_reassign_box',array('type' => 'char', 'precision' => 1, 'nullable' => True)); |
---|
64 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_is_report',array('type' => 'char', 'precision' => 1, 'nullable' => True)); |
---|
65 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_default_user', array('type' => 'varchar', 'precision' => '200', 'nullable' => True, 'default' => '*')); |
---|
66 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_default_group', array('type' => 'varchar', 'precision' => '200', 'nullable' => True, 'default' => '*')); |
---|
67 | |
---|
68 | #Add in instance_activities table the group field |
---|
69 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_instance_activities' ,'wf_group',array('type' => 'varchar', 'precision' => 200, 'nullable' => True, 'default' => '*')); |
---|
70 | |
---|
71 | #Add in instance table the name, and the priority, we keep the properties for the moment |
---|
72 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_instances' ,'wf_priority',array('type' => 'int', 'precision' => 4, 'nullable' => True)); |
---|
73 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_instances' ,'wf_name',array('type' => 'varchar', 'precision' => 120, 'nullable' => True)); |
---|
74 | |
---|
75 | #Add in workitems table note and action |
---|
76 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_workitems' ,'wf_note',array('type' => 'text', 'precision' => 50, 'nullable' => True)); |
---|
77 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_workitems' ,'wf_action',array('type' => 'text', 'precision' => 50, 'nullable' => True)); |
---|
78 | |
---|
79 | #Add in user_roles table the account type |
---|
80 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_user_roles' ,'wf_account_type',array('type' => 'char', 'precision' => 1, 'nullable' => True, 'default' => 'u')); |
---|
81 | #modifying the sequence as well |
---|
82 | #we need a RefreshTable |
---|
83 | $GLOBALS['phpgw_setup']->oProc->RefreshTable('egw_wf_user_roles' ,array( |
---|
84 | 'fd' => array( |
---|
85 | 'wf_role_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
86 | 'wf_p_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
87 | 'wf_user' => array('type' => 'varchar', 'precision' => '200', 'nullable' => False), |
---|
88 | 'wf_account_type' => array('type' => 'char', 'precision' => '1', 'nullable' => True, 'default' => 'u'), |
---|
89 | ), |
---|
90 | 'pk' => array('wf_role_id', 'wf_user', 'wf_account_type'), |
---|
91 | 'fk' => array(), |
---|
92 | 'ix' => array(), |
---|
93 | 'uc' => array() |
---|
94 | )); |
---|
95 | |
---|
96 | #updating the current version |
---|
97 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.00.000'; |
---|
98 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
99 | } |
---|
100 | |
---|
101 | $test[] = '1.1.00.000'; |
---|
102 | function workflow_upgrade1_1_00_000() |
---|
103 | { |
---|
104 | # add a process_config table |
---|
105 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_process_config', |
---|
106 | array( |
---|
107 | 'fd' => array( |
---|
108 | 'wf_p_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
109 | 'wf_config_name' => array('type' => 'varchar', 'precision' => '255', 'nullable' => False), |
---|
110 | 'wf_config_value' => array('type' => 'text', 'nullable' => True), |
---|
111 | 'wf_config_value_int' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
112 | ), |
---|
113 | 'pk' => array('wf_p_id','wf_config_name'), |
---|
114 | 'fk' => array(), |
---|
115 | 'ix' => array(), |
---|
116 | 'uc' => array() |
---|
117 | ) |
---|
118 | ); |
---|
119 | |
---|
120 | //change de default value for priority |
---|
121 | |
---|
122 | |
---|
123 | #updating the current version |
---|
124 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.01.000'; |
---|
125 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
126 | } |
---|
127 | |
---|
128 | $test[] = '1.1.01.000'; |
---|
129 | function workflow_upgrade1_1_01_000() |
---|
130 | { |
---|
131 | #remove unused 'new' fields in activity and add a agent key |
---|
132 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_activities', '', 'wf_is_reassign_box'); |
---|
133 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_activities', '', 'wf_is_report'); |
---|
134 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_activities', '', 'wf_default_group'); |
---|
135 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_agent', array('type' => 'int', 'precision' => '4', 'nullable' => True)); |
---|
136 | |
---|
137 | #add a readonly attribute to role/activty mapping |
---|
138 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activity_roles' ,'wf_readonly', array('type' => 'int', 'precision' => '1', 'nullable' => False, 'default'=> 0)); |
---|
139 | |
---|
140 | #add a instance category attribute |
---|
141 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_instances' ,'wf_category', array('type' => 'int', 'precision'=>'4', 'nullable' => True)); |
---|
142 | |
---|
143 | #updating the current version |
---|
144 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.02.000'; |
---|
145 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | $test[] = '1.1.02.000'; |
---|
150 | function workflow_upgrade1_1_02_000() |
---|
151 | { |
---|
152 | //drop the agent key in activity, we need something more complex in fact |
---|
153 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_activities','','wf_agent'); |
---|
154 | |
---|
155 | //add the agent table, link between activities and agents |
---|
156 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_activity_agents', |
---|
157 | array( |
---|
158 | 'fd' => array( |
---|
159 | 'wf_activity_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
160 | 'wf_agent_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
161 | 'wf_agent_type' => array('type' => 'varchar', 'precision' => '15', 'nullable' => False), |
---|
162 | ), |
---|
163 | 'pk' => array('wf_activity_id', 'wf_agent_id'), |
---|
164 | 'fk' => array(), |
---|
165 | 'ix' => array(), |
---|
166 | 'uc' => array() |
---|
167 | ) |
---|
168 | ); |
---|
169 | |
---|
170 | // add the mail_smtp agent table |
---|
171 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_agent_mail_smtp', |
---|
172 | array( |
---|
173 | 'fd' => array( |
---|
174 | 'wf_agent_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
175 | 'wf_to' => array('type' => 'varchar', 'precision' => '255', 'nullable' => False, 'default' => '%roles%'), |
---|
176 | 'wf_cc' => array('type' => 'varchar', 'precision' => '255', 'nullable' => True), |
---|
177 | 'wf_bcc' => array('type' => 'varchar', 'precision' => '255', 'nullable' => True), |
---|
178 | 'wf_from' => array('type' => 'varchar', 'precision' => '255', 'nullable' => True, 'default' => '%user%'), |
---|
179 | 'wf_replyTo' => array('type' => 'varchar', 'precision' => '255', 'nullable' => True, 'default' => '%user%'), |
---|
180 | 'wf_subject' => array('type' => 'varchar', 'precision' => '255', 'nullable' => True), |
---|
181 | 'wf_message' => array('type' => 'text', 'nullable' => True), |
---|
182 | 'wf_send_mode' => array('type' => 'int', 'precision' => '4', 'nullable' => True, 'default' => 0), |
---|
183 | ), |
---|
184 | 'pk' => array('wf_agent_id'), |
---|
185 | 'fk' => array(), |
---|
186 | 'ix' => array(), |
---|
187 | 'uc' => array() |
---|
188 | ) |
---|
189 | ); |
---|
190 | |
---|
191 | #updating the current version |
---|
192 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.03.000'; |
---|
193 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
194 | } |
---|
195 | |
---|
196 | $test[] = '1.1.03.000'; |
---|
197 | function workflow_upgrade1_1_03_000() |
---|
198 | { |
---|
199 | //change type of wf_next_user to handle serialization -> multiple states if instance has multiple activities running |
---|
200 | //we will loose current wf_next_activity but the update should'nt be made when instances are running and this is |
---|
201 | //a field needed only at runtime, normally. |
---|
202 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_instances','','wf_next_activity'); |
---|
203 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_instances' ,'wf_next_activity', array('type' => 'blob', 'nullable' => True)); |
---|
204 | |
---|
205 | #updating the current version |
---|
206 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.04.000'; |
---|
207 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
208 | } |
---|
209 | |
---|
210 | $test[] = '1.1.04.000'; |
---|
211 | function workflow_upgrade1_1_04_000() |
---|
212 | { |
---|
213 | //unused column. Notice I had to do this manually with MAIN versions of phpgwapi/class.schema_proc.inc.php |
---|
214 | $GLOBALS['phpgw_setup']->oProc->DropColumn('egw_wf_instance_activities','','wf_group'); |
---|
215 | |
---|
216 | //Adding some indexes on some tables: |
---|
217 | |
---|
218 | //we need a RefreshTable for that |
---|
219 | $GLOBALS['phpgw_setup']->oProc->RefreshTable('egw_wf_instance_activities' ,array( |
---|
220 | 'fd' => array( |
---|
221 | 'wf_instance_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
222 | 'wf_activity_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
223 | 'wf_started' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
224 | 'wf_ended' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
225 | 'wf_user' => array('type' => 'varchar', 'precision' => '200', 'nullable' => True), |
---|
226 | 'wf_status' => array('type' => 'varchar', 'precision' => '25', 'nullable' => True), |
---|
227 | ), |
---|
228 | 'pk' => array('wf_instance_id', 'wf_activity_id'), |
---|
229 | 'fk' => array(), |
---|
230 | 'ix' => array(array('wf_activity_id'),array('wf_instance_id'), array('wf_user')), |
---|
231 | 'uc' => array() |
---|
232 | )); |
---|
233 | // we change some indexes |
---|
234 | // we need a RefreshTable |
---|
235 | $GLOBALS['phpgw_setup']->oProc->RefreshTable('egw_wf_instances' ,array( |
---|
236 | 'fd' => array( |
---|
237 | 'wf_instance_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
238 | 'wf_p_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
239 | 'wf_started' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
240 | 'wf_owner' => array('type' => 'varchar', 'precision' => '200', 'nullable' => True), |
---|
241 | 'wf_next_activity' => array('type' => 'blob', 'nullable' => True), |
---|
242 | 'wf_next_user' => array('type' => 'varchar', 'precision' => '200', 'nullable' => True), |
---|
243 | 'wf_ended' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
244 | 'wf_status' => array('type' => 'varchar', 'precision' => '25', 'nullable' => True), |
---|
245 | 'wf_priority' => array('type' => 'int', 'precision' => '4', 'nullable' => True, 'default'=> 0), |
---|
246 | 'wf_properties' => array('type' => 'blob', 'nullable' => True), |
---|
247 | 'wf_name' => array('type' => 'varchar', 'precision'=>'120', 'nullable' => True), |
---|
248 | 'wf_category' => array('type' => 'int', 'precision'=>'4', 'nullable' => True), |
---|
249 | ), |
---|
250 | 'pk' => array('wf_instance_id'), |
---|
251 | 'fk' => array(), |
---|
252 | 'ix' => array(array('wf_owner'), array('wf_status')), |
---|
253 | 'uc' => array() |
---|
254 | )); |
---|
255 | // we change some indexes |
---|
256 | // we need a RefreshTable |
---|
257 | $GLOBALS['phpgw_setup']->oProc->RefreshTable('egw_wf_processes' ,array( |
---|
258 | 'fd' => array( |
---|
259 | 'wf_p_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
260 | 'wf_name' => array('type' => 'varchar', 'precision' => '80', 'nullable' => True), |
---|
261 | 'wf_is_valid' => array('type' => 'char', 'precision' => '1', 'nullable' => True), |
---|
262 | 'wf_is_active' => array('type' => 'char', 'precision' => '1', 'nullable' => True), |
---|
263 | 'wf_version' => array('type' => 'varchar', 'precision' => '12', 'nullable' => True), |
---|
264 | 'wf_description' => array('type' => 'text', 'nullable' => True), |
---|
265 | 'wf_last_modif' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
266 | 'wf_normalized_name' => array('type' => 'varchar', 'precision' => '80', 'nullable' => True), |
---|
267 | ), |
---|
268 | 'pk' => array('wf_p_id'), |
---|
269 | 'fk' => array(), |
---|
270 | 'ix' => array(array('wf_p_id','wf_is_active')), |
---|
271 | 'uc' => array() |
---|
272 | )); |
---|
273 | |
---|
274 | #updating the current version |
---|
275 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.1.05.000'; |
---|
276 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
277 | } |
---|
278 | |
---|
279 | $test[] = '1.1.05.000'; |
---|
280 | function workflow_upgrade1_1_05_000() |
---|
281 | { |
---|
282 | #serialized data is now stored with a Base64 encoding to ensure it work in all case (even with \' for example) |
---|
283 | //We gonna make our updates manually here: |
---|
284 | //they were an error (quotes) in the first version of this upgrade, if your database is MySQL you should |
---|
285 | //set the version to 1.1.05.000 in egw_applications and rerun this upgrade for old properties |
---|
286 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
287 | { |
---|
288 | $GLOBALS['phpgw']->ADOdb->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
289 | $result = $GLOBALS['phpgw']->ADOdb->query('select * from egw_wf_instances'); |
---|
290 | if (!(empty($result))) |
---|
291 | { |
---|
292 | while ($res = $result->fetchRow()) |
---|
293 | { |
---|
294 | $new_props = base64_encode($res['wf_properties']); |
---|
295 | $new_next = base64_encode($res['wf_next_activity']); |
---|
296 | $ok = $GLOBALS['phpgw']->ADOdb->query( |
---|
297 | 'update egw_wf_instances set wf_properties = ?, wf_next_activity=? where wf_instance_id = ?', |
---|
298 | array($new_props,$new_next, (int)$res['wf_instance_id']) |
---|
299 | ); |
---|
300 | } |
---|
301 | } |
---|
302 | $result = $GLOBALS['phpgw']->ADOdb->query('select * from egw_wf_workitems'); |
---|
303 | if (!(empty($result))) |
---|
304 | { |
---|
305 | while ($res = $result->fetchRow()) |
---|
306 | { |
---|
307 | $new_props = base64_encode($res['wf_properties']); |
---|
308 | $ok = $GLOBALS['phpgw']->ADOdb->query( |
---|
309 | 'update egw_wf_workitems set wf_properties = ? where wf_item_id = ?', |
---|
310 | array($new_props, (int)$res['wf_item_id']) |
---|
311 | ); |
---|
312 | } |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | #updating the current version |
---|
317 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.00.000'; |
---|
318 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
319 | } |
---|
320 | |
---|
321 | $test[] = '1.2.00.000'; |
---|
322 | function workflow_upgrade1_2_00_000() |
---|
323 | { |
---|
324 | #updating the current version |
---|
325 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.00.001'; |
---|
326 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
327 | } |
---|
328 | $test[] = '1.2.00.001'; |
---|
329 | function workflow_upgrade1_2_00_001() |
---|
330 | { |
---|
331 | #updating the current version |
---|
332 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.00.002'; |
---|
333 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
334 | } |
---|
335 | $test[] = '1.2.00.002'; |
---|
336 | function workflow_upgrade1_2_00_002() |
---|
337 | { |
---|
338 | #groups Ids are now negative in egroupware, we need to negative all user id which is positive and of type 'g' |
---|
339 | #code inspired by phpgwapi/setup/table_update.inc.php |
---|
340 | // convert all positive group id's to negative ones |
---|
341 | // this allows duplicate id for users and groups in ldap |
---|
342 | |
---|
343 | /* Celepar: não realizar esta atualização |
---|
344 | $where = false; |
---|
345 | list($table,$col,$where) = $data; |
---|
346 | $table = 'egw_wf_user_roles'; |
---|
347 | $col = 'wf_user'; |
---|
348 | $where = "wf_account_type='g' and (SUBSTR($col,1,1) <> '-')"; |
---|
349 | $set = $col.'='.$GLOBALS['egw_setup']->db->concat("'-'",$col); |
---|
350 | $query = "UPDATE $table SET $set WHERE $where"; |
---|
351 | //echo "<p>debug query: $query</p>\n"; |
---|
352 | $GLOBALS['egw_setup']->db->query($query,__LINE__,__FILE__); |
---|
353 | |
---|
354 | */ |
---|
355 | |
---|
356 | #updating the current version |
---|
357 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.000'; |
---|
358 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
359 | } |
---|
360 | |
---|
361 | $test[] = '1.2.01.000'; |
---|
362 | function workflow_upgrade1_2_01_000() |
---|
363 | { |
---|
364 | #updating the current version |
---|
365 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.001'; |
---|
366 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
367 | } |
---|
368 | |
---|
369 | $test[] = '1.2.01.001'; |
---|
370 | function workflow_upgrade1_2_01_001() |
---|
371 | { |
---|
372 | #updating the current version |
---|
373 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.002'; |
---|
374 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
375 | } |
---|
376 | |
---|
377 | $test[] = '1.2.01.002'; |
---|
378 | function workflow_upgrade1_2_01_002() |
---|
379 | { |
---|
380 | #updating the current version |
---|
381 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.003'; |
---|
382 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
383 | } |
---|
384 | |
---|
385 | $test[] = '1.2.01.003'; |
---|
386 | function workflow_upgrade1_2_01_003() |
---|
387 | { |
---|
388 | #updating the current version |
---|
389 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.004'; |
---|
390 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
391 | } |
---|
392 | |
---|
393 | $test[] = '1.2.01.004'; |
---|
394 | function workflow_upgrade1_2_01_004() |
---|
395 | { |
---|
396 | #updating the current version |
---|
397 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.2.01.005'; |
---|
398 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
399 | } |
---|
400 | |
---|
401 | $test[] = '1.2.01.005'; |
---|
402 | function workflow_upgrade1_2_01_005() |
---|
403 | { |
---|
404 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
405 | { |
---|
406 | $workflowHostInfo = extractDatabaseParameters(); |
---|
407 | |
---|
408 | /* create the workflow database */ |
---|
409 | $GLOBALS['phpgw']->ADOdb->query("CREATE DATABASE workflow WITH OWNER = postgres TEMPLATE = template0 ENCODING = 'LATIN1'"); |
---|
410 | $GLOBALS['phpgw']->ADOdb->query("CREATE USER admin_workflow WITH PASSWORD 'admin_workflow' NOCREATEDB NOCREATEUSER VALID UNTIL 'infinity'"); |
---|
411 | $GLOBALS['phpgw']->ADOdb->query("CREATE GROUP workflow"); |
---|
412 | $GLOBALS['phpgw']->ADOdb->query("ALTER GROUP workflow ADD USER admin_workflow"); |
---|
413 | $GLOBALS['phpgw']->ADOdb->query("GRANT workflow TO admin_workflow"); |
---|
414 | |
---|
415 | /* connect to the new database */ |
---|
416 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
417 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
418 | { |
---|
419 | /* create a sample application (Music CD Loan) */ |
---|
420 | $workflowDB->query("CREATE USER admin_cds WITH PASSWORD 'admin_cds' NOCREATEDB NOCREATEUSER VALID UNTIL 'infinity'"); |
---|
421 | $workflowDB->query("ALTER GROUP workflow ADD USER admin_cds"); |
---|
422 | $workflowDB->query("CREATE SCHEMA cds AUTHORIZATION admin_cds"); |
---|
423 | $workflowDB->query("GRANT ALL ON SCHEMA cds TO admin_cds"); |
---|
424 | $workflowDB->query("GRANT ALL ON SCHEMA cds TO postgres"); |
---|
425 | $workflowDB->query("CREATE TABLE cds.cdcollection(cdid int4 NOT NULL, title varchar(200), status varchar(40), usuario varchar(200), CONSTRAINT cdcollection_pkey PRIMARY KEY (cdid))"); |
---|
426 | $workflowDB->query("ALTER TABLE cds.cdcollection OWNER TO admin_cds"); |
---|
427 | $workflowDB->query("GRANT ALL ON TABLE cds.cdcollection TO postgres WITH GRANT OPTION"); |
---|
428 | $workflowDB->query("GRANT ALL ON TABLE cds.cdcollection TO admin_cds"); |
---|
429 | $workflowDB->query("COMMENT ON TABLE cds.cdcollection IS 'Exemplo de Empréstimo de CDs'"); |
---|
430 | $workflowDB->query("INSERT INTO cdcollection VALUES (1, 'Iron Maiden - Powerslave', 'disponivel', '')"); |
---|
431 | $workflowDB->query("INSERT INTO cdcollection VALUES (2, 'Pink Floyd - The Wall', 'disponivel', '')"); |
---|
432 | $workflowDB->query("INSERT INTO cdcollection VALUES (3, 'Deep Purple - Fireball', 'disponivel', '')"); |
---|
433 | |
---|
434 | /* create the new tables */ |
---|
435 | $workflowDB->query('CREATE TABLE organizacao (organizacao_id serial NOT NULL, nome character varying(20) NOT NULL, descricao character varying(100) NOT NULL)'); |
---|
436 | $workflowDB->query('CREATE TABLE area_status (area_status_id serial NOT NULL, organizacao_id integer NOT NULL, descricao character varying(50) NOT NULL, nivel integer NOT NULL)'); |
---|
437 | $workflowDB->query('CREATE TABLE centro_custo (organizacao_id integer NOT NULL, centro_custo_id serial NOT NULL, nm_centro_custo integer NOT NULL, grupo character varying(30), descricao character varying(100) NOT NULL)'); |
---|
438 | $workflowDB->query('CREATE TABLE localidade (organizacao_id integer NOT NULL, localidade_id serial NOT NULL, centro_custo_id integer, descricao character varying(50) NOT NULL)'); |
---|
439 | $workflowDB->query('CREATE TABLE funcionario (funcionario_id character varying NOT NULL, area_id integer NOT NULL, localidade_id integer NOT NULL, centro_custo_id integer NOT NULL, organizacao_id integer NOT NULL, funcionario_status_id integer NOT NULL)'); |
---|
440 | $workflowDB->query('CREATE TABLE area (organizacao_id integer NOT NULL, area_id serial NOT NULL, area_status_id integer NOT NULL, areasup_organizacao_id integer, superior_area_id integer, centro_custo_id integer, titular_funcionario_id character varying, substituto_funcionario_id character varying, sigla character varying(20) NOT NULL, descricao character varying(100) NOT NULL, ativa character varying(1) NOT NULL)'); |
---|
441 | $workflowDB->query('CREATE TABLE funcionario_status (funcionario_status_id serial NOT NULL, descricao character varying(50) NOT NULL)'); |
---|
442 | $workflowDB->query('CREATE TABLE admin_access (admin_access_id integer NOT NULL, tipo character(3) NOT NULL, numvalue smallint NOT NULL, nivel integer DEFAULT 0)'); |
---|
443 | $workflowDB->query('CREATE TABLE aplicacao_externa (apl_in_id serial NOT NULL, apl_st_nome character varying(50) NOT NULL, apl_st_descricao text, apl_st_imagem character varying(100), apl_st_endereco character varying(120) NOT NULL, apl_bt_autentica bit(1), apl_st_post text, apl_in_responsavel integer NOT NULL, apl_in_area integer NOT NULL)'); |
---|
444 | $workflowDB->query('CREATE TABLE aplicacao_externa_acl (apl_in_id integer NOT NULL, apl_in_uid integer NOT NULL)'); |
---|
445 | |
---|
446 | /* add the constraints */ |
---|
447 | $workflowDB->query('ALTER TABLE ONLY organizacao ADD CONSTRAINT organizacao_pkey PRIMARY KEY (organizacao_id)'); |
---|
448 | $workflowDB->query('ALTER TABLE ONLY area_status ADD CONSTRAINT areastatus_pkey PRIMARY KEY (area_status_id, organizacao_id)'); |
---|
449 | $workflowDB->query('ALTER TABLE ONLY centro_custo ADD CONSTRAINT centrocusto_pkey PRIMARY KEY (organizacao_id, centro_custo_id)'); |
---|
450 | $workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT localidade_pkey PRIMARY KEY (organizacao_id, localidade_id)'); |
---|
451 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT funcionario_pkey PRIMARY KEY (funcionario_id)'); |
---|
452 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT area_pkey PRIMARY KEY (organizacao_id, area_id)'); |
---|
453 | $workflowDB->query('ALTER TABLE ONLY funcionario_status ADD CONSTRAINT funcionario_status_pkey PRIMARY KEY (funcionario_status_id)'); |
---|
454 | $workflowDB->query('ALTER TABLE ONLY area_status ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
455 | $workflowDB->query('ALTER TABLE ONLY centro_custo ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
456 | $workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT "$1" FOREIGN KEY (centro_custo_id, organizacao_id) REFERENCES centro_custo(centro_custo_id, organizacao_id)'); |
---|
457 | $workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT "$2" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
458 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id, centro_custo_id) REFERENCES centro_custo(organizacao_id, centro_custo_id)'); |
---|
459 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$2" FOREIGN KEY (organizacao_id, localidade_id) REFERENCES localidade(organizacao_id, localidade_id)'); |
---|
460 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$1" FOREIGN KEY (superior_area_id, areasup_organizacao_id) REFERENCES area(area_id, organizacao_id)'); |
---|
461 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$2" FOREIGN KEY (centro_custo_id, organizacao_id) REFERENCES centro_custo(centro_custo_id, organizacao_id)'); |
---|
462 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$5" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
463 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$6" FOREIGN KEY (area_status_id, organizacao_id) REFERENCES area_status(area_status_id, organizacao_id)'); |
---|
464 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$3" FOREIGN KEY (organizacao_id, area_id) REFERENCES area(organizacao_id, area_id)'); |
---|
465 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$4" FOREIGN KEY (funcionario_status_id) REFERENCES funcionario_status(funcionario_status_id)'); |
---|
466 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$3" FOREIGN KEY (titular_funcionario_id) REFERENCES funcionario(funcionario_id)'); |
---|
467 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$4" FOREIGN KEY (substituto_funcionario_id) REFERENCES funcionario(funcionario_id)'); |
---|
468 | $workflowDB->query('ALTER TABLE ONLY admin_access ADD CONSTRAINT admin_access_pkey PRIMARY KEY (admin_access_id, tipo, numvalue)'); |
---|
469 | $workflowDB->query('ALTER TABLE ONLY aplicacao_externa ADD CONSTRAINT seq_aplicacao_externa PRIMARY KEY (apl_in_id)'); |
---|
470 | $workflowDB->query('ALTER TABLE ONLY aplicacao_externa_acl ADD CONSTRAINT pk_aplicacao_externa_acl PRIMARY KEY (apl_in_id, apl_in_uid)'); |
---|
471 | $workflowDB->query('ALTER TABLE ONLY aplicacao_externa_acl ADD CONSTRAINT fk01_aplicacao_externa_acl FOREIGN KEY (apl_in_id) REFERENCES aplicacao_externa(apl_in_id) ON UPDATE CASCADE ON DELETE CASCADE'); |
---|
472 | |
---|
473 | /* set the permissions to the database objects */ |
---|
474 | $dbObjects = array('organizacao', 'area_status', 'centro_custo', 'localidade', 'funcionario', 'area', 'funcionario_status', 'organizacao_organizacao_id_seq', 'area_status_area_status_id_seq', 'centro_custo_centro_custo_id_seq', 'localidade_localidade_id_seq', 'area_area_id_seq', 'funcionario_status_funcionario_status_id_seq', 'admin_access', 'aplicacao_externa', 'aplicacao_externa_apl_in_id_seq', 'aplicacao_externa_acl'); |
---|
475 | foreach ($dbObjects as $dbObject) |
---|
476 | { |
---|
477 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO admin_workflow"); |
---|
478 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO postgres"); |
---|
479 | $workflowDB->query("GRANT SELECT ON TABLE $dbObject TO public"); |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | /* reconnect to the previous database */ |
---|
484 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
485 | } |
---|
486 | |
---|
487 | #updating the current version |
---|
488 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.3.00.000'; |
---|
489 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
490 | } |
---|
491 | |
---|
492 | $test[] = '1.3.00.000'; |
---|
493 | function workflow_upgrade1_3_00_000() |
---|
494 | { |
---|
495 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_interinstance_relations', |
---|
496 | array( |
---|
497 | 'fd' => array( |
---|
498 | 'wf_parent_instance_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
499 | 'wf_parent_activity_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
500 | 'wf_child_instance_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
501 | 'wf_parent_lock' => array('type' => 'int', 'precision' => '2', 'nullable' => True) |
---|
502 | ), |
---|
503 | 'pk' => array('wf_parent_instance_id', 'wf_parent_activity_id', 'wf_child_instance_id'), |
---|
504 | 'fk' => array(), |
---|
505 | 'ix' => array(), |
---|
506 | 'uc' => array() |
---|
507 | ) |
---|
508 | ); |
---|
509 | |
---|
510 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
511 | { |
---|
512 | $workflowHostInfo = extractDatabaseParameters(); |
---|
513 | |
---|
514 | /* connect to the workflow database */ |
---|
515 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
516 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
517 | { |
---|
518 | /* change the type of the employee ID (funcionario_id field) */ |
---|
519 | $workflowDB->query('ALTER TABLE funcionario ALTER COLUMN centro_custo_id DROP NOT NULL'); |
---|
520 | $workflowDB->query('ALTER TABLE area DROP CONSTRAINT "$3"'); |
---|
521 | $workflowDB->query('ALTER TABLE area DROP CONSTRAINT "$4"'); |
---|
522 | $workflowDB->query('ALTER TABLE funcionario ADD COLUMN funcionario_id2 int4'); |
---|
523 | $workflowDB->query('UPDATE funcionario SET funcionario_id2 = int4(funcionario_id)'); |
---|
524 | $workflowDB->query('ALTER TABLE funcionario DROP COLUMN funcionario_id'); |
---|
525 | $workflowDB->query('ALTER TABLE funcionario RENAME COLUMN funcionario_id2 TO funcionario_id'); |
---|
526 | $workflowDB->query('ALTER TABLE funcionario ALTER funcionario_id SET NOT NULL'); |
---|
527 | $workflowDB->query('ALTER TABLE funcionario ADD CONSTRAINT funcionario_pkey PRIMARY KEY (funcionario_id)'); |
---|
528 | $workflowDB->query('ALTER TABLE area ADD titular_funcionario_id2 int4'); |
---|
529 | $workflowDB->query('ALTER TABLE area ADD substituto_funcionario_id2 int4'); |
---|
530 | $workflowDB->query('UPDATE area SET titular_funcionario_id2 = int4(titular_funcionario_id), substituto_funcionario_id2 = int4(substituto_funcionario_id)'); |
---|
531 | $workflowDB->query('ALTER TABLE area DROP COLUMN titular_funcionario_id'); |
---|
532 | $workflowDB->query('ALTER TABLE area DROP COLUMN substituto_funcionario_id'); |
---|
533 | $workflowDB->query('ALTER TABLE area RENAME COLUMN titular_funcionario_id2 TO titular_funcionario_id'); |
---|
534 | $workflowDB->query('ALTER TABLE area RENAME COLUMN substituto_funcionario_id2 TO substituto_funcionario_id'); |
---|
535 | $workflowDB->query('ALTER TABLE area ADD CONSTRAINT "$3" FOREIGN KEY (titular_funcionario_id) REFERENCES funcionario (funcionario_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION'); |
---|
536 | $workflowDB->query('ALTER TABLE AREA ADD CONSTRAINT "$4" FOREIGN KEY (substituto_funcionario_id) REFERENCES funcionario (funcionario_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION'); |
---|
537 | } |
---|
538 | |
---|
539 | /* reconnect to the previous database */ |
---|
540 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
541 | } |
---|
542 | |
---|
543 | #updating the current version |
---|
544 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.00.000'; |
---|
545 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
546 | } |
---|
547 | |
---|
548 | $test[] = '1.4.00.000'; |
---|
549 | function workflow_upgrade1_4_00_000() |
---|
550 | { |
---|
551 | #updating the current version |
---|
552 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.00.001'; |
---|
553 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
554 | } |
---|
555 | |
---|
556 | $test[] = '1.4.00.001'; |
---|
557 | function workflow_upgrade1_4_00_001() |
---|
558 | { |
---|
559 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_activities' ,'wf_menu_path', array('type' => 'varchar', 'precision' => 200, 'nullable' => True)); |
---|
560 | |
---|
561 | #updating the current version |
---|
562 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.01.000'; |
---|
563 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
564 | } |
---|
565 | |
---|
566 | $test[] = '1.4.01.000'; |
---|
567 | function workflow_upgrade1_4_01_000() |
---|
568 | { |
---|
569 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
570 | { |
---|
571 | $workflowHostInfo = extractDatabaseParameters(); |
---|
572 | |
---|
573 | /* connect to the new database */ |
---|
574 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
575 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
576 | { |
---|
577 | /* add a new column to the area table (orgchart) */ |
---|
578 | $workflowDB->query('ALTER TABLE area ADD COLUMN auxiliar_funcionario_id int4'); |
---|
579 | $workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$7" FOREIGN KEY (auxiliar_funcionario_id) REFERENCES funcionario(funcionario_id)'); |
---|
580 | } |
---|
581 | |
---|
582 | /* reconnect to the previous database */ |
---|
583 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
584 | } |
---|
585 | |
---|
586 | |
---|
587 | |
---|
588 | #updating the current version |
---|
589 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.02.000'; |
---|
590 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
591 | } |
---|
592 | |
---|
593 | $test[] = '1.4.02.000'; |
---|
594 | function workflow_upgrade1_4_02_000() |
---|
595 | { |
---|
596 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_admin_access', |
---|
597 | array( |
---|
598 | 'fd' => array( |
---|
599 | 'admin_access_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
600 | 'tipo' => array('type' => 'char', 'precision' => '3', 'nullable' => False), |
---|
601 | 'numvalue' => array('type' => 'int', 'precision' => '2', 'nullable' => False), |
---|
602 | 'nivel' => array('type' => 'int', 'precision' => '4', 'nullable' => True, 'default' => 0) |
---|
603 | ), |
---|
604 | 'pk' => array('admin_access_id', 'tipo', 'numvalue'), |
---|
605 | 'fk' => array(), |
---|
606 | 'ix' => array(), |
---|
607 | 'uc' => array() |
---|
608 | ) |
---|
609 | ); |
---|
610 | |
---|
611 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_external_application', |
---|
612 | array( |
---|
613 | 'fd' => array( |
---|
614 | 'external_application_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
615 | 'name' => array('type' => 'varchar', 'precision' => '50', 'nullable' => False), |
---|
616 | 'description' => array('type' => 'text', 'nullable' => True), |
---|
617 | 'image' => array('type' => 'varchar', 'precision' => '100', 'nullable' => True), |
---|
618 | 'address' => array('type' => 'varchar', 'precision' => '120', 'nullable' => False), |
---|
619 | 'authentication' => array('type' => 'bit', 'precision' => '1', 'nullable' => True), |
---|
620 | 'post' => array('type' => 'text', 'nullable' => True) |
---|
621 | ), |
---|
622 | 'pk' => array('external_application_id'), |
---|
623 | 'fk' => array(), |
---|
624 | 'ix' => array(), |
---|
625 | 'uc' => array() |
---|
626 | ) |
---|
627 | ); |
---|
628 | |
---|
629 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
630 | { |
---|
631 | $adminAccessData = array(); |
---|
632 | $externalApplicationData = array(); |
---|
633 | $externalApplicationSequence = 1; |
---|
634 | $externalApplicationACLData = array(); |
---|
635 | $workflowHostInfo = extractDatabaseParameters(); |
---|
636 | $GLOBALS['phpgw']->ADOdb->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
637 | |
---|
638 | /* connect to the Workflow database */ |
---|
639 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
640 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
641 | { |
---|
642 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT admin_access_id, tipo, numvalue, nivel FROM admin_access'); |
---|
643 | if ($result) |
---|
644 | while ($row = $result->fetchRow()) |
---|
645 | $adminAccessData[] = array($row['admin_access_id'], $row['tipo'], $row['numvalue'], $row['nivel']); |
---|
646 | |
---|
647 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT apl_in_id, apl_st_nome, apl_st_descricao, apl_st_imagem, apl_st_endereco, apl_bt_autentica, apl_st_post FROM aplicacao_externa'); |
---|
648 | if ($result) |
---|
649 | while ($row = $result->fetchRow()) |
---|
650 | $externalApplicationData[] = array($row['apl_in_id'], $row['apl_st_nome'], $row['apl_st_descricao'], $row['apl_st_imagem'], $row['apl_st_endereco'], $row['apl_bt_autentica'], $row['apl_st_post']); |
---|
651 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT last_value FROM aplicacao_externa_apl_in_id_seq'); |
---|
652 | if ($result) |
---|
653 | if ($row = $result->fetchRow()) |
---|
654 | $externalApplicationSequence = $row['last_value']; |
---|
655 | |
---|
656 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT apl_in_uid, apl_in_id FROM aplicacao_externa_acl'); |
---|
657 | if ($result) |
---|
658 | while ($row = $result->fetchRow()) |
---|
659 | $externalApplicationACLData[] = array($row['apl_in_uid'], $row['apl_in_id']); |
---|
660 | |
---|
661 | /* remove the unused tables */ |
---|
662 | $GLOBALS['phpgw']->ADOdb->query('DROP TABLE admin_access'); |
---|
663 | $GLOBALS['phpgw']->ADOdb->query('DROP SEQUENCE aplicacao_externa_apl_in_id_seq'); |
---|
664 | $GLOBALS['phpgw']->ADOdb->query('DROP CONSTRAINT fk01_aplicacao_externa_acl'); |
---|
665 | $GLOBALS['phpgw']->ADOdb->query('DROP TABLE aplicacao_externa_acl'); |
---|
666 | $GLOBALS['phpgw']->ADOdb->query('DROP TABLE aplicacao_externa'); |
---|
667 | } |
---|
668 | |
---|
669 | /* reconnect to the previous database */ |
---|
670 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
671 | foreach ($adminAccessData as $newRow) |
---|
672 | $result = $GLOBALS['phpgw']->ADOdb->query("INSERT INTO egw_wf_admin_access(admin_access_id, tipo, numvalue, nivel) VALUES (?, ?, ?, ?)", $newRow); |
---|
673 | |
---|
674 | foreach ($externalApplicationData as $newRow) |
---|
675 | $result = $GLOBALS['phpgw']->ADOdb->query("INSERT INTO egw_wf_external_application(external_application_id, name, description, image, address, authentication, post) VALUES(?, ?, ?, ?, ?, ?, ?)", $newRow); |
---|
676 | $GLOBALS['phpgw']->ADOdb->query("SELECT pg_catalog.setval('seq_egw_wf_external_application', ?, true)", array($externalApplicationSequence)); |
---|
677 | |
---|
678 | foreach ($externalApplicationACLData as $newRow) |
---|
679 | $result = $GLOBALS['phpgw']->ADOdb->query("INSERT INTO egw_wf_admin_access(admin_access_id, tipo, numvalue, nivel) VALUES (?, 'APX', ?, 0)", $newRow); |
---|
680 | } |
---|
681 | |
---|
682 | #updating the current version |
---|
683 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.03.000'; |
---|
684 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
685 | } |
---|
686 | |
---|
687 | $test[] = '1.4.03.000'; |
---|
688 | function workflow_upgrade1_4_03_000() |
---|
689 | { |
---|
690 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
691 | { |
---|
692 | $workflowHostInfo = extractDatabaseParameters(); |
---|
693 | |
---|
694 | /* connect to the new database */ |
---|
695 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
696 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
697 | { |
---|
698 | /* add a new column to the funcionario_status table (orgchart) */ |
---|
699 | $workflowDB->query('ALTER TABLE funcionario_status ADD COLUMN exibir character varying(1)'); |
---|
700 | $workflowDB->query('UPDATE funcionario_status SET exibir = ?', array('S')); |
---|
701 | $workflowDB->query('ALTER TABLE funcionario_status ALTER COLUMN exibir SET NOT NULL'); |
---|
702 | } |
---|
703 | |
---|
704 | /* reconnect to the previous database */ |
---|
705 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
706 | } |
---|
707 | |
---|
708 | #updating the current version |
---|
709 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.04.000'; |
---|
710 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
711 | } |
---|
712 | |
---|
713 | $test[] = '1.4.04.000'; |
---|
714 | function workflow_upgrade1_4_04_000() |
---|
715 | { |
---|
716 | /* remove unused table */ |
---|
717 | $GLOBALS['phpgw_setup']->oProc->DropTable('egw_wf_instance_supplements'); |
---|
718 | |
---|
719 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
720 | { |
---|
721 | $GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_instances ALTER COLUMN wf_next_user TYPE text'); |
---|
722 | $GLOBALS['phpgw']->ADOdb->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
723 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT i.wf_instance_id, ia.wf_activity_id, i.wf_next_user FROM egw_wf_instances i, egw_wf_instance_activities ia WHERE (i.wf_instance_id = ia.wf_instance_id) AND (i.wf_next_user IS NOT NULL)'); |
---|
724 | if (!empty($result)) |
---|
725 | { |
---|
726 | while ($res = $result->fetchRow()) |
---|
727 | { |
---|
728 | $newNextUser = base64_encode(serialize(array('*' . $res['wf_activity_id'] => $res['wf_next_user']))); |
---|
729 | $ok = $GLOBALS['phpgw']->ADOdb->query( |
---|
730 | 'UPDATE egw_wf_instances SET wf_next_user = ? WHERE (wf_instance_id = ?)', |
---|
731 | array($newNextUser, (int)$res['wf_instance_id']) |
---|
732 | ); |
---|
733 | } |
---|
734 | } |
---|
735 | |
---|
736 | $workflowHostInfo = extractDatabaseParameters(); |
---|
737 | |
---|
738 | /* connect to the new database */ |
---|
739 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
740 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
741 | { |
---|
742 | /* add a new column to the organizacao table (orgchart) */ |
---|
743 | $workflowDB->query('ALTER TABLE organizacao ADD COLUMN url_imagem character varying(200)'); |
---|
744 | } |
---|
745 | |
---|
746 | /* reconnect to the previous database */ |
---|
747 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
748 | } |
---|
749 | |
---|
750 | #updating the current version |
---|
751 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.05.000'; |
---|
752 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
753 | } |
---|
754 | |
---|
755 | $test[] = '1.4.05.000'; |
---|
756 | function workflow_upgrade1_4_05_000() |
---|
757 | { |
---|
758 | $GLOBALS['phpgw_setup']->oProc->AddColumn('egw_wf_external_application' ,'intranet_only', array('type' => 'bit', 'precision' => '1', 'nullable' => True)); |
---|
759 | |
---|
760 | #updating the current version |
---|
761 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.4.06.000'; |
---|
762 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
763 | } |
---|
764 | |
---|
765 | $test[] = '1.4.06.000'; |
---|
766 | function workflow_upgrade1_4_06_000() |
---|
767 | { |
---|
768 | #updating the current version |
---|
769 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.6.00.000'; |
---|
770 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
771 | } |
---|
772 | |
---|
773 | $test[] = '1.6.00.000'; |
---|
774 | function workflow_upgrade1_6_00_000() |
---|
775 | { |
---|
776 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
777 | { |
---|
778 | $workflowHostInfo = extractDatabaseParameters(); |
---|
779 | |
---|
780 | /* connect to the new database */ |
---|
781 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
782 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
783 | { |
---|
784 | /* create the new tables and add the referencial constraints */ |
---|
785 | $workflowDB->query('CREATE TABLE cargo (cargo_id serial NOT NULL, descricao character varying(150), organizacao_id int4)'); |
---|
786 | $workflowDB->query('ALTER TABLE ONLY cargo ADD CONSTRAINT cargo_pkey PRIMARY KEY (cargo_id)'); |
---|
787 | $workflowDB->query('ALTER TABLE ONLY cargo ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao (organizacao_id)'); |
---|
788 | $workflowDB->query('CREATE TABLE funcionario_categoria (funcionario_categoria_id serial NOT NULL, descricao character varying(150), organizacao_id int4)'); |
---|
789 | $workflowDB->query('ALTER TABLE ONLY funcionario_categoria ADD CONSTRAINT funcionario_categoria_pkey PRIMARY KEY (funcionario_categoria_id)'); |
---|
790 | $workflowDB->query('ALTER TABLE ONLY funcionario_categoria ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao (organizacao_id)'); |
---|
791 | |
---|
792 | /* add a new column to the organizacao table (orgchart) */ |
---|
793 | $workflowDB->query('ALTER TABLE funcionario ADD COLUMN cargo_id int4'); |
---|
794 | $workflowDB->query('ALTER TABLE funcionario ADD COLUMN nivel int2'); |
---|
795 | $workflowDB->query('ALTER TABLE funcionario ADD COLUMN funcionario_categoria_id int4'); |
---|
796 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$5" FOREIGN KEY (cargo_id) REFERENCES cargo (cargo_id)'); |
---|
797 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$6" FOREIGN KEY (funcionario_categoria_id) REFERENCES funcionario_categoria (funcionario_categoria_id)'); |
---|
798 | |
---|
799 | /* set the permissions to the database objects */ |
---|
800 | $dbObjects = array('cargo', 'cargo_cargo_id_seq', 'funcionario_categoria', 'funcionario_categoria_funcionario_categoria_id_seq'); |
---|
801 | foreach ($dbObjects as $dbObject) |
---|
802 | { |
---|
803 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO admin_workflow"); |
---|
804 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO postgres"); |
---|
805 | $workflowDB->query("GRANT SELECT ON TABLE $dbObject TO public"); |
---|
806 | } |
---|
807 | } |
---|
808 | |
---|
809 | /* reconnect to the previous database */ |
---|
810 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
811 | } |
---|
812 | |
---|
813 | #updating the current version |
---|
814 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.6.01.000'; |
---|
815 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
816 | } |
---|
817 | |
---|
818 | $test[] = '1.6.01.000'; |
---|
819 | function workflow_upgrade1_6_01_000() |
---|
820 | { |
---|
821 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
822 | { |
---|
823 | /* tries to load the 'files_dir' value (usually '/home/expressolivre') */ |
---|
824 | $GLOBALS['phpgw']->ADOdb->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
825 | $result = $GLOBALS['phpgw']->ADOdb->query('SELECT config_value FROM phpgw_config WHERE config_app = ? AND config_name = ?', array('phpgwapi', 'files_dir')); |
---|
826 | if (!(empty($result))) |
---|
827 | { |
---|
828 | $res = $result->fetchRow(); |
---|
829 | |
---|
830 | /* initialize some variables */ |
---|
831 | $resourcesBase = $res['config_value']; |
---|
832 | $oldResourcesDir = PHPGW_SERVER_ROOT . '/workflow/resources'; |
---|
833 | $success = true; |
---|
834 | |
---|
835 | /* if the resources dir exists, move it's subdirectories */ |
---|
836 | if (is_dir($oldResourcesDir)) |
---|
837 | { |
---|
838 | $success = false; |
---|
839 | $handle = opendir($oldResourcesDir); |
---|
840 | if ($handle) |
---|
841 | { |
---|
842 | $success = true; |
---|
843 | $OKToDeleteDir = true; |
---|
844 | |
---|
845 | /* move all subdirectories (except the '.' and '..' for oubvious reasons) to their new place */ |
---|
846 | while (false !== ($processDir = readdir($handle))) |
---|
847 | { |
---|
848 | if (($processDir == '.') || ($processDir == '..')) |
---|
849 | continue; |
---|
850 | |
---|
851 | /* check if we are dealing with a directory */ |
---|
852 | if (!is_dir($oldResourcesDir . '/' . $processDir)) |
---|
853 | { |
---|
854 | $OKToDeleteDir = false; |
---|
855 | continue; |
---|
856 | } |
---|
857 | |
---|
858 | /* special treatment for the workflow directory */ |
---|
859 | if ($processDir == 'workflow') |
---|
860 | { |
---|
861 | $success = $success && @rename($oldResourcesDir . '/' . $processDir, $resourcesBase . '/workflow/workflow'); |
---|
862 | continue; |
---|
863 | } |
---|
864 | |
---|
865 | /* if the destination directory exists, move it */ |
---|
866 | $newProcessDir = $resourcesBase . '/workflow/' . $processDir; |
---|
867 | if (is_dir($newProcessDir)) |
---|
868 | $success = $success && @rename($oldResourcesDir . '/' . $processDir, $newProcessDir . '/resources'); |
---|
869 | else |
---|
870 | $OKToDeleteDir = false; |
---|
871 | } |
---|
872 | |
---|
873 | /* close the handler */ |
---|
874 | closedir($handle); |
---|
875 | |
---|
876 | /* if the directory is empty, remove it */ |
---|
877 | if ($OKToDeleteDir && $success) |
---|
878 | if (!@rmdir($oldResourcesDir)) |
---|
879 | echo '<font color="red">Não foi possível remover o diretório: ' . $oldResourcesDir . '<br/> Tente removê-lo manualmente.</font>'; |
---|
880 | } |
---|
881 | } |
---|
882 | |
---|
883 | /* in case of an unsuccessful attemp to move a directory, warn the system admin */ |
---|
884 | if (!$success) |
---|
885 | echo '<font color="red">Pelo menos um diretório não pode ser movido. Você precisa mover, manualmente, os diretórios de resources dos processos. Exemplo: <br/><strong>' . $oldResourcesDir . '/PROCESSO_XX</strong> para <strong>' . $resourcesBase . '/workflow/PROCESSO_XX/resources</strong></font>'; |
---|
886 | } |
---|
887 | |
---|
888 | } |
---|
889 | |
---|
890 | /* updates the current version */ |
---|
891 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.6.02.000'; |
---|
892 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
893 | } |
---|
894 | |
---|
895 | $test[] = '1.6.02.000'; |
---|
896 | function workflow_upgrade1_6_02_000() |
---|
897 | { |
---|
898 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_user_cache', |
---|
899 | array( |
---|
900 | 'fd' => array( |
---|
901 | 'uidnumber' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
902 | 'uid' => array('type' => 'varchar', 'precision' => '30', 'nullable' => True), |
---|
903 | 'cn' => array('type' => 'varchar', 'precision' => '100', 'nullable' => True), |
---|
904 | 'givenname' => array('type' => 'varchar', 'precision' => '30', 'nullable' => True), |
---|
905 | 'sn' => array('type' => 'varchar', 'precision' => '70', 'nullable' => True), |
---|
906 | 'mail' => array('type' => 'varchar', 'precision' => '80', 'nullable' => True), |
---|
907 | 'accountstatus' => array('type' => 'varchar', 'precision' => '80', 'nullable' => True), |
---|
908 | 'dn' => array('type' => 'varchar', 'precision' => '150', 'nullable' => True), |
---|
909 | 'employeenumber' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
910 | 'cpf' => array('type' => 'varchar', 'precision' => '15', 'nullable' => True), |
---|
911 | 'telephonenumber' => array('type' => 'varchar', 'precision' => '50', 'nullable' => True), |
---|
912 | 'last_update' => array('type' => 'timestamp without time zone default now()', 'nullable' => True) |
---|
913 | ), |
---|
914 | 'pk' => array('uidnumber'), |
---|
915 | 'fk' => array(), |
---|
916 | 'ix' => array('mail', 'employeenumber', 'cpf'), |
---|
917 | 'uc' => array() |
---|
918 | ) |
---|
919 | ); |
---|
920 | |
---|
921 | #updating the current version |
---|
922 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.6.03.000'; |
---|
923 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
924 | } |
---|
925 | |
---|
926 | $test[] = '1.6.03.000'; |
---|
927 | function workflow_upgrade1_6_03_000() |
---|
928 | { |
---|
929 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
930 | { |
---|
931 | $workflowHostInfo = extractDatabaseParameters(); |
---|
932 | |
---|
933 | /* connect to the new database */ |
---|
934 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
935 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
936 | { |
---|
937 | $result = $workflowDB->query("SELECT 1 FROM pg_tables WHERE (schemaname = 'public') AND (tablename = 'funcionario_status')"); |
---|
938 | $row = array(); |
---|
939 | if (!empty($result)) |
---|
940 | $row = $result->fetchRow(); |
---|
941 | |
---|
942 | /* only some instalations are missing this table */ |
---|
943 | if ($row === false) |
---|
944 | { |
---|
945 | $workflowDB->query('CREATE TABLE funcionario_status (funcionario_status_id serial NOT NULL, descricao character varying(50) NOT NULL, exibir character varying(1) NOT NULL)'); |
---|
946 | $workflowDB->query('ALTER TABLE ONLY funcionario_status ADD CONSTRAINT funcionario_status_pkey PRIMARY KEY (funcionario_status_id)'); |
---|
947 | $workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$4" FOREIGN KEY (funcionario_status_id) REFERENCES funcionario_status(funcionario_status_id)'); |
---|
948 | |
---|
949 | $dbObjects = array('funcionario_status', 'funcionario_status_funcionario_status_id_seq'); |
---|
950 | foreach ($dbObjects as $dbObject) |
---|
951 | { |
---|
952 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO admin_workflow"); |
---|
953 | $workflowDB->query("GRANT ALL ON TABLE $dbObject TO postgres"); |
---|
954 | $workflowDB->query("GRANT SELECT ON TABLE $dbObject TO public"); |
---|
955 | } |
---|
956 | } |
---|
957 | } |
---|
958 | /* reconnect to the previous database */ |
---|
959 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
960 | } |
---|
961 | |
---|
962 | #updating the current version |
---|
963 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.6.03.001'; |
---|
964 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
965 | } |
---|
966 | |
---|
967 | $test[] = '1.6.03.001'; |
---|
968 | function workflow_upgrade1_6_03_001() |
---|
969 | { |
---|
970 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_jobs', |
---|
971 | array( |
---|
972 | 'fd' => array( |
---|
973 | 'job_id' => array('type' => 'auto', 'precision' => '4', 'nullable' => False), |
---|
974 | 'wf_process_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
975 | 'name' => array('type' => 'varchar', 'precision' => '100', 'nullable' => False), |
---|
976 | 'description' => array('type' => 'text', 'nullable' => True), |
---|
977 | 'time_start' => array('type' => 'timestamp without time zone', 'nullable' => False), |
---|
978 | 'interval_value' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
979 | 'interval_unity' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
980 | 'date_type' => array('type' => 'int', 'precision' => '4', 'nullable' => True), |
---|
981 | 'week_days' => array('type' => 'int', 'precision' => '4', 'nullable' => True, 'default' => 0), |
---|
982 | 'month_offset' => array('type' => 'int', 'precision' => '4', 'nullable' => True, 'default' => 0), |
---|
983 | 'active' => array('type' => 'bool', 'nullable' => True) |
---|
984 | ), |
---|
985 | 'pk' => array('job_id'), |
---|
986 | 'fk' => array(), |
---|
987 | 'ix' => array(), |
---|
988 | 'uc' => array() |
---|
989 | ) |
---|
990 | ); |
---|
991 | |
---|
992 | $GLOBALS['phpgw_setup']->oProc->createTable('egw_wf_job_logs', |
---|
993 | array( |
---|
994 | 'fd' => array( |
---|
995 | 'job_id' => array('type' => 'int', 'precision' => '4', 'nullable' => False), |
---|
996 | 'date_time' => array('type' => 'timestamp without time zone', 'nullable' => False), |
---|
997 | 'result' => array('type' => 'blob', 'nullable' => True), |
---|
998 | 'status' => array('type' => 'int', 'precision' => '4', 'nullable' => True) |
---|
999 | ), |
---|
1000 | 'pk' => array('job_id', 'date_time'), |
---|
1001 | 'fk' => array(), |
---|
1002 | 'ix' => array(), |
---|
1003 | 'uc' => array() |
---|
1004 | ) |
---|
1005 | ); |
---|
1006 | |
---|
1007 | #updating the current version |
---|
1008 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.7.00.000'; |
---|
1009 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1010 | } |
---|
1011 | |
---|
1012 | $test[] = '1.7.00.000'; |
---|
1013 | function workflow_upgrade1_7_00_000() |
---|
1014 | { |
---|
1015 | #updating the current version |
---|
1016 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.00.000'; |
---|
1017 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1018 | } |
---|
1019 | |
---|
1020 | $test[] = '1.8.00.000'; |
---|
1021 | function workflow_upgrade1_8_00_000() |
---|
1022 | { |
---|
1023 | #updating the current version |
---|
1024 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.01.000'; |
---|
1025 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1026 | } |
---|
1027 | |
---|
1028 | $test[] = '1.8.01.000'; |
---|
1029 | function workflow_upgrade1_8_01_000() |
---|
1030 | { |
---|
1031 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
1032 | { |
---|
1033 | $GLOBALS['phpgw']->ADOdb->query('CREATE INDEX egw_wf_instances_wf_name_idx ON egw_wf_instances(UPPER(wf_name))'); |
---|
1034 | $GLOBALS['phpgw']->ADOdb->query('CREATE INDEX egw_wf_instances_wf_p_id_idx ON egw_wf_instances(wf_p_id)'); |
---|
1035 | $GLOBALS['phpgw']->ADOdb->query('DELETE FROM phpgw_config where config_app = \'workflow\' and config_name in (\'database_user\', \'database_password\')'); |
---|
1036 | |
---|
1037 | $workflowHostInfo = extractDatabaseParameters(); |
---|
1038 | |
---|
1039 | /* connect to the new database */ |
---|
1040 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
1041 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
1042 | { |
---|
1043 | /* add a new column to the area organization (orgchart) */ |
---|
1044 | $workflowDB->query('ALTER TABLE organizacao ADD COLUMN ativa character varying(1)'); |
---|
1045 | $workflowDB->query('UPDATE organizacao SET ativa = \'S\''); |
---|
1046 | $workflowDB->query('ALTER TABLE organizacao ALTER ativa SET NOT NULL'); |
---|
1047 | } |
---|
1048 | |
---|
1049 | /* reconnect to the previous database */ |
---|
1050 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
1051 | } |
---|
1052 | |
---|
1053 | #updating the current version |
---|
1054 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.02.000'; |
---|
1055 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1056 | } |
---|
1057 | |
---|
1058 | $test[] = '1.8.02.000'; |
---|
1059 | function workflow_upgrade1_8_02_000() |
---|
1060 | { |
---|
1061 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
1062 | { |
---|
1063 | $workflowHostInfo = extractDatabaseParameters(); |
---|
1064 | |
---|
1065 | /* connect to the new database */ |
---|
1066 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
1067 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
1068 | { |
---|
1069 | /* gather some information */ |
---|
1070 | $workflowDB->setFetchMode(ADODB_FETCH_ASSOC); |
---|
1071 | $organizations = $workflowDB->GetAll('SELECT organizacao_id FROM organizacao'); |
---|
1072 | $employeeStatus = $workflowDB->GetAll('SELECT funcionario_status_id, descricao, exibir FROM funcionario_status'); |
---|
1073 | |
---|
1074 | /* add the new column */ |
---|
1075 | $workflowDB->query('ALTER TABLE funcionario_status ADD COLUMN organizacao_id INTEGER'); |
---|
1076 | if (count($organizations) > 0) |
---|
1077 | { |
---|
1078 | /* run update for the first organization */ |
---|
1079 | $workflowDB->query('UPDATE funcionario_status SET organizacao_id = ?', array($organizations[0]['organizacao_id'])); |
---|
1080 | |
---|
1081 | /* replicate the 'funcionario_status' table information for other organizations */ |
---|
1082 | for ($i = 1; $i < count($organizations); $i++) |
---|
1083 | { |
---|
1084 | $organizationID = $organizations[$i]['organizacao_id']; |
---|
1085 | foreach ($employeeStatus as $es) |
---|
1086 | { |
---|
1087 | $values = array( |
---|
1088 | $es['descricao'], |
---|
1089 | $es['exibir'], |
---|
1090 | $organizationID |
---|
1091 | ); |
---|
1092 | |
---|
1093 | /* insert the new status */ |
---|
1094 | $workflowDB->query('INSERT INTO funcionario_status (descricao, exibir, organizacao_id) VALUES (?, ?, ?)', $values); |
---|
1095 | |
---|
1096 | $values = array( |
---|
1097 | $organizationID, |
---|
1098 | $es['funcionario_status_id'] |
---|
1099 | ); |
---|
1100 | |
---|
1101 | /* update the existing employees */ |
---|
1102 | $workflowDB->query('UPDATE funcionario SET funcionario_status_id = (SELECT MAX(funcionario_status_id) FROM funcionario_status) WHERE (organizacao_id = ?) AND (funcionario_status_id = ?)', $values); |
---|
1103 | } |
---|
1104 | } |
---|
1105 | } |
---|
1106 | /* add the new constraint */ |
---|
1107 | $workflowDB->query('ALTER TABLE ONLY funcionario_status ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
1108 | } |
---|
1109 | |
---|
1110 | /* reconnect to the previous database */ |
---|
1111 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
1112 | } |
---|
1113 | |
---|
1114 | #updating the current version |
---|
1115 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.03.000'; |
---|
1116 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1117 | } |
---|
1118 | |
---|
1119 | $test[] = '1.8.03.000'; |
---|
1120 | function workflow_upgrade1_8_03_000() |
---|
1121 | { |
---|
1122 | /* setting new default attributes for workflow Logger */ |
---|
1123 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
1124 | { |
---|
1125 | $GLOBALS['phpgw']->ADOdb->query('INSERT INTO phpgw_config (config_app, config_name, config_value) VALUES (\'workflow\', \'log_type_file\', \'True\')'); |
---|
1126 | $GLOBALS['phpgw']->ADOdb->query('INSERT INTO phpgw_config (config_app, config_name, config_value) VALUES (\'workflow\', \'log_type_firebug\', \'True\')'); |
---|
1127 | $GLOBALS['phpgw']->ADOdb->query('INSERT INTO phpgw_config (config_app, config_name, config_value) VALUES (\'workflow\', \'log_level\', \'7\')'); |
---|
1128 | } |
---|
1129 | |
---|
1130 | #updating the current version |
---|
1131 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.04.000'; |
---|
1132 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1133 | } |
---|
1134 | |
---|
1135 | $test[] = '1.8.04.000'; |
---|
1136 | function workflow_upgrade1_8_04_000() |
---|
1137 | { |
---|
1138 | /* Create index for table egw_wf_workitems */ |
---|
1139 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
1140 | { |
---|
1141 | $GLOBALS['phpgw']->ADOdb->query('CREATE INDEX egw_wf_workitems_wf_instance_id_idx ON egw_wf_workitems(wf_instance_id)'); |
---|
1142 | } |
---|
1143 | |
---|
1144 | #updating the current version |
---|
1145 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.05.000'; |
---|
1146 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1147 | } |
---|
1148 | |
---|
1149 | $test[] = '1.8.05.000'; |
---|
1150 | function workflow_upgrade1_8_05_000() |
---|
1151 | { |
---|
1152 | /* Alter tables of orgchart */ |
---|
1153 | if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly) |
---|
1154 | { |
---|
1155 | $workflowHostInfo = extractDatabaseParameters(); |
---|
1156 | |
---|
1157 | /* connect to workflow database */ |
---|
1158 | $workflowDB = $GLOBALS['phpgw']->ADOdb; |
---|
1159 | if ($workflowDB->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow')) |
---|
1160 | { |
---|
1161 | /* add the new columns */ |
---|
1162 | $workflowDB->query('ALTER TABLE public.funcionario ADD COLUMN titulo CHARACTER VARYING(30)'); |
---|
1163 | $workflowDB->query('ALTER TABLE public.organizacao ADD COLUMN sitio CHARACTER VARYING(100)'); |
---|
1164 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN empresa CHARACTER VARYING(100)'); |
---|
1165 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN endereco CHARACTER VARYING(100)'); |
---|
1166 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN complemento CHARACTER VARYING(50)'); |
---|
1167 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cep CHARACTER VARYING(9)'); |
---|
1168 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN bairro CHARACTER VARYING(30)'); |
---|
1169 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cidade CHARACTER VARYING(50)'); |
---|
1170 | $workflowDB->query('ALTER TABLE public.localidade ADD COLUMN uf CHARACTER(2)'); |
---|
1171 | |
---|
1172 | /* create table telefone */ |
---|
1173 | $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)'); |
---|
1174 | $workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT telefone_pkey PRIMARY KEY (telefone_id)'); |
---|
1175 | $workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)'); |
---|
1176 | $workflowDB->query("GRANT ALL ON TABLE public.telefone TO admin_workflow"); |
---|
1177 | $workflowDB->query("GRANT ALL ON TABLE public.telefone TO postgres"); |
---|
1178 | $workflowDB->query("GRANT SELECT ON TABLE public.telefone TO public"); |
---|
1179 | $workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO admin_workflow"); |
---|
1180 | $workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO postgres"); |
---|
1181 | $workflowDB->query("GRANT SELECT ON TABLE public.telefone_telefone_id_seq TO public"); |
---|
1182 | } |
---|
1183 | |
---|
1184 | /* reconnect to the previous database */ |
---|
1185 | $GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']); |
---|
1186 | } |
---|
1187 | #updating the current version |
---|
1188 | $GLOBALS['setup_info']['workflow']['currentver'] = '1.8.06.000'; |
---|
1189 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1190 | } |
---|
1191 | |
---|
1192 | $test[] = '1.8.06.000'; |
---|
1193 | function workflow_upgrade1_8_06_000() |
---|
1194 | { |
---|
1195 | #updating the current version |
---|
1196 | $GLOBALS['setup_info']['workflow']['currentver'] = '2.0.000'; |
---|
1197 | return $GLOBALS['setup_info']['workflow']['currentver']; |
---|
1198 | } |
---|
1199 | ?> |
---|