DBVersion000009.class.php (1703B)
1 <?php 2 3 use cms\model\BaseObject; 4 use database\DbVersion; 5 use security\Password; 6 7 /** 8 * New Object type 'url'. 9 * 10 * In this Version 9 we are creating a table 'url' and are copying 11 * the selected entries from table 'link' to 'url'. 12 * 13 * @author dankert 14 * 15 */ 16 class DBVersion000009 extends DbVersion 17 { 18 /** 19 * 20 */ 21 public function update() 22 { 23 $not_nullable = false; 24 $nullable = true; 25 26 // Creating new table 'url' 27 $this->addTable('url'); 28 $this->addColumn('url','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable); 29 $this->addColumn('url','url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable); 30 31 $this->addPrimaryKey('url','id'); 32 $this->addConstraint('url','objectid','object','id'); 33 34 $this->addUniqueIndex('url','objectid'); 35 36 // Copying values from table 'link' to new table 'url' 37 $db = $this->getDb(); 38 39 $insertStmt = $db->sql('INSERT INTO '.$this->getTableName('url'). 40 ' (id,objectid,url) SELECT id,objectid,url FROM '.$this->getTableName('link').' WHERE url is not null' 41 ); 42 $insertStmt->query(); 43 44 // Updating the typeid for URL entrys in table 'object' 45 $updateStmt = $db->sql('UPDATE '.$this->getTableName('object'). 46 ' SET typeid='.BaseObject::TYPEID_URL.' WHERE id IN (SELECT objectid FROM '.$this->getTableName('url').')' 47 ); 48 $updateStmt->query(); 49 50 // Remove old entrys in table 'link' 51 $updateStmt = $db->sql('DELETE FROM '.$this->getTableName('link').' WHERE url is not null' 52 ); 53 $updateStmt->query(); 54 55 // Cleanup: Drop unused column. 56 $this->dropColumn('link','url'); 57 } 58 } 59 60 ?>