File modules/cms/update/version/DBVersion000009.class.php
Last commit: Sun Oct 1 02:58:08 2023 +0200 Jan Dankert Refactoring: No it is possible to use 8 byte integers in the database
1 <?php 2 3 4 namespace cms\update\version; 5 6 use cms\model\BaseObject; 7 use database\DbVersion; 8 use database\Column; 9 use security\Password; 10 11 /** 12 * New Object type 'url'. 13 * 14 * In this Version 9 we are creating a table 'url' and are copying 15 * the selected entries from table 'link' to 'url'. 16 * 17 * @author dankert 18 * 19 */ 20 class DBVersion000009 extends DbVersion 21 { 22 /** 23 * 24 */ 25 public function update() 26 { 27 // Creating new table 'url' 28 $table = $this->table('url')->add(); 29 $table->column('objectid')->type(Column::TYPE_INT)->add(); 30 $table->column('url')->type(Column::TYPE_VARCHAR)->add(); 31 32 $table->addPrimaryKey(); 33 $table->addConstraint('objectid', 'object'); 34 35 $table->addUniqueIndex('objectid'); 36 37 // Copying values from table 'link' to new table 'url' 38 $db = $this->getDb(); 39 40 $insertStmt = $db->sql('INSERT INTO '.$table->getSqlName(). 41 ' (id,objectid,url) SELECT id,objectid,url FROM '.$this->table('link')->getSqlName().' WHERE url is not null' 42 ); 43 $insertStmt->execute(); 44 45 // Updating the typeid for URL entrys in table 'object' 46 $updateStmt = $db->sql('UPDATE '.$this->table('object')->getSqlName(). 47 ' SET typeid='.BaseObject::TYPEID_URL.' WHERE id IN (SELECT objectid FROM '.$this->table('url')->getSqlName().')' 48 ); 49 $updateStmt->execute(); 50 51 $tableLink = $this->table('link'); 52 // Remove old entrys in table 'link' 53 $updateStmt = $db->sql('DELETE FROM '.$tableLink->getSqlName().' WHERE url is not null' 54 ); 55 $updateStmt->execute(); 56 57 // Cleanup: Drop unused column. 58 $tableLink->column('url')->drop(); 59 } 60 }
Downloadmodules/cms/update/version/DBVersion000009.class.php
History Sun, 1 Oct 2023 02:58:08 +0200 Jan Dankert Refactoring: No it is possible to use 8 byte integers in the database Wed, 7 Jul 2021 22:29:06 +0200 Jan Dankert Refactoring: Split values and content, new table "content". Sun, 7 Mar 2021 00:10:20 +0100 Jan Dankert Refactoring: Hopefully more performance while accessing the database resultsets. Fri, 25 Sep 2020 01:00:58 +0200 Jan Dankert Refactoring: More OO in the database updater :) Sun, 23 Feb 2020 00:30:10 +0100 Jan Dankert Refactoring: Namespacing for module 'database-update', now called 'cms\update'.