[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

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

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   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 20295 2006-02-15 12:31:25Z  $ */
  13  
  14      $test[] = '0.9.13.001';
  15  	function sitemgr_upgrade0_9_13_001()
  16      {
  17          global $setup_info;
  18          $setup_info['sitemgr']['currentver'] = '0.9.14.001';
  19  
  20          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_pages',
  21              'sort_order',array('type'=>int, 'precision'=>4));
  22          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_categories',
  23              'sort_order',array('type'=>int, 'precision'=>4));
  24  
  25          return $setup_info['sitemgr']['currentver'];
  26      }
  27  
  28      $test[] = '0.9.14.001';
  29  	function sitemgr_upgrade0_9_14_001()
  30      {
  31          global $setup_info;
  32          $setup_info['sitemgr']['currentver'] = '0.9.14.002';
  33  
  34          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_pages',
  35              'hide_page',array('type'=>int, 'precision'=>4));
  36          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_categories',
  37              'parent',array('type'=>int, 'precision'=>4));
  38  
  39          return $setup_info['sitemgr']['currentver'];
  40      }
  41  
  42      $test[] = '0.9.14.002';
  43  	function sitemgr_upgrade0_9_14_002()
  44      {
  45          /******************************************************\
  46          * Purpose of this upgrade is to switch to phpgw        *
  47          * categories from the db categories.  So the           *
  48          * sql data will be moved to the cat stuff and the sql  *
  49          * categories table will be deleted.                    *
  50          *                                                      *
  51          * It would be nice if we could just run an UPDATE sql  *
  52          * query, but then you run the risk of this scenario:   *
  53          * old_cat_id = 5, new_cat_id = 2 --> update all pages  *
  54          * old_cat_id = 2, new_cat_id = 3 --> update all pages  *
  55          *  now all old_cat_id 5 pages are cat_id 3....         *
  56          \******************************************************/
  57          global $setup_info;
  58          $setup_info['sitemgr']['currentver'] = '0.9.14.003';
  59  
  60          //$cat_db_so =& CreateObject('sitemgr.Categories_db_SO');
  61  
  62          //$cat_db_so->convert_to_phpgwapi();
  63  
  64          // Finally, delete the categories table
  65          //$GLOBALS['egw_setup']->oProc->DropTable('phpgw_sitemgr_categories');
  66          
  67          // Turns out that convert_to_phpgwapi() must be run under 
  68          // the normal phpgw environment and not the setup env.
  69          // This upgrade routine has been moved to the main body 
  70          // of code.
  71  
  72          return $setup_info['sitemgr']['currentver'];
  73      }
  74  
  75      $test[] = '0.9.14.003';
  76  	function sitemgr_upgrade0_9_14_003()
  77      {
  78          global $setup_info;
  79          $setup_info['sitemgr']['currentver'] = '0.9.14.004';
  80  
  81          if (file_exists(EGW_SERVER_ROOT .'/sitemgr/setup/sitemgr_sitelang'))
  82          {
  83              $langfile = file(EGW_SERVER_ROOT . '/sitemgr/setup/sitemgr_sitelang');
  84              $lang = rtrim($langfile[0]);
  85              if (strlen($lang) != 2)
  86              {
  87                  $lang = "en";
  88              }
  89              }
  90          else
  91              {
  92                  $lang = "en";
  93              }
  94  
  95          //echo 'Updating sitemgr to a multilingual architecture with existing site language ' . $lang;
  96  
  97          $db2 = $GLOBALS['egw_setup']->db;
  98  
  99          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_pages_lang',
 100              array(
 101                  'fd' => array(
 102                      'page_id' => array('type' => 'auto', 'nullable' => false),
 103                      'lang' => array('type' => 'varchar', 'precision' => 2, 
 104                          'nullable' => false),
 105                      'title' => array('type' => 'varchar', 'precision' => 256),
 106                      'subtitle' => array('type' => 'varchar', 
 107                          'precision' => 256),
 108                      'content' => array('type' => 'text')
 109                  ),
 110                  'pk' => array('page_id','lang'),
 111                  'fk' => array(),
 112                  'ix' => array(),
 113                  'uc' => array()
 114              )
 115          );
 116          $GLOBALS['egw_setup']->oProc->CreateTable(
 117              'phpgw_sitemgr_categories_lang',
 118              array(
 119                  'fd' => array(
 120                      'cat_id' => array('type' => 'auto', 'nullable' => false),
 121                      'lang' => array('type' => 'varchar', 'precision' => 2, 
 122                          'nullable' => false),
 123                      'name' => array('type' => 'varchar', 'precision' => 100),
 124                      'description' => array('type' => 'varchar', 
 125                          'precision' => 256)
 126                  ),
 127                  'pk' => array('cat_id','lang'),
 128                  'fk' => array(),
 129                  'ix' => array(),
 130                  'uc' => array()
 131              )
 132          );
 133          $GLOBALS['egw_setup']->oProc->query("select * from {$GLOBALS['egw_setup']->cats_table} where cat_appname='sitemgr'");
 134          while($GLOBALS['egw_setup']->oProc->next_record())
 135          {
 136              $cat_id = $GLOBALS['egw_setup']->oProc->f('cat_id');
 137              $name = $GLOBALS['egw_setup']->oProc->f('cat_name');
 138              $description = $GLOBALS['egw_setup']->oProc->f('cat_description');
 139              $db2->query("INSERT INTO phpgw_sitemgr_categories_lang (cat_id, lang, name, description) VALUES ($cat_id, '$lang', '$name', '$description')");
 140          }
 141  
 142          $GLOBALS['egw_setup']->oProc->query("select * from phpgw_sitemgr_pages");
 143          while($GLOBALS['egw_setup']->oProc->next_record())
 144          {
 145              $page_id = $GLOBALS['egw_setup']->oProc->f('page_id');
 146              $title = $GLOBALS['egw_setup']->oProc->f('title');
 147              $subtitle = $GLOBALS['egw_setup']->oProc->f('subtitle');
 148              $content =  $GLOBALS['egw_setup']->oProc->f('content');
 149                      
 150              $db2->query("INSERT INTO phpgw_sitemgr_pages_lang (page_id, lang, title, subtitle, content) VALUES ($page_id, '$lang', '$title', '$subtitle', '$content')");
 151          }
 152          
 153          $newtbldef = array(
 154              'fd' => array(
 155                  'page_id' => array('type' => 'auto', 'nullable' => false),
 156                  'cat_id' => array('type' => 'int', 'precision' => 4),
 157                  'sort_order' => array('type' => 'int', 'precision' => 4),
 158                  'hide_page' => array('type' => 'int', 'precision' => 4),
 159                  'name' => array('type' => 'varchar', 'precision' => 100),
 160                  'subtitle' => array('type' => 'varchar', 'precision' => 256),
 161                  'content' => array('type' => 'text')
 162              ),
 163              'pk' => array('page_id'),
 164              'fk' => array(),
 165              'ix' => array('cat_id'),
 166              'uc' => array()
 167          );
 168          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_pages',
 169              $newtbldef,'title');
 170          $newtbldef = array(
 171              'fd' => array(
 172                  'page_id' => array('type' => 'auto', 'nullable' => false),
 173                  'cat_id' => array('type' => 'int', 'precision' => 4),
 174                  'sort_order' => array('type' => 'int', 'precision' => 4),
 175                  'hide_page' => array('type' => 'int', 'precision' => 4),
 176                  'name' => array('type' => 'varchar', 'precision' => 100),
 177                  'content' => array('type' => 'text')
 178              ),
 179              'pk' => array('page_id'),
 180              'fk' => array(),
 181              'ix' => array('cat_id'),
 182              'uc' => array()
 183          );
 184          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_pages',
 185              $newtbldef,'subtitle');
 186          $newtbldef = array(
 187              'fd' => array(
 188                  'page_id' => array('type' => 'auto', 'nullable' => false),
 189                  'cat_id' => array('type' => 'int', 'precision' => 4),
 190                  'sort_order' => array('type' => 'int', 'precision' => 4),
 191                  'hide_page' => array('type' => 'int', 'precision' => 4),
 192                  'name' => array('type' => 'varchar', 'precision' => 100)
 193              ),
 194              'pk' => array('page_id'),
 195              'fk' => array(),
 196              'ix' => array('cat_id'),
 197              'uc' => array()
 198          );
 199          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_pages',
 200              $newtbldef,'content');
 201  
 202          // try to set the sitelanguages preference. 
 203          // if it already exists do nothing
 204          $db2->query("SELECT pref_id FROM phpgw_sitemgr_preferences WHERE name='sitelanguages'");
 205          if ($db2->next_record())
 206          {
 207          }
 208          else
 209          {
 210              $db2->query("INSERT INTO phpgw_sitemgr_preferences (name, value) VALUES ('sitelanguages', '$lang')");
 211          }
 212  
 213          //internationalize the names for site-name, header and footer 
 214          //preferences
 215          $prefstochange = array('sitemgr-site-name','siteheader','sitefooter');
 216          
 217          foreach ($prefstochange as $oldprefname)
 218          {
 219              $newprefname = $oldprefname . '-' . $lang;
 220              //echo "DEBUG: Changing $oldprefname to $newprefname. ";
 221              $db2->query("UPDATE phpgw_sitemgr_preferences SET name='$newprefname' where name='$oldprefname'");
 222          }
 223  
 224          return $setup_info['sitemgr']['currentver'];    
 225      } 
 226  
 227      $test[] = '0.9.14.004';
 228  	function sitemgr_upgrade0_9_14_004()
 229      {
 230          global $setup_info;
 231          $setup_info['sitemgr']['currentver'] = '0.9.14.005';
 232  
 233          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_sitemgr_blocks', 'position', 'pos');
 234  
 235          return $setup_info['sitemgr']['currentver'];                             
 236      }
 237  
 238      $test[] = '0.9.14.005';
 239  	function sitemgr_upgrade0_9_14_005()
 240      {
 241          global $setup_info;
 242          $setup_info['sitemgr']['currentver'] = '0.9.14.006';
 243  
 244          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_blocks',
 245              'description', array('type' => 'varchar', 'precision' => 256));
 246          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_blocks',
 247              'view', array('type' => 'int', 'precision' => 4));
 248          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_blocks',
 249              'actif', array('type' => 'int', 'precision' => 2));
 250          return $setup_info['sitemgr']['currentver'];
 251      }
 252      
 253      $test[] = '0.9.14.006';
 254  	function sitemgr_upgrade0_9_14_006()
 255      {
 256          global $setup_info;
 257          $setup_info['sitemgr']['currentver'] = '0.9.15.001';
 258  
 259          $GLOBALS['egw_setup']->oProc->DropTable('phpgw_sitemgr_blocks');
 260          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_modules',array(
 261              'fd' => array(
 262                  'module_id' => array('type' => 'auto', 'precision' => 4, 'nullable' => false),
 263                  'app_name' => array('type' => 'varchar', 'precision' => 25),
 264                  'module_name' => array('type' => 'varchar', 'precision' => 25),
 265                  'description' => array('type' => 'varchar', 'precision' => 255)
 266              ),
 267              'pk' => array('module_id'),
 268              'fk' => array(),
 269              'ix' => array(),
 270              'uc' => array()
 271          ));
 272          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_content',array(
 273              'fd' => array(
 274                  'block_id' => array('type' => 'auto', 'nullable' => false),
 275                  'area' => array('type' => 'varchar', 'precision' => 50),
 276                  //if page_id != NULL scope=page, elseif cat_id != NULL scope=category, else scope=site
 277                  'cat_id' => array('type' => 'int', 'precision' => 4),
 278                  'page_id' => array('type' => 'int', 'precision' => 4),
 279                  'module_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 280                  'arguments' => array('type' => 'text'),
 281                  'sort_order' => array('type' => 'int', 'precision' => 4),
 282                  'view' => array('type' => 'int', 'precision' => 4),
 283                  'actif' => array('type' => 'int', 'precision' => 2)
 284              ),
 285              'pk' => array('block_id'),
 286              'fk' => array(),
 287              'ix' => array(),
 288              'uc' => array()
 289          ));
 290          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_content_lang',array(
 291              'fd' => array(
 292                  'block_id' => array('type' => 'auto', 'nullable' => false),
 293                  'lang' => array('type' => 'varchar', 'precision' => 2, 'nullable' => false),
 294                  'arguments_lang' => array('type' => 'text'),
 295                  'title' => array('type' => 'varchar', 'precision' => 255),
 296              ),
 297              'pk' => array('block_id','lang'),
 298              'fk' => array(),
 299              'ix' => array(),
 300              'uc' => array()
 301          ));
 302          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_active_modules',array(
 303              'fd' => array(
 304                  // area __PAGE__ stands for master list
 305                  'area' => array('type' => 'varchar', 'precision' => 50, 'nullable' => false),
 306                  // cat_id 0 stands for site wide
 307                  'cat_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 308                  'module_id' => array('type' => 'auto', 'precision' => 4, 'nullable' => false)
 309              ),
 310              'pk' => array('area','cat_id','module_id'),
 311              'fk' => array(),
 312              'ix' => array(),
 313              'uc' => array()
 314          ));
 315          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_properties',array(
 316              'fd' => array(
 317                  // area __PAGE__ stands for all areas
 318                  'area' => array('type' => 'varchar', 'precision' => 50, 'nullable' => false),
 319                  // cat_id 0 stands for site wide 
 320                  'cat_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false), 
 321                  'module_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 322                  'properties' => array('type' => 'text')
 323              ),
 324              'pk' => array('area','cat_id','module_id'),
 325              'fk' => array(),
 326              'ix' => array(),
 327              'uc' => array()
 328          ));
 329  
 330          //we register some standard modules so that the default site template works
 331          // but only if we running a real update
 332          if (!$GLOBALS['egw_setup']->oProc->m_bDeltaOnly)
 333          {
 334          $db2 = $GLOBALS['egw_setup']->db;
 335              foreach (array('index','toc','html') as $module)
 336              {
 337                  $db2->query("INSERT INTO phpgw_sitemgr_modules (app_name,module_name) VALUES ('sitemgr','$module')",__LINE__,__FILE__);
 338                  $module_id = $db2->get_last_insert_id('phpgw_sitemgr_modules','module_id');
 339                  $db2->query("INSERT INTO phpgw_sitemgr_active_modules (area,cat_id,module_id) VALUES ('__PAGE__',0,$module_id)",__LINE__,__FILE__);
 340              }
 341          }
 342          //now to the difficult part: we try to put the old content field of phpgw_sitemgr_pages into the new phpgw_sitemgr_content table
 343          $db3 = $GLOBALS['egw_setup']->db;
 344          $GLOBALS['egw_setup']->oProc->query("select * from phpgw_sitemgr_pages",__LINE__,__FILE__);
 345          $emptyarray = serialize(array());
 346          while($GLOBALS['egw_setup']->oProc->next_record())
 347          {
 348              $page_id = $GLOBALS['egw_setup']->oProc->f('page_id');
 349              $cat_id = $GLOBALS['egw_setup']->oProc->f('cat_id');
 350              //module_id is still the id of html module since it is the last inserted above
 351              $db2->query("INSERT INTO phpgw_sitemgr_content (area,cat_id,page_id,module_id,arguments,sort_order,view,actif) VALUES ('CENTER',$cat_id,$page_id,$module_id,'$emptyarray',0,0,1)",__LINE__,__FILE__);
 352              $block_id = $db2->get_last_insert_id('phpgw_sitemgr_content','block_id');
 353              $db2->query("select * from phpgw_sitemgr_pages_lang WHERE page_id = $page_id",__LINE__,__FILE__);
 354              while($db2->next_record())
 355              {
 356                  $lang = $db2->f('lang');
 357                  $content = $db2->db_addslashes(serialize(array('htmlcontent' => stripslashes($db2->f('content')))));
 358                  $db3->query("INSERT INTO phpgw_sitemgr_content_lang (block_id,lang,arguments_lang,title) VALUES ($block_id,'$lang','$content','HTML')",__LINE__,__FILE__);
 359              }
 360          }
 361          //finally drop the content field
 362          $newtbldef = array(
 363              'fd' => array(
 364                  'page_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 365                  'lang' => array('type' => 'varchar', 'precision' => 2, 'nullable' => false),
 366                  'title' => array('type' => 'varchar', 'precision' => 255),
 367                  'subtitle' => array('type' => 'varchar', 'precision' => 255)
 368              ),
 369              'pk' => array('page_id','lang'),
 370              'fk' => array(),
 371              'ix' => array(),
 372              'uc' => array()
 373          );
 374          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_pages_lang',$newtbldef,'content');
 375          return $setup_info['sitemgr']['currentver'];
 376      }
 377  
 378      $test[] = '0.9.15.001';
 379  	function sitemgr_upgrade0_9_15_001()
 380      {
 381          global $setup_info;
 382          $setup_info['sitemgr']['currentver'] = '0.9.15.002';
 383  
 384          $GLOBALS['egw_setup']->oProc->RenameColumn('phpgw_sitemgr_content', 'view', 'viewable');
 385  
 386          return $setup_info['sitemgr']['currentver'];                             
 387      }
 388  
 389      $test[] = '0.9.15.002';
 390  	function sitemgr_upgrade0_9_15_002()
 391      {
 392          global $setup_info;
 393          $setup_info['sitemgr']['currentver'] = '0.9.15.003';
 394  
 395          $newtbldef = array(
 396              'fd' => array(
 397                  'module_id' => array('type' => 'auto', 'precision' => 4, 'nullable' => false),
 398                  'module_name' => array('type' => 'varchar', 'precision' => 25),
 399                  'description' => array('type' => 'varchar', 'precision' => 255)
 400              ),
 401              'pk' => array('module_id'),
 402              'fk' => array(),
 403              'ix' => array(),
 404              'uc' => array()
 405          );
 406  
 407          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_modules',$newtbldef,'app_name');
 408  
 409          return $setup_info['sitemgr']['currentver'];                             
 410      }
 411  
 412      $test[] = '0.9.15.003';
 413  	function sitemgr_upgrade0_9_15_003()
 414      {
 415          global $setup_info;
 416          $setup_info['sitemgr']['currentver'] = '0.9.15.004';
 417  
 418          $GLOBALS['egw_setup']->oProc->createtable('phpgw_sitemgr_sites',array(
 419              'fd' => array(
 420                  'site_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 421                  'site_name' => array('type' => 'varchar', 'precision' => 255),
 422                  'site_url' => array('type' => 'varchar', 'precision' => 255),
 423                  'site_dir' => array('type' => 'varchar', 'precision' => 255),
 424                  'themesel' => array('type' => 'varchar', 'precision' => 50),
 425                  'site_languages' => array('type' => 'varchar', 'precision' => 50),
 426                  'home_page_id' => array('type' => 'int', 'precision' => 4),
 427                  'anonymous_user' => array('type' => 'varchar', 'precision' => 50),
 428                  'anonymous_passwd' => array('type' => 'varchar', 'precision' => 50),
 429              ),
 430              'pk' => array('site_id'),
 431              'fk' => array(),
 432              'ix' => array(),
 433              'uc' => array()
 434          ));
 435  
 436          $db2 = $GLOBALS['egw_setup']->db;
 437  
 438          //Create default site and hang all existing categories into it
 439          $GLOBALS['egw_setup']->oProc->query("INSERT INTO {$GLOBALS['egw_setup']->cats_table} (cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,last_mod) VALUES (0,-1,'public','sitemgr','Default Website','This website has been added by setup',0)");
 440  
 441          $GLOBALS['egw_setup']->oProc->query("SELECT cat_id FROM {$GLOBALS['egw_setup']->cats_table} WHERE cat_name='Default Website' AND cat_appname='sitemgr'");
 442          if ($GLOBALS['egw_setup']->oProc->next_record())
 443          {
 444              $site_id = $GLOBALS['egw_setup']->oProc->f('cat_id');
 445              $db2->query("UPDATE {$GLOBALS['egw_setup']->cats_table} SET cat_main = $site_id WHERE cat_appname = 'sitemgr'",__LINE__,__FILE__);
 446              $db2->query("UPDATE {$GLOBALS['egw_setup']->cats_table} SET cat_parent = $site_id WHERE cat_appname = 'sitemgr' AND cat_parent = 0 AND cat_id != $site_id",__LINE__,__FILE__);
 447              $db2->query("UPDATE {$GLOBALS['egw_setup']->cats_table} SET cat_level = cat_level +1 WHERE cat_appname = 'sitemgr' AND cat_id != $site_id",__LINE__,__FILE__);
 448              $db2->query("INSERT INTO phpgw_sitemgr_sites (site_id,site_name)  VALUES ($site_id,'Default Website')");
 449          }
 450  
 451          //insert values from old preferences table into new sites table
 452          $oldtonew = array(
 453              'sitemgr-site-url' => 'site_url',
 454              'sitemgr-site-dir' => 'site_dir',
 455              'themesel' => 'themesel',
 456              'sitelanguages' => 'site_languages',
 457              'home-page-id' => 'home_page_id',
 458              'anonymous-user' => 'anonymous_user',
 459              'anonymous-passwd' => 'anonymous_passwd'
 460          );
 461          foreach ($oldtonew as $old => $new)
 462          {
 463              $GLOBALS['egw_setup']->oProc->query("SELECT value from phpgw_sitemgr_preferences WHERE name = '$old'");
 464              if ($GLOBALS['egw_setup']->oProc->next_record())
 465              {
 466                  $value = $GLOBALS['egw_setup']->oProc->f('value');
 467                  $db2->query("UPDATE phpgw_sitemgr_sites SET $new = '$value' WHERE site_id = $site_id");
 468              }
 469          }
 470  
 471          //site names and headers
 472          $GLOBALS['egw_setup']->oProc->query("SELECT site_languages from phpgw_sitemgr_sites");
 473          if ($GLOBALS['egw_setup']->oProc->next_record())
 474          {
 475              $sitelanguages = $db2->f('site_languages');
 476              $sitelanguages = explode(',',$sitelanguages);
 477              $db2->query("SELECT module_id from phpgw_sitemgr_modules WHERE module_name='html'");
 478              $db2->next_record();
 479              $html_module = $db2->f('module_id');
 480              $emptyarray = serialize(array());
 481              $db2->query("INSERT INTO phpgw_sitemgr_content (area,cat_id,page_id,module_id,arguments,sort_order,viewable,actif) VALUES ('HEADER',$site_id,0,$html_module,'$emptyarray',0,0,1)",__LINE__,__FILE__);
 482              $headerblock = $db2->get_last_insert_id('phpgw_sitemgr_content','block_id');
 483              $db2->query("INSERT INTO phpgw_sitemgr_content (area,cat_id,page_id,module_id,arguments,sort_order,viewable,actif) VALUES ('FOOTER',$site_id,0,$html_module,'$emptyarray',0,0,1)",__LINE__,__FILE__);
 484              $footerblock = $db2->get_last_insert_id('phpgw_sitemgr_content','block_id');
 485  
 486              foreach ($sitelanguages as $lang)
 487              {
 488                  $db2->query("SELECT value from phpgw_sitemgr_preferences WHERE name = 'sitemgr-site-name-$lang'");
 489                  if ($db2->next_record())
 490                  {
 491                      $name_lang = $db2->f('value');
 492                      $db2->query("INSERT INTO phpgw_sitemgr_categories_lang (cat_id,lang,name) VALUES ($site_id,'$lang','$name_lang')");
 493                  }
 494                  $db2->query("SELECT value from phpgw_sitemgr_preferences WHERE name = 'siteheader-$lang'");
 495                  if ($db2->next_record())
 496                  {
 497                      $header_lang = $db2->f('value');
 498                      $content = $db2->db_addslashes(serialize(array('htmlcontent' => stripslashes($header_lang))));
 499          
 500                      $db2->query("INSERT INTO phpgw_sitemgr_content_lang (block_id,lang,arguments_lang,title) VALUES ($headerblock,'$lang','$content','Site header')",__LINE__,__FILE__);
 501                  }
 502                  $db2->query("SELECT value from phpgw_sitemgr_preferences WHERE name = 'sitefooter-$lang'");
 503                  if ($db2->next_record())
 504                  {
 505                      $footer_lang = $db2->f('value');
 506                      $content = $db2->db_addslashes(serialize(array('htmlcontent' => stripslashes($footer_lang))));
 507                  
 508                      $db2->query("INSERT INTO phpgw_sitemgr_content_lang (block_id,lang,arguments_lang,title) VALUES ($footerblock,'$lang','$content','Site footer')",__LINE__,__FILE__);
 509                  }
 510              }
 511          }
 512          $GLOBALS['egw_setup']->oProc->DropTable('phpgw_sitemgr_preferences');
 513  
 514          return $setup_info['sitemgr']['currentver'];
 515      }
 516  
 517      $test[] = '0.9.15.004';
 518  	function sitemgr_upgrade0_9_15_004()
 519      {
 520          global $setup_info;
 521          $setup_info['sitemgr']['currentver'] = '0.9.15.005';
 522          $db2 = $GLOBALS['egw_setup']->db;
 523          $db3 = $GLOBALS['egw_setup']->db;
 524  
 525          //Create the field state for pages and categories and give all existing pages and categories published state (2)
 526          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_pages',
 527              'state',array('type'=>int, 'precision'=>2));
 528      
 529          $GLOBALS['egw_setup']->oProc->query("UPDATE phpgw_sitemgr_pages SET state = 2");
 530  
 531          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_categories_state',array(
 532              'fd' => array(
 533                  'cat_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 534                  'state' => array('type' => 'int', 'precision' => 2)
 535              ),
 536              'pk' => array('cat_id'),
 537              'fk' => array(),
 538              'ix' => array(),
 539              'uc' => array()
 540          ));
 541  
 542          $GLOBALS['egw_setup']->oProc->query("select cat_id from {$GLOBALS['egw_setup']->cats_table} where cat_appname='sitemgr' AND cat_level > 0");
 543          while($GLOBALS['egw_setup']->oProc->next_record())
 544          {
 545              $cat_id = $GLOBALS['egw_setup']->oProc->f('cat_id');
 546              $db2->query("INSERT INTO phpgw_sitemgr_categories_state (cat_id,state) VALUES ($cat_id,2)");
 547          }
 548  
 549          //rename table content blocks and table content_lang blocks_lang
 550          //and add the new tables content and content_lang
 551          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_sitemgr_content','phpgw_sitemgr_blocks');
 552          $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_sitemgr_content_lang','phpgw_sitemgr_blocks_lang');
 553          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_content',array(
 554              'fd' => array(
 555                  'version_id' => array('type' => 'auto', 'nullable' => false),
 556                  'block_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 557                  'arguments' => array('type' => 'text'),
 558                  'state' => array('type' => 'int', 'precision' => 2)
 559              ),
 560              'pk' => array('version_id'),
 561              'fk' => array(),
 562              'ix' => array(),
 563              'uc' => array()
 564          ));
 565          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_content_lang',array(
 566              'fd' => array(
 567                  'version_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 568                  'lang' => array('type' => 'varchar', 'precision' => 2, 'nullable' => false),
 569                  'arguments_lang' => array('type' => 'text'),
 570              ),
 571              'pk' => array('version_id','lang'),
 572              'fk' => array(),
 573              'ix' => array(),
 574              'uc' => array()
 575          ));
 576  
 577          //create rows in the new content tables from old content tables (where state=0(Draft) when inactive, state=2(Published) when active)
 578          $GLOBALS['egw_setup']->oProc->query("SELECT block_id,arguments,actif FROM phpgw_sitemgr_blocks");
 579          while ($GLOBALS['egw_setup']->oProc->next_record())
 580          {
 581              $block_id = $GLOBALS['egw_setup']->oProc->f('block_id');
 582              $arguments = $GLOBALS['egw_setup']->oProc->f('arguments');
 583              $state = $GLOBALS['egw_setup']->oProc->f('actif') ? 0 : 2;
 584              $db2->query("INSERT INTO phpgw_sitemgr_content (block_id,arguments,state) VALUES ($block_id,'$arguments',$state)");
 585              $version_id = $db2->get_last_insert_id('phpgw_sitemgr_content','version_id');
 586              $db2->query("SELECT lang,arguments_lang  FROM phpgw_sitemgr_blocks_lang WHERE block_id = $block_id");
 587              while ($db2->next_record())
 588              {
 589                  $lang = $db2->f('lang');
 590                  $arguments_lang = $db2->f('arguments_lang');
 591                  $title = $db2->f('title');
 592                  $db3->query("INSERT INTO phpgw_sitemgr_content_lang (version_id,lang,arguments_lang) VALUES ($version_id,'$lang','$arguments_lang')");
 593              }
 594          }
 595  
 596          //drop columns in tables blocks and blocks_lang
 597          $newtbldef = array(
 598              'fd' => array(
 599                  'block_id' => array('type' => 'auto', 'nullable' => false),
 600                  'area' => array('type' => 'varchar', 'precision' => 50),
 601                  'cat_id' => array('type' => 'int', 'precision' => 4),
 602                  'page_id' => array('type' => 'int', 'precision' => 4),
 603                  'module_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 604                  'sort_order' => array('type' => 'int', 'precision' => 4),
 605                  'viewable' => array('type' => 'int', 'precision' => 4),
 606                  'actif' => array('type' => 'int', 'precision' => 2)
 607              ),
 608              'pk' => array('block_id'),
 609              'fk' => array(),
 610              'ix' => array(),
 611              'uc' => array()
 612          );
 613          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_blocks',$newtbldef,'arguments');
 614          $newtbldef = array(
 615              'fd' => array(
 616                  'block_id' => array('type' => 'auto', 'nullable' => false),
 617                  'area' => array('type' => 'varchar', 'precision' => 50),
 618                  'cat_id' => array('type' => 'int', 'precision' => 4),
 619                  'page_id' => array('type' => 'int', 'precision' => 4),
 620                  'module_id' => array('type' => 'int', 'precision' => 4, 'nullable' => false),
 621                  'sort_order' => array('type' => 'int', 'precision' => 4),
 622                  'viewable' => array('type' => 'int', 'precision' => 4),
 623              ),
 624              'pk' => array('block_id'),
 625              'fk' => array(),
 626              'ix' => array(),
 627              'uc' => array()
 628          );
 629          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_blocks',$newtbldef,'actif');
 630          $newtbldef = array(
 631              'fd' => array(
 632                  'block_id' => array('type' => 'auto', 'nullable' => false),
 633                  'lang' => array('type' => 'varchar', 'precision' => 2, 'nullable' => false),
 634                  'title' => array('type' => 'varchar', 'precision' => 255),
 635              ),
 636              'pk' => array('block_id','lang'),
 637              'fk' => array(),
 638              'ix' => array(),
 639              'uc' => array()
 640          );
 641          $GLOBALS['egw_setup']->oProc->DropColumn('phpgw_sitemgr_blocks_lang',$newtbldef,'arguments_lang');
 642          return $setup_info['sitemgr']['currentver'];
 643      }
 644  
 645  
 646      $test[] = '0.9.15.005';
 647  	function sitemgr_upgrade0_9_15_005()
 648      {
 649          // setting all lang-columns to varchar(5)
 650          foreach(array(
 651              'phpgw_sitemgr_pages_lang',
 652              'phpgw_sitemgr_categories_lang',
 653              'phpgw_sitemgr_blocks_lang',
 654              'phpgw_sitemgr_content_lang',
 655          ) as $table)
 656          {
 657              $GLOBALS['egw_setup']->oProc->AlterColumn($table,'lang',array(
 658                  'type' => 'varchar',
 659                  'precision' => '5',
 660                  'nullable' => False
 661              ));
 662          }
 663          $GLOBALS['setup_info']['sitemgr']['currentver'] = '0.9.15.006';
 664          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 665      }
 666  
 667  
 668      $test[] = '0.9.15.006';
 669  	function sitemgr_upgrade0_9_15_006()
 670      {
 671          // add column for index-pages
 672          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_categories_state','index_page_id',array(
 673              'type' => 'int',
 674              'precision' => '4',
 675              'default' => '0'
 676          ));
 677  
 678          $GLOBALS['setup_info']['sitemgr']['currentver'] = '0.9.15.007';
 679          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 680      }
 681  
 682      // the following series of updates add some indices, to speedup the selects
 683  
 684      $test[] = '0.9.15.007';
 685  	function sitemgr_upgrade0_9_15_007()
 686      {
 687          $GLOBALS['egw_setup']->oProc->RefreshTable('phpgw_sitemgr_pages',array(
 688              'fd' => array(
 689                  'page_id' => array('type' => 'auto','nullable' => False),
 690                  'cat_id' => array('type' => 'int','precision' => '4'),
 691                  'sort_order' => array('type' => 'int','precision' => '4'),
 692                  'hide_page' => array('type' => 'int','precision' => '4'),
 693                  'name' => array('type' => 'varchar','precision' => '100'),
 694                  'state' => array('type' => 'int','precision' => '2')
 695              ),
 696              'pk' => array('page_id'),
 697              'fk' => array(),
 698              'ix' => array('cat_id',array('state','cat_id','sort_order'),array('name','cat_id')),
 699              'uc' => array()
 700          ));
 701  
 702          $GLOBALS['setup_info']['sitemgr']['currentver'] = '0.9.15.008';
 703          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 704      }
 705  
 706  
 707      $test[] = '0.9.15.008';
 708  	function sitemgr_upgrade0_9_15_008()
 709      {
 710          $GLOBALS['egw_setup']->oProc->RefreshTable('phpgw_sitemgr_categories_state',array(
 711              'fd' => array(
 712                  'cat_id' => array('type' => 'int','precision' => '4','nullable' => False),
 713                  'state' => array('type' => 'int','precision' => '2'),
 714                  'index_page_id' => array('type' => 'int','precision' => '4','default' => '0')
 715              ),
 716              'pk' => array('cat_id'),
 717              'fk' => array(),
 718              'ix' => array(array('cat_id','state')),
 719              'uc' => array()
 720          ));
 721  
 722          $GLOBALS['setup_info']['sitemgr']['currentver'] = '0.9.15.009';
 723          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 724      }
 725  
 726  
 727      $test[] = '0.9.15.009';
 728  	function sitemgr_upgrade0_9_15_009()
 729      {
 730          $GLOBALS['egw_setup']->oProc->RefreshTable('phpgw_sitemgr_sites',array(
 731              'fd' => array(
 732                  'site_id' => array('type' => 'int','precision' => '4','nullable' => False),
 733                  'site_name' => array('type' => 'varchar','precision' => '255'),
 734                  'site_url' => array('type' => 'varchar','precision' => '255'),
 735                  'site_dir' => array('type' => 'varchar','precision' => '255'),
 736                  'themesel' => array('type' => 'varchar','precision' => '50'),
 737                  'site_languages' => array('type' => 'varchar','precision' => '50'),
 738                  'home_page_id' => array('type' => 'int','precision' => '4'),
 739                  'anonymous_user' => array('type' => 'varchar','precision' => '50'),
 740                  'anonymous_passwd' => array('type' => 'varchar','precision' => '50')
 741              ),
 742              'pk' => array('site_id'),
 743              'fk' => array(),
 744              'ix' => array('site_url'),
 745              'uc' => array()
 746          ));
 747  
 748          // we dont need to do update 0.9.15.010, as UpdateSequenze is called now by RefreshTable
 749          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.0';
 750          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 751      }
 752      
 753      
 754      $test[] = '0.9.15.010';
 755  	function sitemgr_upgrade0_9_15_010()
 756      {
 757          $GLOBALS['egw_setup']->oProc->UpdateSequence('phpgw_sitemgr_pages','page_id');
 758  
 759          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.0';
 760          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 761      }
 762      
 763      $test[] = '1.0.0';
 764  	function sitemgr_upgrade1_0_0()
 765      {
 766          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_notifications',array(
 767              'fd' => array(
 768                  'notification_id' => array('type' => 'auto','nullable' => False),
 769                  'site_id' => array('type' => 'int','precision' => '4','nullable' => False),
 770                  'site_language' => array('type' => 'varchar','precision' => '3','nullable' => False,'default' => 'all'),
 771                  'cat_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 772                  'email' => array('type' => 'varchar','precision' => '255','nullable' => False)
 773              ),
 774              'pk' => array('notification_id'),
 775              'fk' => array('site_id' => 'phpgw_sitemgr_sites'),
 776              'ix' => array('email'),
 777              'uc' => array()
 778          ));
 779  
 780          $GLOBALS['egw_setup']->oProc->CreateTable('phpgw_sitemgr_notify_messages',array(
 781              'fd' => array(
 782                  'message_id' => array('type' => 'auto','nullable' => False),
 783                  'site_id' => array('type' => 'int','precision' => '4','nullable' => False),
 784                  'language' => array('type' => 'varchar','precision' => '3'),
 785                  'message' => array('type' => 'text','nullable' => False),
 786                  'subject' => array('type' => 'text','nullable' => False)
 787              ),
 788              'pk' => array('message_id'),
 789              'fk' => array('site_id' => 'phpgw_sitemgr_sites'),
 790              'ix' => array(),
 791              'uc' => array(array('site_id','language'))
 792          ));
 793  
 794          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.0.001';
 795          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 796      }
 797  
 798  
 799      $test[] = '1.0.0.001';
 800  	function sitemgr_upgrade1_0_0_001()
 801      {
 802          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_sites','upload_dir',array(
 803              'type' => 'varchar',
 804              'precision' => '50'
 805          ));
 806  
 807          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.0.002';
 808          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 809      }
 810  
 811  
 812      $test[] = '1.0.0.002';
 813  	function sitemgr_upgrade1_0_0_002()
 814      {
 815          $GLOBALS['egw_setup']->oProc->AlterColumn('phpgw_sitemgr_sites','upload_dir',array(
 816              'type' => 'varchar',
 817              'precision' => '255'
 818          ));
 819          $GLOBALS['egw_setup']->oProc->AddColumn('phpgw_sitemgr_sites','upload_url',array(
 820              'type' => 'varchar',
 821              'precision' => '255'
 822          ));
 823  
 824          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.0.003';
 825          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 826      }
 827  
 828  
 829      $test[] = '1.0.0.003';
 830  	function sitemgr_upgrade1_0_0_003()
 831      {
 832          foreach(array('phpgw_sitemgr_pages','phpgw_sitemgr_pages_lang','phpgw_sitemgr_categories_state','phpgw_sitemgr_categories_lang','phpgw_sitemgr_modules','phpgw_sitemgr_blocks','phpgw_sitemgr_blocks_lang','phpgw_sitemgr_content','phpgw_sitemgr_content_lang','phpgw_sitemgr_active_modules','phpgw_sitemgr_properties','phpgw_sitemgr_sites','phpgw_sitemgr_notifications','phpgw_sitemgr_notify_messages') as $table)
 833          {
 834              $GLOBALS['egw_setup']->oProc->RenameTable($table,str_replace('phpgw_sitemgr','egw_sitemgr',$table));
 835          }
 836  
 837          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.0.1.001';
 838          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 839      }
 840  
 841      $test[] = '1.0.1.001';
 842  	function sitemgr_upgrade1_0_1_001()
 843      {
 844          // this update replaces diverse old navigation modules with conny's new "navigation" module
 845          $modules2nav_type = array('currentsection' => 1,'index' => 2,'index_block' => 3,'navigation' => 4,'sitetree' => 5,'toc' => 6,'toc_block' => 7);
 846          
 847          $db = clone($GLOBALS['egw_setup']->db);
 848          $db->set_app('sitemgr');
 849          $db2 = clone($db);
 850          
 851          // get the module_id of all navigation modules and remove the old modules
 852          $db->select('egw_sitemgr_modules','module_id,module_name',array('module_name' => array_keys($modules2nav_type)),__LINE__,__FILE__);
 853          $id2module = $old_modules = array();
 854          while(($row = $db->row(true)))
 855          {
 856              $id2module[$row['module_id']] = $row['module_name'];
 857              if ($row['module_name'] != 'navigation')
 858              {
 859                  $old_modules[] = $row['module_id'];
 860              }
 861          }
 862          $db->delete('egw_sitemgr_modules',array('module_id' => $old_modules),__LINE__,__FILE__);
 863          
 864          // check if navigation is already registered, if not register it
 865          
 866          if (!($navigation_id = array_search('navigation',$id2module)))    
 867          {
 868              if (ereg('\$this->description = lang\(\'([^'."\n".']*)\'\);',implode("\n",file(EGW_SERVER_ROOT.'/sitemgr/modules/class.module_navigation.inc.php')),$parts))
 869              {
 870                  $description = str_replace("\\'","'",$parts[1]);
 871              }
 872              $db->insert('egw_sitemgr_modules',array(
 873                  'module_name' => 'navigation',
 874                  'module_description' => $description,
 875              ),false,__LINE__,__FILE__);
 876              $navigation_id = $db->get_last_insert_id('egw_sitemgr_modules','module_id');
 877          }
 878          // add navigation to all contentareas, which allowed any for the old modules before and remove the old modules
 879          $db->select('egw_sitemgr_active_modules','DISTINCT cat_id,area',array('module_id' => $old_modules),__LINE__,__FILE__);
 880          while (($row = $db->row(true)))
 881          {
 882              $row['module_id'] = $navigation_id;
 883              $db2->insert('egw_sitemgr_active_modules',array(),$row,__LINE__,__FILE__);
 884          }
 885          $db->delete('egw_sitemgr_active_modules',array('module_id' => $old_modules),__LINE__,__FILE__);
 886          
 887          // replace old modules in the blocks with the navigation module
 888          $db->select('egw_sitemgr_blocks','block_id,module_id',array('module_id' => array_keys($id2module)),__LINE__,__FILE__);
 889          $block_id2module_id = array();
 890          while (($row = $db->row(true)))
 891          {
 892              $block_id2module_id[$row['block_id']] = $row['module_id'];
 893          }
 894          $db->select('egw_sitemgr_content','version_id,block_id,arguments',array('block_id' => array_keys($block_id2module_id)),__LINE__,__FILE__);
 895          while (($row = $db->row(true)))
 896          {
 897              $arguments = unserialize($row['arguments']);
 898              if (!isset($arguments['nav_type']))
 899              {
 900                  $version_id = $row['version_id'];
 901                  unset($row['version_id']);
 902                  $arguments['nav_type'] = $modules2nav_type[$id2module[$block_id2module_id[$row['block_id']]]];
 903                  $row['arguments'] = serialize($arguments);
 904                  $db2->update('egw_sitemgr_content',$row,array('version_id' => $version_id),__LINE__,__FILE__);
 905              }
 906          }
 907          $db->update('egw_sitemgr_blocks',array('module_id' => $navigation_id),array('module_id' => $old_modules),__LINE__,__FILE__);
 908  
 909          $GLOBALS['setup_info']['sitemgr']['currentver'] = '1.2';
 910          return $GLOBALS['setup_info']['sitemgr']['currentver'];
 911      }    
 912  ?>


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