Migrating old data into C5
PermalinkI've managed to write some simple code to add the pages and tested it successfully with a local installation:
<?php $pt = CollectionType::getByHandle('full'); $data = array( 'uID' => 1, 'cName' => 'Automatic Test Page', 'cHandle' => 'news-' . date(time()), 'cDescription' => 'This is a sample test page added automatically through code'); $Section = Page::getByPath('/news'); $newPage = $Section->add($pt,$data); $bt = BlockType::getByHandle('content'); $data2 = array('uID' => 1, 'content' => 'This is a test page added using code.'); $newPage->addBlock($bt, 'Main', $data2);
This is great. I just have to connect to the DB where I have my old data and loop through the records and add them under this section.
The question is, where is the best place to place such a code, especially if I have many sites I need to migrate?
Also, am I doing the right thing with this code? :-) Thanks! (concrete/controllers/install.php was a great help!)