Version 2

Porting Articles To Blogs

Created by: Will, Last modification: 01 Aug 2007 (16:49 UTC) by Will
NOTICE: This script is in development! You should proceed with caution with using this script. Always backup your site and test on a copy before working on a live site.

This script is a DRAFT, designed for converting bitweaver Articles content into Blog Posts content. One of the more important aspects of this script is that it changes the content_type_guid on all Articles content to bitblogposts. This has some serious consequences, the most important being that existing Article urls will no longer resolve! The ArticlesPackage will no longer identify old Articles. Instead the blog package will identify them as Blog Posts!

Another thing to be aware of is that Articles and Blog Posts handle their expiration dates quite differently. Article expiration is sort of controlled by Article Type (or Topic - not sure) and the Articles edit form. The topic decides whether Articles can or can not expire and the form decides when. The Article form by default loads with the expiration being One Year ahead.

Blog Posts by contrast only expire if the expiration date is greater than the publish date. Therefore individual blog posts can be set to never expire, where as Articles requires the Topic to enforce that.

As a cude way to deal with this we set all expiration dates to be the publish_date -1 — this will keep all articles from expiring. You may want to change this to make the expiration more sophisticated if you have deliberately expired Articles..


// the blog these posts should be inserted into
$blog_content_id NULL;

// no need to touch any of the stuff below unless you want to change the
// import behaviour
require_once( 'bit_setup_inc.php' );
ARTICLES_PKG_PATH.'BitArticle.php' );
BLOGS_PKG_PATH.'BitBlogPost.php' );
LIBERTY_PKG_PATH.'LibertyComment.php' );
$gBitSystem->isPackageActive'tags' )) {
TAGS_PKG_PATH.'LibertyTag.php' );

$gBitSystem->verifyPermission'p_admin' );

$gBitSystem->isPackageActive'blogs' ) && $gBitSystem->isPackageActive'articles' )) {
// get the list of Articles
$art = new BitArticle();
$getHash['max_records'] = 99999;
$articlesHash $art->getList($getHash);

$articlesHash as $article ) {
$bp = new BitBlogPost();

$feedback "Importing: ".$article['title'];

$post['content_id'] = $article['content_id'];
$post['publish_date'] = $article['publish_date'];

        if ( 
$article['expire_date'] > $article['publish_date'] ){
$article['expire_date'] = $article['publish_date'] - 1;

$table BIT_DB_PREFIX."blog_posts";
$post['post_id'] = $bp->mDb->GenID'blog_posts_post_id_seq' );
$bp->mPostId $post['post_id'];

//store the new post
if ( $result $bp->mDb->associateInsert$table$post ) ){

$query "UPDATE `".BIT_DB_PREFIX."liberty_content` lc SET content_type_guid='bitblogpost' WHERE content_type_guid='bitarticle'";

$result $bp->mDb->query$query );

// let's reload to get a full mInfo hash which is needed below
$bp->loadFALSE );

// if blog_content_id, then map the post to the relative blogs
if( !empty( $blog_content_id )){
$bp->storePostMap$bp->mContentId$blog_content_id );

$feedback .= "\n- Post: SUCCESS - content_id: ".$post['content_id'];

        } else {
$feedback .= "\n- Post: ERROR:\n --- ".implode"\n --- "$bp->mErrors );

//vd(strtotime($post['date'])." - ".date("r", strtotime($post['date']))." - ".$post['date']);
vd$feedback );

Page History
23 Aug 2007 (18:33 UTC)
no need for comments class
Current • Source
View • Compare • Difference • Source
View • Compare • Difference • Source