^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.

This script does not currently do anything to change the expiration dates, which means if you are porting old Articles straight to Blog Posts with out adjusting the dates you may find many of your Blog Posts expired. One goal for this script then is to take Article dates, run comparisons, and adjust as best as possible to work with how BlogsPackage handles dates.

{code title=draft script to port Articles to Blog Posts}
<?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' );
require_once( LIBERTY_PKG_PATH.'LibertyComment.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'];
$post['expire_date'] = $article['expire_date'];

$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 );
}
}
?>
{/code}
Page History
Date/CommentUserIPVersion
23 Aug 2007 (18:33 UTC)
no need for comments class
Will89.247.33.2033
Current • Source
Will89.247.7.292
View • Compare • Difference • Source
Will89.247.7.291
View • Compare • Difference • Source