Importer script

Permalink
Er, the comments section athttp://www.concrete5.org/help/building_with_concrete5/developers/mi... did not support code tags, and also it ate lots of my post (i.e., the actual PHP script - I sincerely hope it *did not* actually execute it!), so here's the last part from the line "Here goes" (for the beginning of the post, see the Migrating to Concrete article):

The code I used:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
ini_set("auto_detect_line_endings", "1");
$indata = file("/PATH/TO/flatfile.txt", (int) FILE_IGNORE_EMPTY_LINES | (int) FILE_TEXT);
if(!$indata) die("couldn't open input file");
$logfile = fopen("/PATH/TO/log_file.txt", "w");
if(!$logfile) die("couldn't open log file");
// The page to store the imported pages under - it is best to make sure
// the page doesn't have any existing sub-pages
define('PAGE_TO_STORE_UNDER', '/news');
// The page type to use for the new pages
define('PAGE_TYPE', 'news_pages');
// Uncomment this to make pages invisible in menu
//define('EXCLUDE_FROM_NAV', TRUE);
function cleanpath($dirty)

Note that I a) back-translated this to English (was originally in Swedish) and b) changed my path specs to defines to spare you from editing all over the file. So - if there's a syntax error, just correct it ;) The procedure in and of itself worked for me, at least.

Also, to import from somewhere else, like another database, I guess the relevant parts to change are a) the '$indata =' line at the top (remove it or use it to specify your db), and b) the code at the bottom, starting from '$curline = substr...'.

 

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.