File modules/cms/update/version/DBVersion000031.class.php

Last commit: Sat Nov 27 00:10:15 2021 +0100	Jan Dankert	Fix: Creation time of templates and file contents should be unknown.
1 <?php 2 3 namespace cms\update\version; 4 5 use cms\base\Startup; 6 use database\DbVersion; 7 use database\Column; 8 use security\Password; 9 10 /** 11 * Migrate file values to content. 12 * 13 * @author dankert 14 * 15 */ 16 class DBVersion000031 extends DbVersion 17 { 18 /** 19 * 20 */ 21 public function update() 22 { 23 $contentTable = $this->table('content' ); 24 $valueTable = $this->table('value' ); 25 26 $fileTable = $this->table('file' ); 27 $fileTable->column('contentid')->add(); 28 29 $db = $this->getDb(); 30 $stmt = $db->sql('SELECT id FROM '.$fileTable->getSqlName() ); 31 32 foreach($stmt->getCol() as $fileid ) 33 { 34 $stmt = $db->sql('SELECT * FROM '.$fileTable->getSqlName().' WHERE id='.$fileid ); 35 $row = $stmt->getRow(); 36 37 $stmt = $db->sql('SELECT MAX(id) FROM '.$contentTable->getSqlName() ); 38 $contentid = $stmt->getOne() + 1; 39 40 $stmt = $db->sql('INSERT INTO '.$contentTable->getSqlName().' (id) VALUES('.$contentid.')') ; 41 $stmt->execute(); 42 43 $stmt = $db->sql('SELECT MAX(id) FROM '.$valueTable->getSqlName() ); 44 $valueid = $stmt->getOne() + 1; 45 46 $stmt = $db->sql('INSERT INTO '.$valueTable->getSqlName().' (id,contentid,active,publish,file,lastchange_date) VALUES('.$valueid.','.$contentid.',1,1,{file},{time})'); 47 $stmt->setString( 'file', $row['value'] ); 48 $stmt->setInt ( 'time', 0 ); 49 $stmt->execute(); 50 51 $stmt = $db->sql('UPDATE '.$fileTable->getSqlName().' SET contentid='.$contentid.' WHERE id='.$row['id']); 52 $stmt->execute(); 53 } 54 55 $fileTable->addConstraint('contentid' , 'content' ); 56 $fileTable->column('value')->drop(); 57 58 } 59 } 60
Download modules/cms/update/version/DBVersion000031.class.php
History Sat, 27 Nov 2021 00:10:15 +0100 Jan Dankert Fix: Creation time of templates and file contents should be unknown. Mon, 8 Nov 2021 01:05:56 +0100 Jan Dankert Fix: Do not update all rows with the content id :-O Sun, 7 Nov 2021 23:45:50 +0100 Jan Dankert Fix: First successful migration to the new "content" table. Wed, 7 Jul 2021 22:29:06 +0200 Jan Dankert Refactoring: Split values and content, new table "content".