[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/setup/ -> tables_update.inc.php (source)

   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      // $Id: tables_update.inc.php 22669 2006-10-18 05:41:42Z ralfbecker $
  13  
  14      /* Include older eGroupWare update support */
  15      include ('tables_update_0_9_9.inc.php');
  16      include ('tables_update_0_9_10.inc.php');
  17      include ('tables_update_0_9_12.inc.php');
  18      include ('tables_update_0_9_14.inc.php');
  19  
  20      // updates from the stable 1.0.0 branch
  21      $test[] = '1.0.0.001';
  22  	function phpgwapi_upgrade1_0_0_001()
  23      {
  24          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.0.004';
  25          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
  26      }
  27  
  28      $test[] = '1.0.0.002';
  29  	function phpgwapi_upgrade1_0_0_002()
  30      {
  31          // identical to 1.0.0.001, only created to get a new version of the packages
  32          return phpgwapi_upgrade1_0_0_001();
  33      }
  34  
  35      $test[] = '1.0.0.003';
  36  	function phpgwapi_upgrade1_0_0_003()
  37      {
  38          // identical to 1.0.0.001, only created to get a new version of the final 1.0 packages
  39          return phpgwapi_upgrade1_0_0_001();
  40      }
  41      
  42      $test[] = '1.0.0.004';
  43  	function phpgwapi_upgrade1_0_0_004()
  44      {
  45          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','id','async_id');
  46          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','next','async_next');
  47          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','times','async_times');
  48          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','method','async_method');
  49          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','data','async_data');
  50          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_async','account_id','async_account_id');
  51  
  52          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.001';
  53          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
  54      }
  55  
  56      $test[] = '1.0.0.005';
  57  	function phpgwapi_upgrade1_0_0_005()
  58      {
  59          // identical to 1.0.0.001, only created to get a new version of the bugfix release
  60          return phpgwapi_upgrade1_0_0_004();
  61      }
  62      
  63      $test[] = '1.0.0.006';
  64  	function phpgwapi_upgrade1_0_0_006()
  65      {
  66          // identical to 1.0.0.001, only created to get a new version of the bugfix release
  67          return phpgwapi_upgrade1_0_0_004();
  68      }
  69      
  70      $test[] = '1.0.0.007';
  71  	function phpgwapi_upgrade1_0_0_007()
  72      {
  73          // identical to 1.0.0.001, only created to get a new version of the bugfix release
  74          return phpgwapi_upgrade1_0_0_004();
  75      }
  76      
  77      $test[] = '1.0.0.008';
  78  	function phpgwapi_upgrade1_0_0_008()
  79      {
  80          // identical to 1.0.0.001, only created to get a new version of the bugfix release
  81          return phpgwapi_upgrade1_0_0_004();
  82      }
  83      
  84      $test[] = '1.0.0.009';
  85  	function phpgwapi_upgrade1_0_0_009()
  86      {
  87          // identical to 1.0.0.001, only created to get a new version of the bugfix release
  88          return phpgwapi_upgrade1_0_0_004();
  89      }
  90      
  91      $test[] = '1.0.1.001';
  92  	function phpgwapi_upgrade1_0_1_001()
  93      {
  94          // removing the ACL entries of deleted accounts
  95          $GLOBALS['egw_setup']->setup_account_object();
  96          if ($GLOBALS['phpgw']->accounts->table)
  97          {
  98              $GLOBALS['phpgw']->accounts->table = $GLOBALS['egw_setup']->accounts_table;
  99          }
 100          if (($all_accounts = $GLOBALS['phpgw']->accounts->search(array('type'=>'both'))))
 101          {
 102              foreach($all_accounts as $key => $value)
 103              {
 104                  // the latest version of the egw api(>1.2.001) is returning negative groupids
 105                  // but in the currently updated version of the acl table, the groupids are yet positive
 106                  $allaccounts[] = abs($key);
 107              }
 108              $GLOBALS['egw_setup']->oProc->query("DELETE FROM phpgw_acl WHERE acl_account NOT IN (".implode(',',$allaccounts).")",__LINE__,__FILE__);
 109              $GLOBALS['egw_setup']->oProc->query("DELETE FROM phpgw_acl WHERE acl_appname='phpgw_group' AND acl_location NOT IN ('".implode("','",$allaccounts)."')",__LINE__,__FILE__);
 110          }
 111          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.002';
 112          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 113      }
 114  
 115  
 116      $test[] = '1.0.1.002';
 117  	function phpgwapi_upgrade1_0_1_002()
 118      {
 119          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','file_id','vfs_file_id');
 120          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','owner_id','vfs_owner_id');
 121          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','createdby_id','vfs_createdby_id');
 122          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','modifiedby_id','vfs_modifiedby_id');
 123          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','created','vfs_created');
 124          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','modified','vfs_modified');
 125          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','size','vfs_size');
 126          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','mime_type','vfs_mime_type');
 127          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','deleteable','vfs_deleteable');
 128          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','comment','vfs_comment');
 129          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','app','vfs_app');
 130          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','directory','vfs_directory');
 131          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','name','vfs_name');
 132          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','link_directory','vfs_link_directory');
 133          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','link_name','vfs_link_name');
 134          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','version','vfs_version');
 135          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_vfs','content','vfs_content');
 136          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_vfs','egw_vfs');
 137  
 138          $GLOBALS['egw_setup']->oProc->RefreshTable('egw_vfs',array(
 139              'fd' => array(
 140                  'vfs_file_id' => array('type' => 'auto','nullable' => False),
 141                  'vfs_owner_id' => array('type' => 'int','precision' => '4','nullable' => False),
 142                  'vfs_createdby_id' => array('type' => 'int','precision' => '4'),
 143                  'vfs_modifiedby_id' => array('type' => 'int','precision' => '4'),
 144                  'vfs_created' => array('type' => 'date','nullable' => False,'default' => '1970-01-01'),
 145                  'vfs_modified' => array('type' => 'date'),
 146                  'vfs_size' => array('type' => 'int','precision' => '4'),
 147                  'vfs_mime_type' => array('type' => 'varchar','precision' => '64'),
 148                  'vfs_deleteable' => array('type' => 'char','precision' => '1','default' => 'Y'),
 149                  'vfs_comment' => array('type' => 'varchar','precision' => '255'),
 150                  'vfs_app' => array('type' => 'varchar','precision' => '25'),
 151                  'vfs_directory' => array('type' => 'varchar','precision' => '255'),
 152                  'vfs_name' => array('type' => 'varchar','precision' => '128','nullable' => False),
 153                  'vfs_link_directory' => array('type' => 'varchar','precision' => '255'),
 154                  'vfs_link_name' => array('type' => 'varchar','precision' => '128'),
 155                  'vfs_version' => array('type' => 'varchar','precision' => '30','nullable' => False,'default' => '0.0.0.0'),
 156                  'vfs_content' => array('type' => 'text')
 157              ),
 158              'pk' => array('vfs_file_id'),
 159              'fk' => array(),
 160              'ix' => array(array('vfs_directory','vfs_name','vfs_mime_type')),
 161              'uc' => array()
 162          ));
 163  
 164          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.003';
 165          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 166      }
 167  
 168      $test[] = '1.0.1.003';
 169  	function phpgwapi_upgrade1_0_1_003()
 170      {
 171          $GLOBALS['egw_setup']->oProc->CreateTable(
 172              'egw_api_content_history', array(
 173                  'fd' => array(
 174                      'sync_appname'    =>  array('type' => 'varchar','precision' => '60','nullable' => False),
 175                      'sync_contentid' => array('type' => 'varchar','precision' => '60','nullable' => False),
 176                      'sync_added'    =>  array('type' => 'timestamp', 'nullable' => False),
 177                      'sync_modified'    =>  array('type' => 'timestamp', 'nullable' => False),
 178                      'sync_deleted'    =>  array('type' => 'timestamp', 'nullable' => False),
 179                      'sync_id'    =>  array('type' => 'auto','nullable' => False),
 180                      'sync_guid'    =>  array('type' => 'varchar','precision' => '120','nullable' => False),
 181                      'sync_changedby' => array('type' => 'int','precision' => '4','nullable' => False),
 182                  ),
 183                  'pk' => array('sync_id'),
 184                  'fk' => array(),
 185                  'ix' => array(array('sync_appname','sync_contentid'),'sync_added','sync_modified','sync_deleted','sync_guid','sync_changedby'),
 186                  'uc' => array()
 187              )
 188          );
 189  
 190          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.004';
 191          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 192      }
 193  
 194      $test[] = '1.0.1.004';
 195  	function phpgwapi_upgrade1_0_1_004()
 196      {
 197          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_api_content_history','sync_added',array(
 198              'type' => 'timestamp'
 199          ));
 200          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_api_content_history','sync_modified',array(
 201              'type' => 'timestamp'
 202          ));
 203          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_api_content_history','sync_deleted',array(
 204              'type' => 'timestamp'
 205          ));
 206  
 207          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.005';
 208          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 209      }
 210  
 211      $test[] = '1.0.1.005';
 212  	function phpgwapi_upgrade1_0_1_005()
 213      {
 214          /*********************************************************************\
 215           *                           VFS version 2                             *
 216          \*********************************************************************/
 217  
 218          $GLOBALS['egw_setup']->oProc->CreateTable(
 219              'phpgw_vfs2_mimetypes', array(
 220                  'fd' => array(
 221                      'mime_id' => array('type' => 'auto','nullable' => False),
 222                      'extension' => array('type' => 'varchar', 'precision' => 10, 'nullable' => false),
 223                      'mime' => array('type' => 'varchar', 'precision' => 50, 'nullable' => false),
 224                      'mime_magic' => array('type' => 'varchar', 'precision' => 255, 'nullable' => true),
 225                      'friendly' => array('type' => 'varchar', 'precision' => 50, 'nullable' => false),
 226                      'image' => array('type' => 'blob'),
 227                      'proper_id' => array('type' => 'varchar', 'precision' => 4)
 228                  ),
 229                  'pk' => array('mime_id'),
 230                  'fk' => array(),
 231                  'ix' => array(),
 232                  'uc' => array()
 233              )
 234          );
 235  
 236          $GLOBALS['egw_setup']->oProc->CreateTable(
 237              'phpgw_vfs2_files' , array(
 238                  'fd' => array(
 239                      'file_id' => array('type' => 'auto','nullable' => False),
 240                      'mime_id' => array('type' => 'int','precision' => 4),
 241                      'owner_id' => array('type' => 'int','precision' => 4,'nullable' => False),
 242                      'createdby_id' => array('type' => 'int','precision' => 4),
 243                      'created' => array('type' => 'timestamp','default' => '1970-01-01 00:00:00', 'nullable' => False),
 244                      'size' => array('type' => 'int','precision' => 8),
 245                      'deleteable' => array('type' => 'char','precision' => 1,'default' => 'Y'),
 246                      'comment' => array('type' => 'varchar','precision' => 255),
 247                      'app' => array('type' => 'varchar','precision' => 25),
 248                      'directory' => array('type' => 'varchar','precision' => 255),
 249                      'name' => array('type' => 'varchar','precision' => 128,'nullable' => False),
 250                      'link_directory' => array('type' => 'varchar','precision' => 255),
 251                      'link_name' => array('type' => 'varchar','precision' => 128),
 252                      'version' => array('type' => 'varchar','precision' => 30,'nullable' => False,'default' => '0.0.0.0'),
 253                      'content' => array('type' => 'longtext'),
 254                      'is_backup' => array('type' => 'varchar', 'precision' => 1, 'nullable' => False, 'default' => 'N'),
 255                      'shared' => array('type' => 'varchar', 'precision' => 1, 'nullable' => False,'default' => 'N'),
 256                      'proper_id' => array('type' => 'varchar', 'precision' => 45)
 257                  ),
 258                  'pk' => array('file_id'),
 259                  'fk' => array('mime_id' => array ('phpgw_vfs2_mimetypes' => 'mime_id')),
 260                  'ix' => array(array('directory','name')),
 261                  'uc' => array()
 262              )
 263          );
 264  
 265          $GLOBALS['egw_setup']->oProc->CreateTable(
 266              'phpgw_vfs2_customfields' , array(
 267                  'fd' => array(
 268                      'customfield_id' => array('type' => 'auto','nullable' => False),
 269                      'customfield_name' => array('type' => 'varchar','precision' => 60,'nullable' => False),
 270                      'customfield_description' => array('type' => 'varchar','precision' => 255,'nullable'=> True),
 271                      'customfield_type' => array('type' => 'varchar','precision' => 20, 'nullable' => false),
 272                      'customfield_precision' => array('type' => 'int', 'precision' => 4, 'nullable' => true),
 273                      'customfield_active' => array('type' => 'varchar','precision' => 1,'nullable' => False,'default' => 'N')
 274                  ),
 275                  'pk' => array('customfield_id'),
 276                  'fk' => array(),
 277                  'ix' => array(),
 278                  'uc' => array()
 279              )
 280          );
 281  
 282          $GLOBALS['egw_setup']->oProc->CreateTable(
 283              'phpgw_vfs2_quota' , array(
 284                  'fd' => array(
 285                      'account_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 286                      'quota' => array('type' => 'int','precision' => 4,'nullable' => false)
 287                  ),
 288                  'pk' => array('account_id'),
 289                  'fk' => array('account_id' => array('phpgw_accounts' => 'account_id')),
 290                  'ix' => array(),
 291                  'uc' => array()
 292              )
 293          );
 294  
 295          $GLOBALS['egw_setup']->oProc->CreateTable(
 296              'phpgw_vfs2_shares' , array(
 297                  'fd' => array(
 298                      'account_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 299                      'file_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 300                      'acl_rights' => array('type' => 'int','precision' => 4,'nullable' => false)
 301                  ),
 302                  'pk' => array('account_id','file_id'),
 303                  'fk' => array('account_id' => array('phpgw_accounts' => 'account_id'), 'file_id' => array('phpgw_vfs2_files' => 'file_id')),
 304                  'ix' => array(),
 305                  'uc' => array()
 306              )
 307          );
 308  
 309          $GLOBALS['egw_setup']->oProc->CreateTable(
 310              'phpgw_vfs2_versioning' , array(
 311                  'fd' => array(
 312                      'version_id' => array('type' => 'auto', 'nullable' => false),
 313                      'file_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 314                      'operation' => array('type' => 'int','precision' => 4, 'nullable' => False),
 315                      'modifiedby_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 316                      'modified' => array('type' => 'timestamp', 'nullable' => False ),
 317                      'version' => array('type' => 'varchar', 'precision' => 30, 'nullable' => False ),
 318                      'comment' => array('type' => 'varchar', 'precision' => 255, 'nullable' => True),
 319                      'backup_file_id' => array('type' => 'int','precision' => 4, 'nullable' => True),
 320                      'backup_content' => array('type' => 'longtext', 'nullable' => True),
 321                      'src' => array('type' => 'varchar', 'precision' => 255, 'nullable' => True),
 322                      'dest' => array('type' => 'varchar', 'precision' => 255, 'nullable' => True)
 323                  ),
 324                  'pk' => array('version_id'),
 325                  'fk' => array('file_id' => array('phpgw_vfs2_files' => 'file_id')),
 326                  'ix' => array(),
 327                  'uc' => array()
 328              )
 329          );
 330  
 331          $GLOBALS['egw_setup']->oProc->CreateTable(
 332              'phpgw_vfs2_customfields_data' , array(
 333                  'fd' => array(
 334                      'file_id' => array('type' => 'int','precision' => 4,'nullable' => false),
 335                      'customfield_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 336                      'data' => array('type' => 'longtext', 'nullable' => True)
 337                  ),
 338                  'pk' => array('file_id','customfield_id'),
 339                  'fk' => array('file_id' => array('phpgw_vfs2_files' => 'file_id'),'customfield_id' => array('phpgw_vfs2_customfields' => 'customfield_id')),
 340                  'ix' => array(),
 341                  'uc' => array()
 342              )
 343          );
 344  
 345          $GLOBALS['egw_setup']->oProc->CreateTable(
 346              'phpgw_vfs2_prefixes' , array(
 347                  'fd' => array(
 348                      'prefix_id' => array('type' => 'auto','nullable' => false),
 349                      'prefix' => array('type' => 'varchar', 'precision' => 8, 'nullable' => false),
 350                      'owner_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 351                      'prefix_description' => array('type' => 'varchar', 'precision' => 30, 'nullable' => True),
 352                      'prefix_type' => array('type' => 'varchar', 'precision' => 1, 'nullable' => false, 'default' => 'p')
 353                  ),
 354                  'pk' => array('prefix_id'),
 355                  'fk' => array(),
 356                  'ix' => array(),
 357                  'uc' => array()
 358              )
 359          );
 360  
 361          /*************************************************************************\
 362           *                    Default Records for VFS v2                         *
 363          \*************************************************************************/
 364          if ($GLOBALS['DEBUG'])
 365          {
 366              echo "<br>\n<b>initiating to create the default records for VFS SQL2...";
 367          }
 368          
 369          include  PHPGW_INCLUDE_ROOT.'/phpgwapi/setup/default_records_mime.inc.php';
 370  
 371          $GLOBALS['egw_setup']->oProc->query("INSERT INTO phpgw_vfs2_files (mime_id,owner_id,createdby_id,size,directory,name)
 372                         SELECT mime_id,0,0,4096,'/','' FROM phpgw_vfs2_mimetypes WHERE mime='Directory'");
 373  
 374          if ($GLOBALS['DEBUG'])
 375          {
 376              echo " DONE!</b>";
 377          }
 378          /*************************************************************************/
 379  
 380          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.006';
 381          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 382      }
 383  
 384  
 385      $test[] = '1.0.1.006';
 386  	function phpgwapi_upgrade1_0_1_006()
 387      {
 388          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_async','egw_async');
 389  
 390          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.007';
 391          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 392      }
 393  
 394      $test[] = '1.0.1.007';
 395  	function phpgwapi_upgrade1_0_1_007()
 396      {
 397          //Creating cached values for modified and modifiedby_id
 398          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_vfs2_files', 'modifiedby_id', array('type' => 'int','precision' => 4));
 399          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_vfs2_files', 'modified', array('type' => 'timestamp', 'nullable' => true));
 400  
 401          //Updating existing values
 402          $sql = "SELECT max(modified) as mod, file_id, min(modifiedby_id) from phpgw_vfs2_versioning group by file_id";
 403  
 404          $GLOBALS['egw_setup']->oProc->m_odb->query($sql,__LINE__,__FILE__);
 405  
 406          $files_to_change = array();
 407          while ($GLOBALS['egw_setup']->oProc->m_odb->next_record())
 408          {
 409              $files_to_change[] = $GLOBALS['egw_setup']->oProc->m_odb->Record;
 410          }
 411  
 412          foreach ($files_to_change as $key => $val)
 413          {
 414              $GLOBALS['egw_setup']->oProc->m_odb->update('phpgw_vfs2_files',
 415                  array(
 416                      'modified' => $val['mod'],
 417                      'modifiedby_id' => $val['modifiedby_id']
 418                      ),
 419                  array('file_id' => $val['file_id']),__LINE__,__FILE__
 420                  );
 421          }
 422  
 423          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.008';
 424          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 425      }
 426  
 427      $test[] = '1.0.1.008';
 428  	function phpgwapi_upgrade1_0_1_008()
 429      {
 430          $GLOBALS['egw_setup']->oProc->CreateTable(
 431              'egw_contentmap', array(
 432                  'fd' => array(
 433                      'map_id'    => array('type' => 'varchar', 'precision' => '255', 'nullable' => False),
 434                      'map_guid'    => array('type' => 'varchar', 'precision' => '200', 'nullable' => False),
 435                      'map_locuid'    => array('type' => 'varchar', 'precision' => '200', 'nullable' => False),
 436                      'map_timestamp'    => array('type' => 'timestamp', 'nullable' => False),
 437                      'map_expired'    => array('type' => 'bool', 'nullable' => False),
 438                  ),
 439                  'pk' => array(array('map_id','map_guid','map_locuid')),
 440                  'fk' => array(),
 441                  'ix' => array(array('map_id','map_locuid'),'map_expired'),
 442                  'uc' => array()
 443              )
 444          );
 445  
 446          $GLOBALS['egw_setup']->oProc->CreateTable(
 447              'egw_syncmldevinfo', array(
 448                  'fd' => array(
 449                      'dev_id'        => array('type' => 'varchar', 'precision' => '255', 'nullable' => False),
 450                      'dev_dtdversion'    => array('type' => 'varchar', 'precision' => '10', 'nullable' => False),
 451                      'dev_numberofchanges'    => array('type' => 'bool', 'nullable' => False),
 452                      'dev_largeobjs'        => array('type' => 'bool', 'nullable' => False),
 453                      'dev_swversion'        => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 454                      'dev_oem'        => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 455                      'dev_model'        => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 456                      'dev_manufacturer'    => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 457                      'dev_devicetype'    => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 458                      'dev_deviceid'        => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 459                      'dev_datastore'        => array('type' => 'text', 'nullable' => False),
 460                  ),
 461                  'pk' => array('dev_id'),
 462                  'fk' => array(),
 463                  'ix' => array(),
 464                  'uc' => array()
 465              )
 466          );
 467  
 468          $GLOBALS['egw_setup']->oProc->CreateTable(
 469              'egw_syncmlsummary', array(
 470                  'fd' => array(
 471                      'dev_id'        => array('type' => 'varchar', 'precision' => '255', 'nullable' => False),
 472                      'sync_path'        => array('type' => 'varchar', 'precision' => '100', 'nullable' => False),
 473                      'sync_serverts'        => array('type' => 'varchar', 'precision' => '20', 'nullable' => False),
 474                      'sync_clientts'        => array('type' => 'varchar', 'precision' => '20', 'nullable' => False),
 475                  ),
 476                  'pk' => array(array('dev_id','sync_path')),
 477                  'fk' => array(),    
 478                  'ix' => array(),
 479                  'uc' => array()
 480              )
 481          );
 482  
 483          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.009';
 484          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 485      }
 486  
 487      $test[] = '1.0.1.009';
 488  	function phpgwapi_upgrade1_0_1_009()
 489      {
 490          if (@file_exists(EGW_SERVER_ROOT . '/home/setup/setup.inc.php'))
 491          {
 492              // automatic install of the new home app
 493              include (EGW_SERVER_ROOT . '/home/setup/setup.inc.php');
 494              $home_version = $setup_info['home']['version'];
 495              
 496              $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->applications_table,array(
 497                  'app_enabled' => $setup_info['home']['enable'],
 498                  'app_order'   => $setup_info['home']['app_order'],
 499                  'app_version' => $setup_info['home']['version'],
 500                  'app_tables'  => '',
 501                  'app_version' => $home_version,
 502              ),array(
 503                  'app_name' => 'home',
 504              ),__LINE__,__FILE__,False,False,$GLOBALS['egw_setup']->oProc->GetTableDefinition($GLOBALS['egw_setup']->applications_table));
 505              
 506              // give all users and groups with preferences rights, rights for the home app.
 507              $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->acl_table,'acl_account',array(
 508                  'acl_appname'  => 'preferences',
 509                  'acl_location' => 'run',
 510                  'acl_rights'   => 1,
 511              ),__LINE__,__FILE__);
 512              $accounts_with_preference_rights = array();
 513              while (($row = $GLOBALS['egw_setup']->db->row(true)))
 514              {
 515                  $accounts_with_preference_rights[] = $row['acl_account'];
 516              }
 517              foreach($accounts_with_preference_rights as $account)
 518              {
 519                  $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->acl_table,array(
 520                      'acl_rights'   => 1,
 521                  ),array(
 522                      'acl_appname'  => 'home',
 523                      'acl_location' => 'run',
 524                      'acl_account'  => $account,
 525                  ),__LINE__,__FILE__,False,False,$GLOBALS['egw_setup']->oProc->GetTableDefinition($GLOBALS['egw_setup']->acl_table));
 526              }    
 527          }
 528          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.010';
 529          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 530      }
 531  
 532  
 533      $test[] = '1.0.1.010';
 534  	function phpgwapi_upgrade1_0_1_010()
 535      {
 536          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_sessions','session_ip',array(
 537              'type' => 'varchar',
 538              'precision' => '40'
 539          ));
 540  
 541          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_access_log','ip',array(
 542              'type' => 'varchar',
 543              'precision' => '40',
 544              'nullable' => False
 545          ));
 546  
 547          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_access_log','loginid',array(
 548              'type' => 'varchar',
 549              'precision' => '128'
 550          ));
 551  
 552          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.011';
 553          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 554      }
 555  
 556      $test[] = '1.0.1.011';
 557  	function phpgwapi_upgrade1_0_1_011()
 558      {
 559          // moving the egw_links table into the API
 560          if ($GLOBALS['egw_setup']->oProc->GetTableDefinition('phpgw_links'))
 561          {
 562              // table exists with old name ==> rename it to new one
 563              $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_links','egw_links');
 564          }
 565          elseif (!$GLOBALS['egw_setup']->oProc->GetTableDefinition('egw_links'))
 566          {
 567              // table does not exist at all (infolog not installed) ==> create it
 568              $GLOBALS['egw_setup']->oProc->CreateTable('egw_links',array(
 569                  'fd' => array(
 570                      'link_id' => array('type' => 'auto','nullable' => False),
 571                      'link_app1' => array('type' => 'varchar','precision' => '25','nullable' => False),
 572                      'link_id1' => array('type' => 'varchar','precision' => '50','nullable' => False),
 573                      'link_app2' => array('type' => 'varchar','precision' => '25','nullable' => False),
 574                      'link_id2' => array('type' => 'varchar','precision' => '50','nullable' => False),
 575                      'link_remark' => array('type' => 'varchar','precision' => '50'),
 576                      'link_lastmod' => array('type' => 'int','precision' => '4','nullable' => False),
 577                      'link_owner' => array('type' => 'int','precision' => '4','nullable' => False)
 578                  ),
 579                  'pk' => array('link_id'),
 580                  'fk' => array(),
 581                  'ix' => array(array('link_app1','link_id1','link_lastmod'),array('link_app2','link_id2','link_lastmod')),
 582                  'uc' => array()
 583              ));
 584          }
 585          // move the link-configuration to the api
 586          $GLOBALS['egw_setup']->oProc->query('UPDATE '.$GLOBALS['egw_setup']->config_table." SET config_app='phpgwapi' WHERE config_app='infolog' AND config_name IN ('link_pathes','send_file_ips')",__LINE__,__FILE__);
 587  
 588          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.012';
 589          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 590      }
 591  
 592      $test[] = '1.0.1.012';
 593  	function phpgwapi_upgrade1_0_1_012()
 594      {
 595          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_accounts','egw_accounts');
 596          $GLOBALS['egw_setup']->set_table_names(True);
 597          if ($GLOBALS['phpgw']->accounts->table)
 598          {
 599              $GLOBALS['phpgw']->accounts->table = $GLOBALS['egw_setup']->accounts_table;
 600          }
 601          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_acl','egw_acl');
 602          $GLOBALS['egw_setup']->set_table_names(True);
 603          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_log','egw_log');
 604          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_log_msg','egw_log_msg');
 605  
 606          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.013';
 607          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 608      }
 609  
 610      $test[] = '1.0.1.013';
 611  	function phpgwapi_upgrade1_0_1_013()
 612      {
 613          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_config','egw_config');
 614          $GLOBALS['egw_setup']->set_table_names(True);
 615          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_applications','egw_applications');
 616          $GLOBALS['egw_setup']->set_table_names(True);
 617  
 618          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.014';
 619          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 620      }
 621  
 622      $test[] = '1.0.1.014';
 623  	function phpgwapi_upgrade1_0_1_014()
 624      {
 625          // index was to big for mysql with charset utf8 (max 1000byte = 333 utf8 chars)
 626          // before we can shorten the message_id, we have to make sure there are no identical message_id > 128 chars
 627          // and we have to truncate the message_id explicitly, postgresql f.e. will not do it for us, but bail out instead
 628          $to_delete = array();
 629          $to_truncate = array();
 630          $GLOBALS['egw_setup']->db->select('phpgw_lang','app_name,lang,message_id','LENGTH(message_id) > 128',__LINE__,__FILE__,
 631              false,'ORDER BY app_name,lang,message_id');
 632          while(($row = $GLOBALS['egw_setup']->db->row(true)))
 633          {
 634              if ($last_row && $last_row['app_name'] == $row['app_name'] && $last_row['lang'] == $row['lang'] && 
 635                  substr($last_row['message_id'],0,128) == substr($row['message_id'],0,128))
 636              {
 637                  $to_delete[] = $row;
 638              }
 639              else
 640              {
 641                  $to_truncate[] = $row;
 642              }
 643              $last_row = $row;
 644          }
 645          $table_def = $GLOBALS['egw_setup']->oProc->GetTableDefinition('phpgw_lang');
 646          foreach ($to_delete as $row)
 647          {
 648              $GLOBALS['egw_setup']->db->delete('phpgw_lang',$row,__LINE__,__FILE__,False,$table_def);
 649          }
 650          foreach ($to_truncate as $row)
 651          {
 652              $where = $row;
 653              $row['message_id'] = substr($row['message_id'],0,128);
 654              $GLOBALS['egw_setup']->db->update('phpgw_lang',$row,$where,__LINE__,__FILE__,'phpgwapi',False,$table_def);
 655          }
 656          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_lang','app_name',array(
 657              'type' => 'varchar',
 658              'precision' => '32',
 659              'nullable' => False,
 660              'default' => 'common'
 661          ));
 662          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_lang','message_id',array(
 663              'type' => 'varchar',
 664              'precision' => '128',
 665              'nullable' => False,
 666              'default' => ''
 667          ));
 668          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_lang','egw_lang');
 669          $GLOBALS['egw_setup']->set_table_names(True);
 670          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_languages','egw_languages');
 671          $GLOBALS['egw_setup']->set_table_names(True);
 672  
 673          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.015';
 674          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 675      }
 676  
 677  
 678      $test[] = '1.0.1.015';
 679  	function phpgwapi_upgrade1_0_1_015()
 680      {
 681          // index was to big for mysql with charset utf8 (max 1000byte = 333 utf8 chars)
 682          /* done by RefreshTable() anyway
 683          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_contentmap','map_id',array(
 684              'type' => 'varchar',
 685              'precision' => '128',
 686              'nullable' => False
 687          ));*/
 688          /* done by RefreshTable() anyway
 689          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_contentmap','map_guid',array(
 690              'type' => 'varchar',
 691              'precision' => '128',
 692              'nullable' => False
 693          ));*/
 694          /* done by RefreshTable() anyway
 695          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_contentmap','map_locuid',array(
 696              'type' => 'int',
 697              'precision' => '8',
 698              'nullable' => False
 699          ));*/
 700          $GLOBALS['egw_setup']->oProc->RefreshTable('egw_contentmap',array(
 701              'fd' => array(
 702                  'map_id' => array('type' => 'varchar','precision' => '128','nullable' => False),
 703                  'map_guid' => array('type' => 'varchar','precision' => '128','nullable' => False),
 704                  'map_locuid' => array('type' => 'int','precision' => '8','nullable' => False),
 705                  'map_timestamp' => array('type' => 'timestamp','nullable' => False),
 706                  'map_expired' => array('type' => 'bool','nullable' => False)
 707              ),
 708              'pk' => array('map_id','map_guid','map_locuid'),
 709              'fk' => array(),
 710              'ix' => array('map_expired',array('map_id','map_locuid')),
 711              'uc' => array()
 712          ));
 713  
 714          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.016';
 715          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 716      }
 717  
 718  
 719      $test[] = '1.0.1.016';
 720  	function phpgwapi_upgrade1_0_1_016()
 721      {
 722          // index was to big for mysql with charset utf8 (max 1000byte = 333 utf8 chars)
 723          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_vfs2_files','name',array(
 724              'type' => 'varchar',
 725              'precision' => '64',
 726              'nullable' => False
 727          ));
 728  
 729          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.017';
 730          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 731      }
 732  
 733  
 734      $test[] = '1.0.1.017';
 735  	function phpgwapi_upgrade1_0_1_017()
 736      {
 737          // index was to big for mysql with charset utf8 (max 1000byte = 333 utf8 chars)
 738          /* done by RefreshTable() anyway
 739          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_vfs','vfs_name',array(
 740              'type' => 'varchar',
 741              'precision' => '64',
 742              'nullable' => False
 743          ));*/
 744          $GLOBALS['egw_setup']->oProc->RefreshTable('egw_vfs',array(
 745              'fd' => array(
 746                  'vfs_file_id' => array('type' => 'auto','nullable' => False),
 747                  'vfs_owner_id' => array('type' => 'int','precision' => '4','nullable' => False),
 748                  'vfs_createdby_id' => array('type' => 'int','precision' => '4'),
 749                  'vfs_modifiedby_id' => array('type' => 'int','precision' => '4'),
 750                  'vfs_created' => array('type' => 'date','nullable' => False,'default' => '1970-01-01'),
 751                  'vfs_modified' => array('type' => 'date'),
 752                  'vfs_size' => array('type' => 'int','precision' => '4'),
 753                  'vfs_mime_type' => array('type' => 'varchar','precision' => '64'),
 754                  'vfs_deleteable' => array('type' => 'char','precision' => '1','default' => 'Y'),
 755                  'vfs_comment' => array('type' => 'varchar','precision' => '255'),
 756                  'vfs_app' => array('type' => 'varchar','precision' => '25'),
 757                  'vfs_directory' => array('type' => 'varchar','precision' => '255'),
 758                  'vfs_name' => array('type' => 'varchar','precision' => '64','nullable' => False),
 759                  'vfs_link_directory' => array('type' => 'varchar','precision' => '255'),
 760                  'vfs_link_name' => array('type' => 'varchar','precision' => '128'),
 761                  'vfs_version' => array('type' => 'varchar','precision' => '30','nullable' => False,'default' => '0.0.0.0'),
 762                  'vfs_content' => array('type' => 'text')
 763              ),
 764              'pk' => array('vfs_file_id'),
 765              'fk' => array(),
 766              'ix' => array(array('vfs_directory','vfs_name')),
 767              'uc' => array()
 768          ));
 769  
 770          $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.018';
 771          return $GLOBALS['setup_info']['phpgwapi']['currentver'];
 772      }
 773  
 774  
 775      $test[] = '1.0.1.018';
 776  	function phpgwapi_upgrade1_0_1_018()
 777      {
 778          // This update fixes charset in mysql4+ tables, if the default client charset does not match the eGW system-charset.
 779          // It is necessary as update, as we now set the system_charset as client charset, which causes the existing input to be returned wrong.
 780          
 781          
 782          // We have to shorten the felamimail columns first, as this update would fail, because it's run before the felamimail update
 783          // (shortening them twice, does no harm) !!!
 784          if ($GLOBALS['egw_setup']->table_exist(array('phpgw_felamimail_cache')))
 785          {
 786              $table_def_cache = $GLOBALS['egw_setup']->oProc->GetTableDefinition('phpgw_felamimail_cache');
 787              $table_def_folderstatus = $GLOBALS['egw_setup']->oProc->GetTableDefinition('phpgw_felamimail_folderstatus');
 788  
 789              foreach (array('fmail_accountname','accountname','fmail_foldername','foldername') as $column_name)
 790              {
 791                  if (isset($table_def_cache['fd'][$column_name]))
 792                  {
 793                      $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_felamimail_cache',$column_name,array(
 794                  'type' => 'varchar',
 795                  'precision' => '128',
 796                  'nullable' => False
 797              ));
 798                  }
 799                  if (isset($table_def_folderstatus['fd'][$column_name]))
 800                  {
 801                      $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_felamimail_folderstatus',$column_name,array(
 802                  'type' => 'varchar',
 803                  'precision' => '128',
 804                  'nullable' => False
 805              ));
 806          }
 807              }
 808          }
 809          if (substr($GLOBALS['egw_setup']->db->Type,0,5) == 'mysql' && $GLOBALS['egw_setup']->system_charset && $GLOBALS['egw_setup']->db_charset_was &&
 810              $GLOBALS['egw_setup']->system_charset != $GLOBALS['egw_setup']->db_charset_was)
 811          {
 812              include (EGW_SERVER_ROOT.'/setup/fix_mysql_charset.php');
 813  
 814              // now the DB is fixed we can set the charset
 815              $GLOBALS['egw_setup']->db->Link_ID->SetCharSet($GLOBALS['egw_setup']->system_charset);
 816          }
 817          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.019';
 818      }
 819  
 820  
 821      $test[] = '1.0.1.019';
 822  	function phpgwapi_upgrade1_0_1_019()
 823      {
 824          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_categories','egw_categories');
 825          $GLOBALS['egw_setup']->cats_table = 'egw_categories';
 826  
 827          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.020';
 828      }
 829  
 830  
 831      $test[] = '1.0.1.020';
 832  	function phpgwapi_upgrade1_0_1_020()
 833      {
 834          // in some old installations the email_type is NOT NULL, contrary to what our tables_current says
 835          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_addressbook','email_type',array(
 836              'type' => 'varchar',
 837              'precision' => '32',
 838              'default' => 'INTERNET'
 839          ));
 840          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_addressbook','email_home_type',array(
 841              'type' => 'varchar',
 842              'precision' => '32',
 843              'default' => 'INTERNET'
 844          ));
 845  
 846          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.021';
 847      }
 848  
 849  
 850      $test[] = '1.0.1.021';
 851  	function phpgwapi_upgrade1_0_1_021()
 852      {
 853          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_hooks','egw_hooks');
 854          $GLOBALS['egw_setup']->hooks_table = 'egw_hooks';
 855  
 856          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.022';
 857      }
 858  
 859  
 860      $test[] = '1.0.1.022';
 861  	function phpgwapi_upgrade1_0_1_022()
 862      {
 863          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_preferences','egw_preferences');
 864          $GLOBALS['egw_setup']->prefs_table = 'egw_preferences';
 865  
 866          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.023';
 867      }
 868  
 869  
 870      $test[] = '1.0.1.023';
 871  	function phpgwapi_upgrade1_0_1_023()
 872      {
 873          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_sessions','egw_sessions');
 874          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_sessions','session_dla',array(
 875              'type' => 'int',
 876              'precision' => '8',        // timestamps need to be 64bit since the 32bit overflow in 2003
 877          ));
 878          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_sessions','session_logintime',array(
 879              'type' => 'int',
 880              'precision' => '8',        // timestamps need to be 64bit since the 32bit overflow in 2003
 881          ));
 882  
 883          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_app_sessions','egw_app_sessions');
 884          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_app_sessions','session_dla',array(
 885              'type' => 'int',
 886              'precision' => '8',        // timestamps need to be 64bit since the 32bit overflow in 2003
 887          ));
 888  
 889          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.024';
 890      }
 891  
 892  
 893      $test[] = '1.0.1.024';
 894  	function phpgwapi_upgrade1_0_1_024()
 895      {
 896          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_access_log','egw_access_log');
 897  
 898          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.025';
 899      }
 900  
 901  
 902      $test[] = '1.0.1.025';
 903  	function phpgwapi_upgrade1_0_1_025()
 904      {
 905          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_nextid','egw_nextid');
 906  
 907          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.026';
 908      }
 909  
 910  
 911      $test[] = '1.0.1.026';
 912  	function phpgwapi_upgrade1_0_1_026()
 913      {
 914          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_history_log','egw_history_log');
 915  
 916          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.027';
 917      }
 918  
 919  
 920      $test[] = '1.0.1.027';
 921  	function phpgwapi_upgrade1_0_1_027()
 922      {
 923          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_interserv','egw_interserv');
 924  
 925          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.028';
 926      }
 927  
 928  
 929      $test[] = '1.0.1.028';
 930  	function phpgwapi_upgrade1_0_1_028()
 931      {
 932          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_addressbook','egw_addressbook');
 933          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_addressbook_extra','egw_addressbook_extra');
 934  
 935          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.029';
 936      }
 937      
 938      
 939      $test[] = '1.0.1.029';
 940  	function phpgwapi_upgrade1_0_1_029()
 941      {
 942          // convert all positive group id's to negative ones, since 1.2.002 except the account_id itself
 943          // this allows duplicate id for users and groups in ldap
 944          // This update include the next 2 updates and goes direct to version 1.2.002!
 945          $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_value',array(
 946              'config_name' => 'account_repository',
 947              'config_app'  => 'phpgwapi',
 948          ),__LINE__,__FILE__);
 949          
 950          if($GLOBALS['egw_setup']->db->next_record() && $GLOBALS['egw_setup']->db->f('config_value') == 'ldap')
 951          {
 952              $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->acl_table,'DISTINCT acl_location',array(
 953                  'acl_appname' => 'phpgw_group',
 954                  'acl_location > 0',
 955              ),__LINE__,__FILE__);
 956          }
 957          else
 958          {
 959              $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->accounts_table,'account_id',array(
 960                  'account_type' => 'g',
 961                  'account_id > 0',
 962              ),__LINE__,__FILE__);
 963          }
 964          $groupIDs = array();
 965          while($GLOBALS['egw_setup']->db->next_record())
 966          {
 967              $groupIDs[] = $GLOBALS['egw_setup']->db->f(0);
 968          }
 969          $tables = array();
 970          foreach($GLOBALS['egw_setup']->db->table_names() as $data)
 971          {
 972              $tables[] = $data['table_name'];
 973          }
 974          foreach(array(
 975              array('egw_acl','acl_location'),
 976              array('egw_acl','acl_account'),
 977              array('egw_accounts','account_primary_group',"account_type='u'"),
 978              array('egw_cal_user','cal_user_id',"cal_user_type='u'"),
 979              // adding the old name, as the rename might have not been done (api upgrades run befor app ones)
 980              array('phpgw_cal_user','cal_user_id',"cal_user_type='u'"),
 981              array('egw_wiki_pages','wiki_readable',true),
 982              array('egw_wiki_pages','wiki_writable',true),
 983              // adding the old name, as the rename might have not been done (api upgrades run befor app ones)
 984              array('phpgw_wiki_pages','wiki_readable',true),
 985              array('phpgw_wiki_pages','wiki_writable',true),
 986              array('egw_vfs','vfs_owner_id'),
 987              array('egw_vfs','vfs_createdby_id'),
 988          ) as $data)
 989          {
 990              $where = false;
 991              list($table,$col,$where) = $data;
 992              
 993              if (!in_array($table,$tables)) continue;    // app is not installed
 994  
 995              if ($col == 'acl_location')    // varchar not int!
 996              {
 997                  $set = $col.'='.$GLOBALS['egw_setup']->db->concat("'-'",$col);
 998                  $in = "$col IN ('".implode("','",$groupIDs)."')";
 999              }
1000              else
1001              {
1002                  $set = "$col=-$col";
1003                  $in = "$col IN (".implode(',',$groupIDs).')';                
1004              }
1005              if ($where === true)
1006              {
1007                  $in = '';
1008                  $where = '1=1';
1009              }
1010              $query = "UPDATE $table SET $set WHERE $in".($in && $where ? ' AND ' : '').$where;
1011              //echo "<p>$query</p>\n";
1012              $GLOBALS['egw_setup']->db->query($query,__LINE__,__FILE__);
1013          }
1014          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.002';
1015      }
1016      
1017      
1018      $test[] = '1.2';
1019  	function phpgwapi_upgrade1_2()
1020      {
1021          // groupid's in egw_vfs.{owner|createdby}_id were not converted
1022          $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_value',array(
1023              'config_name' => 'account_repository',
1024              'config_app'  => 'phpgwapi',
1025          ),__LINE__,__FILE__);
1026          
1027          if($GLOBALS['egw_setup']->db->next_record() && $GLOBALS['egw_setup']->db->f('config_value') == 'ldap')
1028          {
1029              $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->acl_table,'DISTINCT acl_location',array(
1030                  'acl_appname' => 'phpgw_group',
1031              ),__LINE__,__FILE__);
1032          }
1033          else
1034          {
1035              $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->accounts_table,'account_id',array(
1036                  'account_type' => 'g',
1037              ),__LINE__,__FILE__);
1038          }
1039          $groupIDs = array();
1040          while($GLOBALS['egw_setup']->db->next_record())
1041          {
1042              $groupIDs[] = abs($GLOBALS['egw_setup']->db->f(0));
1043          }
1044          $tables = array();
1045          foreach($GLOBALS['egw_setup']->db->table_names() as $data)
1046          {
1047              $tables[] = $data['table_name'];
1048          }
1049          foreach(array(
1050              array('egw_vfs','vfs_owner_id'),
1051              array('egw_vfs','vfs_createdby_id'),
1052          ) as $data)
1053          {
1054              $where = false;
1055              list($table,$col,$where) = $data;
1056              
1057              if (!in_array($table,$tables)) continue;    // app is not installed
1058  
1059              if ($col == 'acl_location')    // varchar not int!
1060              {
1061                  $set = $col.'='.$GLOBALS['egw_setup']->db->concat("'-'",$col);
1062                  $in = "$col IN ('".implode("','",$groupIDs)."')";
1063              }
1064              else
1065              {
1066                  $set = "$col=-$col";
1067                  $in = "$col IN (".implode(',',$groupIDs).')';                
1068              }
1069              if ($where === true)
1070              {
1071                  $in = '';
1072                  $where = '1=1';
1073              }
1074              $query = "UPDATE $table SET $set WHERE $in".($in && $where ? ' AND ' : '').$where;
1075              //echo "<p>$query</p>\n";
1076              $GLOBALS['egw_setup']->db->query($query,__LINE__,__FILE__);
1077          }
1078          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.001';
1079      }
1080      
1081      $test[] = '1.2.001';
1082  	function phpgwapi_upgrade1_2_001()
1083      {
1084          // convert groupid's in egw_accounts back to positive, as not all DBMS can deal with neg. id's
1085          if ($GLOBALS['egw_setup']->db->Type == 'mssql')
1086          {
1087              $GLOBALS['egw_setup']->db->query("SET identity_update egw_accounts ON",__LINE__,__FILE__);
1088          }
1089          $GLOBALS['egw_setup']->db->query("UPDATE egw_accounts SET account_id=-account_id WHERE account_type='g' AND account_id < 0",__LINE__,__FILE__);
1090  
1091          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.002';
1092      }
1093  
1094      $test[] = '1.2.002';
1095  	function phpgwapi_upgrade1_2_002()
1096      {
1097          // removed 1.2.002 update as it exceeded the max index of 1000Byte under MySQL, 1.2.004 does the right thing now
1098          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.003';
1099      }
1100  
1101      $test[] = '1.2.003';
1102  	function phpgwapi_upgrade1_2_003()
1103      {
1104          // change lenght of dir/name from 255/64 to 233/100, as 64 was definitly to short, 
1105          // sum has to be <= 333 (1000/3) because of the mysql index restrictions
1106          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_vfs','vfs_directory',array(
1107              'type' => 'varchar',
1108              'precision' => '233'
1109          ));
1110          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_vfs','vfs_name',array(
1111              'type' => 'varchar',
1112              'precision' => '100',
1113              'nullable' => False
1114          ));
1115  
1116          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.004';
1117      }
1118  
1119      $test[] = '1.2.004';
1120  	function phpgwapi_upgrade1_2_004()
1121      {
1122          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_contentmap','map_guid',array(
1123              'type' => 'varchar',
1124              'precision' => '100',
1125              'nullable' => False
1126          ));
1127          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_contentmap','map_locuid',array(
1128              'type' => 'varchar',
1129              'precision' => '100',
1130              'nullable' => False
1131          ));
1132  
1133          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.005';
1134      }
1135  
1136      $test[] = '1.2.005';
1137  	function phpgwapi_upgrade1_2_005()
1138      {
1139          // new version number for 1.2RC7
1140          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.007';
1141      }
1142  
1143      $test[] = '1.2.007';
1144  	function phpgwapi_upgrade1_2_007()
1145      {
1146          // fixing the lang change from zt -> zh-tw for existing installations
1147          $GLOBALS['egw_setup']->db->update('egw_languages',array('lang_id' => 'zh-tw'),array('lang_id' => 'zt'),__LINE__,__FILE__);
1148  
1149          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.008';
1150      }
1151  
1152      $test[] = '1.2.008';
1153  	function phpgwapi_upgrade1_2_008()
1154      {
1155          // final 1.2 release
1156          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.100';
1157      }
1158  
1159  
1160      $test[] = '1.2.100';
1161  	function phpgwapi_upgrade1_2_100()
1162      {
1163          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_accounts','account_lid',array(
1164              'type' => 'varchar',
1165              'precision' => '64',
1166              'nullable' => False
1167          ));
1168  
1169          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.101';
1170      }
1171  
1172  
1173      $test[] = '1.2.101';
1174  	function phpgwapi_upgrade1_2_101()
1175      {
1176          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_access_log','sessionid',array(
1177              'type' => 'char',
1178              'precision' => '128',
1179              'nullable' => False
1180          ));
1181  
1182          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.102';
1183      }
1184  
1185  
1186      $test[] = '1.2.102';
1187  	function phpgwapi_upgrade1_2_102()
1188      {
1189          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.103';
1190      }
1191  
1192  
1193      $test[] = '1.2.103';
1194  	function phpgwapi_upgrade1_2_103()
1195      {
1196          $GLOBALS['egw_setup']->oProc->AlterColumn('egw_links','link_remark',array(
1197              'type' => 'varchar',
1198              'precision' => '100'
1199          ));
1200  
1201          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.104';
1202      }
1203  
1204  
1205      $test[] = '1.2.104';
1206  	function phpgwapi_upgrade1_2_104()
1207      {
1208          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.105';
1209      }
1210  
1211  
1212      $test[] = '1.2.105';
1213  	function phpgwapi_upgrade1_2_105()
1214      {
1215          return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.2.106';
1216      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7