openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

DBVersion000016.class.php (2664B)


      1 <?php
      2 
      3 namespace cms\update\version;
      4 
      5 use database\DbVersion;
      6 use database\Column;
      7 
      8 /**
      9  * Converting element types from string to number.
     10  *
     11  * @author dankert
     12  *
     13  */
     14 class DBVersion000016 extends DbVersion
     15 {
     16     /**
     17      *
     18      */
     19     public function update()
     20     {
     21     	$table = $this->table('element');
     22 
     23         // Type 3 = Text is the default.
     24         $table->column('typeid')->type(Column::TYPE_INT)->size(0)->defaultValue(3)->add();
     25 
     26         $db = $this->getDb();
     27         $tableProject = $table->getSqlName();
     28 
     29         // Update the types
     30         $conversionTable = array(
     31           1 => 'date',
     32           2 => 'number',
     33           3 => 'text',
     34           4 => 'info' ,
     35           5 => 'infodate',
     36           6 => 'link'    ,
     37           7 => 'longtext',
     38           8 => 'code'    ,
     39           9 => 'dynamic' ,
     40          10 => 'select'  ,
     41          11 => 'copy'    ,
     42          12 => 'linkinfo',
     43          13 => 'linkdate',
     44          14 => 'insert'
     45         );
     46 
     47         foreach ($conversionTable as $typeid => $typename )
     48         {
     49             $updateStmt = $db->sql(<<<SQL
     50 UPDATE $tableProject
     51    SET typeid=$typeid WHERE type = '$typename'
     52 SQL
     53             );
     54             $updateStmt->execute();
     55         }
     56 
     57 		$table->column('type')->drop();
     58 
     59 
     60 
     61         $table->column('flags')->type(Column::TYPE_INT)->size(0)->defaultValue(0)->add();
     62 
     63         $updateStmt = $db->sql(<<<SQL
     64 UPDATE $tableProject
     65    SET flags=flags+1 WHERE html = 1
     66 SQL
     67         );
     68         $updateStmt->execute();
     69 
     70         $updateStmt = $db->sql(<<<SQL
     71 UPDATE $tableProject
     72    SET flags=flags+2 WHERE all_languages = 1
     73 SQL
     74         );
     75         $updateStmt->execute();
     76 
     77         $updateStmt = $db->sql(<<<SQL
     78 UPDATE $tableProject
     79    SET flags=flags+4 WHERE writable = 1
     80 SQL
     81         );
     82         $updateStmt->execute();
     83 
     84         $updateStmt = $db->sql(<<<SQL
     85 UPDATE $tableProject
     86    SET flags=flags+8 WHERE with_icon = 1
     87 SQL
     88         );
     89         $updateStmt->execute();
     90 
     91 
     92 
     93         $table->column('format')->type(Column::TYPE_INT)->size(0)->defaultValue(0)->add();
     94 
     95         // Format = HTML
     96         $updateStmt = $db->sql(<<<SQL
     97 UPDATE $tableProject
     98    SET format=1 WHERE html = 1 and wiki = 0
     99 SQL
    100         );
    101         $updateStmt->execute();
    102 
    103         // Format = Wiki
    104         $updateStmt = $db->sql(<<<SQL
    105 UPDATE $tableProject
    106    SET format=2 WHERE wiki = 1
    107 SQL
    108         );
    109         $updateStmt->execute();
    110 
    111         // Other formats were not supported up to this version.
    112 
    113         // Cleanup
    114 		$table->column('wiki'         )->drop();
    115 		$table->column('html'         )->drop();
    116 		$table->column('all_languages')->drop();
    117 		$table->column('writable'     )->drop();
    118 		$table->column('with_icon'    )->drop();
    119 
    120     }
    121 
    122 
    123 }
    124 
    125 ?>