[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

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

   1  <?php
   2      $test[] = '0.9.14.001';
   3  	function phpbrain_upgrade0_9_14_001()
   4      {
   5          global $DEBUG;
   6  
   7          $db1 = $GLOBALS['phpgw_setup']->db;
   8  
   9          $GLOBALS['phpgw_setup']->oProc->CreateTable(
  10              'phpgw_kb_ratings', array(
  11                  'fd' => array(
  12                      'user_id'    => array('type' => 'int','precision' => '4', 'nullable' => False),
  13                      'art_id'    => array('type' => 'int','precision' => '4','nullable' => False)
  14                  ),
  15                  'pk' => array('user_id', 'art_id'),
  16                  'fk' => array(),
  17                  'ix' => array(),
  18                  'uc' => array()
  19              )
  20          );
  21  
  22          $GLOBALS['phpgw_setup']->oProc->CreateTable(
  23              'phpgw_kb_related_art', array(
  24                  'fd' => array(
  25                      'art_id'            => array('type' => 'int','precision' => '4','nullable' => False),
  26                      'related_art_id'    => array('type' => 'int','precision' => '4','nullable' => False)
  27                  ),
  28                  'pk' => array('art_id', 'related_art_id'),
  29                  'fk' => array(),
  30                  'ix' => array(),
  31                  'uc' => array()
  32              )
  33          );
  34  
  35          $GLOBALS['phpgw_setup']->oProc->CreateTable(
  36              'phpgw_kb_search', array(
  37                  'fd' => array(
  38                      'keyword'    => array('type' => 'varchar', 'precision' => '10','nullable' => False),
  39                      'art_id'    => array('type' => 'int','precision' => '4','nullable' => False),
  40                      'score'        => array('type' => 'int','precision' => '8','nullable' => False)
  41                  ),
  42                  'pk' => array('keyword', 'art_id'),
  43                  'fk' => array(),
  44                  'ix' => array(),
  45                  'uc' => array()
  46              )
  47          );
  48          if ($DEBUG) echo '<br>tables_update: new tables created';
  49  
  50          $GLOBALS['phpgw_setup']->oProc->RenameTable('phpgw_kb_faq', 'phpgw_kb_articles');
  51          $GLOBALS['phpgw_setup']->oProc->RenameColumn('phpgw_kb_articles', 'faq_id', 'art_id');
  52          $GLOBALS['phpgw_setup']->oProc->RenameColumn('phpgw_kb_articles', 'url', 'urls');
  53          $GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_kb_articles', 'urls', array('type' => 'text', 'nullable' => False));
  54          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'q_id', array('type' => 'int', 'precision' => 8, 'nullable' => False));
  55          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'topic', array('type' => 'text', 'nullable' => False));
  56          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'created', array('type' => 'int', 'precision' => '4', 'nullable' => True));
  57          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'modified_user_id', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  58          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'votes_1', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  59          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'votes_2', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  60          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'votes_3', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  61          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'votes_4', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  62          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'votes_5', array('type' => 'int', 'precision' => '4', 'nullable' => False));
  63          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_articles', 'files', array('type' => 'text', 'nullable' => False));
  64          if ($DEBUG) echo '<br>tables_update: added columns to phpgw_kb_articles';
  65  
  66          $sql = "SELECT art_id, user_id, modified, urls, votes, total FROM phpgw_kb_articles";
  67          $GLOBALS['phpgw_setup']->oProc->query($sql, __LINE__, __FILE__);
  68          if ($DEBUG) echo '<br>tables_update: query on phpgw_kb_articles executed';
  69          while($GLOBALS['phpgw_setup']->oProc->next_record())
  70          {
  71              $art_id        = $GLOBALS['phpgw_setup']->oProc->f('art_id');
  72              $user_id    = $GLOBALS['phpgw_setup']->oProc->f('user_id');
  73              $keywords    = $GLOBALS['phpgw_setup']->oProc->f('keywords');
  74              $modified    = $GLOBALS['phpgw_setup']->oProc->f('modified');
  75              $urls         = $GLOBALS['phpgw_setup']->oProc->f('urls');
  76              $votes        = $GLOBALS['phpgw_setup']->oProc->f('votes');
  77              $total        = $GLOBALS['phpgw_setup']->oProc->f('total');
  78  
  79              if ($urls)
  80              {
  81                  $new_urls = serialize(array(0=>array('link' => $urls, 'title' => '')));
  82              }
  83              else
  84              {
  85                  $new_urls = '';
  86              }
  87              if (!$votes)
  88              {
  89                  $average = -1;
  90              }
  91              else
  92              {
  93                  $average = round($total / $votes);
  94              }
  95              $votes_str = array();
  96              for ($j=1; $j<=5; $j++)
  97              {
  98                  if ($j == $average)
  99                  {
 100                      $votes_str[] = "votes_" . $j . "=$votes";
 101                  }
 102                  else
 103                  {
 104                      $votes_str[] = "votes_" . $j . "=0";
 105                  }
 106              }
 107              $votes_str = implode(', ', $votes_str);
 108              $sql = "UPDATE phpgw_kb_articles SET created=$modified, modified_user_id=$user_id, $votes_str, urls='$new_urls', q_id='0', topic='', files=''  WHERE art_id=$art_id";
 109              $db1->query($sql, __LINE__, __FILE__);
 110  
 111              $sql = "INSERT INTO phpgw_kb_search (keyword, art_id, score) VALUES ('', $art_id, 1)";
 112              $db1->query($sql, __LINE__, __FILE__);
 113          }
 114          $new_table_def = array(
 115              'fd' => array(
 116                  'art_id'            => array('type' => 'auto','nullable' => False),
 117                  'title'                => array('type' => 'text','nullable' => False),
 118                  'text'                => array('type' => 'text','nullable' => False),
 119                  'cat_id'            => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 120                  'published'         => array('type' => 'int','precision' => '2','nullable' => False,'default' => '0'),
 121                  'keywords'            => array('type' => 'text','nullable' => False),
 122                  'user_id'            => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 123                  'views'                => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 124                  'modified'            => array('type' => 'int','precision' => '4','nullable' => True),
 125                  'urls'                => array('type' => 'text', 'nullable' => False),
 126                  'votes'                => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 127                  'total'                => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 128                  'q_id'                => array('type' => 'int', 'precision' => 8, 'nullable' => False),
 129                  'topic'                => array('type' => 'text', 'nullable' => False),
 130                  'created'            => array('type' => 'int','precision' => '4','nullable' => True),
 131                  'modified_user_id'    => array('type' => 'int','precision' => '4','nullable' => False),
 132                  'votes_1'            => array('type' => 'int','precision' => '4','nullable' => False),
 133                  'votes_2'            => array('type' => 'int','precision' => '4','nullable' => False),
 134                  'votes_3'            => array('type' => 'int','precision' => '4','nullable' => False),
 135                  'votes_4'            => array('type' => 'int','precision' => '4','nullable' => False),
 136                  'votes_5'            => array('type' => 'int','precision' => '4','nullable' => False),
 137                  'files'                => array('type' => 'text', 'nullable' => False)
 138              ),
 139              'pk' => array('art_id'),
 140              'fk' => array(),
 141              'ix' => array(),
 142              'uc' => array()
 143          );
 144          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles', $new_table_def, 'is_faq');
 145          if ($DEBUG) echo '<br>tables_update: dropped column is_faq in phpgw_kb_articles';
 146          unset($new_table_def['fd']['votes']);
 147          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles', $new_table_def, 'votes');
 148          if ($DEBUG) echo '<br>tables_update: dropped column votes in phpgw_kb_articles';
 149          unset($new_table_def['fd']['total']);
 150          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles', $new_table_def, 'total');
 151          if ($DEBUG) echo '<br>tables_update: dropped column total in phpgw_kb_articles';
 152  
 153          $GLOBALS['phpgw_setup']->oProc->RenameColumn('phpgw_kb_comment', 'faq_id', 'art_id');
 154          if ($DEBUG) echo '<br>tables_update: renamed column faq_id to art_id in phpgw_kb_articles';
 155          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_comment', 'published', array('type' => 'int', 'precision' => '2', 'nullable' => False));
 156          if ($DEBUG) echo '<br>tables_update: added column published in phpgw_kb_articles';
 157          $sql = "UPDATE phpgw_kb_comment SET published=1";
 158          $db1->query($sql, __LINE__, __FILE__);
 159  
 160  
 161          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_questions', 'user_id', array('type' => 'int', 'precision' => '4', 'nullable' => False));
 162          if ($DEBUG) echo '<br>tables_update: added column user_id in phpgw_kb_questions';
 163          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_questions', 'details', array('type' => 'text', 'nullable' => False));
 164          if ($DEBUG) echo '<br>tables_update: added column details in phpgw_kb_questions';
 165          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_questions', 'cat_id', array('type' => 'int', 'precision' => '4', 'nullable' => False, 'default' => '0'));
 166          if ($DEBUG) echo '<br>tables_update: added column cat_id in phpgw_kb_questions';
 167          $GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_kb_questions', 'creation', array('type' => 'int', 'precision' => '4', 'nullable' => True));
 168          if ($DEBUG) echo '<br>tables_update: added column creation in phpgw_kb_questions';
 169  
 170          $sql = "SELECT question_id, pending FROM phpgw_kb_questions";
 171          $GLOBALS['phpgw_setup']->oProc->query($sql, __LINE__, __FILE__);
 172          while($GLOBALS['phpgw_setup']->oProc->next_record())
 173          {
 174              $question_id    = $GLOBALS['phpgw_setup']->oProc->f('question_id');
 175              $published        = $GLOBALS['phpgw_setup']->oProc->f('pending');
 176              $published = $published? 0 : 1;
 177              $sql = "UPDATE phpgw_kb_questions SET pending=$published, user_id='0', details='', cat_id='0', creation='". time() ."' WHERE question_id=$question_id";
 178              $db1->query($sql, __LINE__, __FILE__);
 179          }
 180          $GLOBALS['phpgw_setup']->oProc->RenameColumn('phpgw_kb_questions', 'question', 'summary');
 181          if ($DEBUG) echo '<br>tables_update: renamed column question to summary in phpgw_kb_questions';
 182          $GLOBALS['phpgw_setup']->oProc->RenameColumn('phpgw_kb_questions', 'pending', 'published');
 183          if ($DEBUG) echo '<br>tables_update: renamed column pending to published in phpgw_kb_questions';
 184  
 185          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0RC5';
 186          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 187      }
 188  
 189      $test[] = '1.0RC5';
 190  	function phpbrain_upgrade1_0RC5()
 191      {
 192          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.0';
 193          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 194      }
 195  
 196      $test[] = '1.0.0';
 197  	function phpbrain_upgrade1_0_0()
 198      {
 199          $GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_kb_search', 'keyword', array('type' => 'varchar', 'precision' => '30', 'nullable' => False));
 200  
 201          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.1';
 202          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 203      }
 204  
 205      $test[] = '1.0.1';
 206      // this upgrade changes \n from older version's plain text to <br>
 207  	function phpbrain_upgrade1_0_1()
 208      {
 209          $db1 = $GLOBALS['phpgw_setup']->db;
 210  
 211          $sql = "SELECT art_id, text FROM phpgw_kb_articles";
 212          $GLOBALS['phpgw_setup']->oProc->query($sql, __LINE__, __FILE__);
 213          while($GLOBALS['phpgw_setup']->oProc->next_record())
 214          {
 215              $art_id = $GLOBALS['phpgw_setup']->oProc->f('art_id');
 216              $text = $GLOBALS['phpgw_setup']->oProc->f('text');
 217              
 218              if (!ereg("<[^<]+>.+<[^/]*/.+>", $text))
 219              {
 220                  // text doesn't have html -> proceed to replace all \n by <br>
 221                  $new_text = ereg_replace("\n", "<br />", $text);
 222  
 223                  $sql ="UPDATE phpgw_kb_articles SET text='$new_text' WHERE art_id = $art_id";
 224                  $db1->query($sql, __LINE__, __FILE__);
 225              }
 226          }
 227  
 228          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.2';
 229          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 230      }
 231  
 232      $test[] = '1.0.2';
 233  	function phpbrain_upgrade1_0_2()
 234      {
 235          $GLOBALS['phpgw_setup']->oProc->CreateTable('phpgw_kb_files',array(
 236              'fd' => array(
 237                  'art_id' => array('type' => 'int','precision' => '4'),
 238                  'art_file' => array('type' => 'varchar','precision' => '255'),
 239                  'art_file_comments' => array('type' => 'varchar','precision' => '255'),
 240              ),
 241              'pk' => array('art_id','art_file'),
 242              'fk' => array(),
 243              'ix' => array(),
 244              'uc' => array()
 245          ));
 246  
 247          $db2 = $GLOBALS['phpgw_setup']->db;
 248          $GLOBALS['phpgw_setup']->oProc->query("SELECT art_id,files FROM phpgw_kb_articles WHERE files != ''",__LINE__,__FILE__);
 249          while ($GLOBALS['phpgw_setup']->oProc->next_record())
 250          {
 251              $art_id = $GLOBALS['phpgw_setup']->oProc->f('art_id');
 252              $files = unserialize($GLOBALS['phpgw_setup']->oProc->f('files'));
 253              if (is_array($files))
 254              {
 255                  foreach($files as $file)
 256                  {
 257                      $db2->insert('phpgw_kb_files',array(
 258                          'art_id' => $art_id,
 259                          'art_file'   => $file['file'],
 260                          'art_file_comments'    => $file['comment'],
 261                      ),false,__LINE__,__FILE__,'phpbrain');
 262                  }
 263              }
 264          }
 265          
 266          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.3';
 267          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 268      }
 269  
 270  
 271      $test[] = '1.0.3';
 272  	function phpbrain_upgrade1_0_3()
 273      {
 274          $GLOBALS['phpgw_setup']->oProc->CreateTable('phpgw_kb_urls',array(
 275              'fd' => array(
 276                  'art_id' => array('type' => 'int','precision' => '4'),
 277                  'art_url' => array('type' => 'varchar','precision' => '255'),
 278                  'art_url_title' => array('type' => 'varchar','precision' => '255')
 279              ),
 280              'pk' => array('art_id','art_url'),
 281              'fk' => array(),
 282              'ix' => array(),
 283              'uc' => array()
 284          ));
 285  
 286          $db2 = $GLOBALS['phpgw_setup']->db;
 287          $GLOBALS['phpgw_setup']->oProc->query("SELECT art_id,urls FROM phpgw_kb_articles WHERE urls != ''",__LINE__,__FILE__);
 288          while ($GLOBALS['phpgw_setup']->oProc->next_record())
 289          {
 290              $art_id = $GLOBALS['phpgw_setup']->oProc->f('art_id');
 291              $urls = unserialize($GLOBALS['phpgw_setup']->oProc->f('urls'));
 292              if (is_array($files))
 293              {
 294                  foreach($urls as $url)
 295                  {
 296                      $db2->insert('phpgw_kb_files',array(
 297                          'art_id' => $art_id,
 298                          'art_url'    => $url['link'],
 299                          'art_url_title'    => $url['title'],
 300                      ),false,__LINE__,__FILE__,'phpbrain');
 301                  }
 302              }
 303          }
 304          
 305          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.4';
 306          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 307      }
 308      
 309      $test[] = '1.0.4';
 310  	function phpbrain_upgrade1_0_4()
 311      {
 312          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles',array(
 313              'fd' => array(
 314                  'art_id' => array('type' => 'auto','nullable' => False),
 315                  'q_id' => array('type' => 'int','precision' => '8','nullable' => False),
 316                  'title' => array('type' => 'text','nullable' => False),
 317                  'topic' => array('type' => 'text','nullable' => False),
 318                  'text' => array('type' => 'text','nullable' => False),
 319                  'cat_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 320                  'published' => array('type' => 'int','precision' => '2','nullable' => False,'default' => '0'),
 321                  'user_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 322                  'views' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 323                  'created' => array('type' => 'int','precision' => '4','nullable' => True),
 324                  'modified' => array('type' => 'int','precision' => '4','nullable' => True),
 325                  'modified_user_id' => array('type' => 'int','precision' => '4','nullable' => False),
 326                  'files' => array('type' => 'text','nullable' => False),
 327                  'urls' => array('type' => 'text','nullable' => False),
 328                  'votes_1' => array('type' => 'int','precision' => '4','nullable' => False),
 329                  'votes_2' => array('type' => 'int','precision' => '4','nullable' => False),
 330                  'votes_3' => array('type' => 'int','precision' => '4','nullable' => False),
 331                  'votes_4' => array('type' => 'int','precision' => '4','nullable' => False),
 332                  'votes_5' => array('type' => 'int','precision' => '4','nullable' => False)
 333              ),
 334              'pk' => array('art_id'),
 335              'fk' => array(),
 336              'ix' => array(),
 337              'uc' => array()
 338          ),'keywords');
 339          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles',array(
 340              'fd' => array(
 341                  'art_id' => array('type' => 'auto','nullable' => False),
 342                  'q_id' => array('type' => 'int','precision' => '8','nullable' => False),
 343                  'title' => array('type' => 'text','nullable' => False),
 344                  'topic' => array('type' => 'text','nullable' => False),
 345                  'text' => array('type' => 'text','nullable' => False),
 346                  'cat_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 347                  'published' => array('type' => 'int','precision' => '2','nullable' => False,'default' => '0'),
 348                  'user_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 349                  'views' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 350                  'created' => array('type' => 'int','precision' => '4','nullable' => True),
 351                  'modified' => array('type' => 'int','precision' => '4','nullable' => True),
 352                  'modified_user_id' => array('type' => 'int','precision' => '4','nullable' => False),
 353                  'urls' => array('type' => 'text','nullable' => False),
 354                  'votes_1' => array('type' => 'int','precision' => '4','nullable' => False),
 355                  'votes_2' => array('type' => 'int','precision' => '4','nullable' => False),
 356                  'votes_3' => array('type' => 'int','precision' => '4','nullable' => False),
 357                  'votes_4' => array('type' => 'int','precision' => '4','nullable' => False),
 358                  'votes_5' => array('type' => 'int','precision' => '4','nullable' => False)
 359              ),
 360              'pk' => array('art_id'),
 361              'fk' => array(),
 362              'ix' => array(),
 363              'uc' => array()
 364          ),'files');
 365          $GLOBALS['phpgw_setup']->oProc->DropColumn('phpgw_kb_articles',array(
 366              'fd' => array(
 367                  'art_id' => array('type' => 'auto','nullable' => False),
 368                  'q_id' => array('type' => 'int','precision' => '8','nullable' => False),
 369                  'title' => array('type' => 'text','nullable' => False),
 370                  'topic' => array('type' => 'text','nullable' => False),
 371                  'text' => array('type' => 'text','nullable' => False),
 372                  'cat_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 373                  'published' => array('type' => 'int','precision' => '2','nullable' => False,'default' => '0'),
 374                  'user_id' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 375                  'views' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
 376                  'created' => array('type' => 'int','precision' => '4','nullable' => True),
 377                  'modified' => array('type' => 'int','precision' => '4','nullable' => True),
 378                  'modified_user_id' => array('type' => 'int','precision' => '4','nullable' => False),
 379                  'votes_1' => array('type' => 'int','precision' => '4','nullable' => False),
 380                  'votes_2' => array('type' => 'int','precision' => '4','nullable' => False),
 381                  'votes_3' => array('type' => 'int','precision' => '4','nullable' => False),
 382                  'votes_4' => array('type' => 'int','precision' => '4','nullable' => False),
 383                  'votes_5' => array('type' => 'int','precision' => '4','nullable' => False)
 384              ),
 385              'pk' => array('art_id'),
 386              'fk' => array(),
 387              'ix' => array(),
 388              'uc' => array()
 389          ),'urls');
 390          $GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_kb_articles','title',array(
 391              'type' => 'varchar',
 392              'precision' => '255',
 393              'nullable' => False
 394          ));
 395          $GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_kb_articles','topic',array(
 396              'type' => 'varchar',
 397              'precision' => '255',
 398              'nullable' => False
 399          ));
 400  
 401          $GLOBALS['setup_info']['phpbrain']['currentver'] = '1.0.5';
 402          return $GLOBALS['setup_info']['phpbrain']['currentver'];
 403      }
 404  ?>


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