Ignore:
Timestamp:
07/12/10 10:39:22 (14 years ago)
Author:
niltonneto
Message:

Ticket #1135 - Ajuste da atualização do header.inc.php, setup dos módulos e API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/workflow/setup/tables_update.inc.php

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