Porting Articles To Blogs
Created by: Will, Last modification: 23 Aug 2007 (18:33 UTC)
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 crude 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..
draft
<?php
// 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' );
require_once( ARTICLES_PKG_PATH.'BitArticle.php' );
require_once( BLOGS_PKG_PATH.'BitBlogPost.php' );
if( $gBitSystem->isPackageActive( 'tags' )) {
require_once( TAGS_PKG_PATH.'LibertyTag.php' );
}
$gBitSystem->verifyPermission( 'p_admin' );
if( $gBitSystem->isPackageActive( 'blogs' ) && $gBitSystem->isPackageActive( 'articles' )) {
// get the list of Articles
$art = new BitArticle();
$getHash['max_records'] = 99999;
$articlesHash = $art->getList($getHash);
foreach( $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";
$bp->mDb->StartTrans();
$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->load( FALSE );
// 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 );
}
$bp->mDb->CompleteTrans();
//vd(strtotime($post['date'])." - ".date("r", strtotime($post['date']))." - ".$post['date']);
vd( $feedback );
}
}
?>