File modules/cms/update/version/DBVersion000030.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 template models to a text content 12 * 13 * @author dankert 14 * 15 */ 16 class DBVersion000030 extends DbVersion 17 { 18 /** 19 * 20 */ 21 public function update() 22 { 23 $contentTable = $this->table('content' ); 24 $valueTable = $this->table('value' ); 25 26 $templateModelTable = $this->table('templatemodel' ); 27 $templateModelTable->column('contentid')->add(); 28 29 $db = $this->getDb(); 30 $stmt = $db->sql('SELECT * FROM '.$templateModelTable->getSqlName() ); 31 32 foreach($stmt->getAll() as $row ) // all templates should fit into memory. 33 { 34 $stmt = $db->sql('SELECT MAX(id) FROM '.$contentTable->getSqlName()); 35 $contentid = $stmt->getOne() + 1; 36 37 $stmt = $db->sql('INSERT INTO '.$contentTable->getSqlName().' (id) VALUES('.$contentid.')') ; 38 $stmt->execute(); 39 40 $stmt = $db->sql('SELECT MAX(id) FROM '.$valueTable->getSqlName()); 41 $valueid = $stmt->getOne() + 1; 42 43 $stmt = $db->sql('INSERT INTO '.$valueTable->getSqlName().' (id,contentid,active,publish,text,lastchange_date) VALUES('.$valueid.','.$contentid.',1,1,{text},{time})'); 44 $stmt->setString( 'text', $row['text'] ); 45 $stmt->setInt ( 'time', 0 ); 46 $stmt->execute(); 47 48 $stmt = $db->sql('UPDATE '.$templateModelTable->getSqlName().' SET contentid='.$contentid.' WHERE id='.$row['id']); 49 $stmt->execute(); 50 } 51 52 $templateModelTable->addConstraint('contentid' , 'content' ); 53 $templateModelTable->column('text')->drop(); 54 } 55 } 56
Download modules/cms/update/version/DBVersion000030.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".